Currently, the condition for generating equals/hashCode/toString methods is "generated class declares properties". As a result, classes that don't declare properties inherit these methods from their generated superclasses. However, generated equals and toString methods aren't designed to be inherited and will either fail or produce wrong results when called for a subclass.
Currently, the condition for generating with methods is "class is not abstract". However, it isn't useful to generate with methods for non-instantiable non-abstract classes.
Currently, the condition for making classes serializable is "class is not a module class". However, it isn't useful to make non-instantiable non-module classes serializable, and it is useful to make instantiable module classes serializable.
Changes:
Change the condition for generating equals/hashCode/toString/with/Serializable to "class is instantiable". This is a breaking change.
(A generated class is instantiable, i.e., declares a public constructor, if it is neither abstract nor stateless. This behavior remains unchanged.)
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/apple/pkl/pull/710
**Author:** [@odenix](https://github.com/odenix)
**Created:** 10/19/2024
**Status:** ✅ Merged
**Merged:** 10/24/2024
**Merged by:** [@bioball](https://github.com/bioball)
**Base:** `main` ← **Head:** `codegen-java`
---
### 📝 Commits (1)
- [`f970f66`](https://github.com/apple/pkl/commit/f970f669b763f779bd7eef46095c376e1b042a27) codegen-java: Change condition for generating equals/hashCode/toString/with/Serializable
### 📊 Changes
**3 files changed** (+958 additions, -814 deletions)
<details>
<summary>View changed files</summary>
📝 `pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/JavaCodeGenerator.kt` (+10 -8)
📝 `pkl-codegen-java/src/test/kotlin/org/pkl/codegen/java/JavaCodeGeneratorTest.kt` (+936 -794)
📝 `pkl-codegen-java/src/test/resources/org/pkl/codegen/java/Inheritance.jva` (+12 -12)
</details>
### 📄 Description
Motivation:
* Currently, the condition for generating `equals/hashCode/toString` methods is "generated class declares properties". As a result, classes that don't declare properties inherit these methods from their generated superclasses. However, generated `equals` and `toString` methods aren't designed to be inherited and will either fail or produce wrong results when called for a subclass.
* Currently, the condition for generating `with` methods is "class is not abstract". However, it isn't useful to generate `with` methods for non-instantiable non-abstract classes.
* Currently, the condition for making classes serializable is "class is not a module class". However, it isn't useful to make non-instantiable non-module classes serializable, and it is useful to make instantiable module classes serializable.
Changes:
Change the condition for generating `equals/hashCode/toString/with/Serializable` to "class is instantiable". This is a breaking change.
(A generated class is instantiable, i.e., declares a public constructor, if it is neither abstract nor stateless. This behavior remains unchanged.)
Result:
* Fixes all motivating issues.
* Fixes #706.
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/apple/pkl/pull/710
Author: @odenix
Created: 10/19/2024
Status: ✅ Merged
Merged: 10/24/2024
Merged by: @bioball
Base:
main← Head:codegen-java📝 Commits (1)
f970f66codegen-java: Change condition for generating equals/hashCode/toString/with/Serializable📊 Changes
3 files changed (+958 additions, -814 deletions)
View changed files
📝
pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/JavaCodeGenerator.kt(+10 -8)📝
pkl-codegen-java/src/test/kotlin/org/pkl/codegen/java/JavaCodeGeneratorTest.kt(+936 -794)📝
pkl-codegen-java/src/test/resources/org/pkl/codegen/java/Inheritance.jva(+12 -12)📄 Description
Motivation:
equals/hashCode/toStringmethods is "generated class declares properties". As a result, classes that don't declare properties inherit these methods from their generated superclasses. However, generatedequalsandtoStringmethods aren't designed to be inherited and will either fail or produce wrong results when called for a subclass.withmethods is "class is not abstract". However, it isn't useful to generatewithmethods for non-instantiable non-abstract classes.Changes:
Change the condition for generating
equals/hashCode/toString/with/Serializableto "class is instantiable". This is a breaking change.(A generated class is instantiable, i.e., declares a public constructor, if it is neither abstract nor stateless. This behavior remains unchanged.)
Result:
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.