[PR #734] [MERGED] codegen-java: Make stateless classes instantiable #700

Closed
opened 2025-12-30 01:26:14 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/apple/pkl/pull/734
Author: @odenix
Created: 10/24/2024
Status: Merged
Merged: 10/24/2024
Merged by: @bioball

Base: mainHead: stateless-classes


📝 Commits (1)

  • 3843175 codegen-java: Make stateless classes instantiable

📊 Changes

2 files changed (+92 additions, -4 deletions)

View changed files

📝 pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/JavaCodeGenerator.kt (+3 -2)
📝 pkl-codegen-java/src/test/kotlin/org/pkl/codegen/java/JavaCodeGeneratorTest.kt (+89 -2)

📄 Description

Last codegen PR for now. :-)

Motivation:
Currently, the condition for making a generated Java class instantiable is "class is neither abstract nor stateless".
(An instantiable class receives a public constructor and equals/hashCode/toString/with methods.)
This is inconsistent with Pkl and codegen-kotlin, both of which support instantiation of stateless classes.

Changes:
Widen condition for making a class instantiable to "class is neither abstract nor a stateless final module class".
This is consistent with codegen-kotlin, which generates object declarations (only) for stateless final module classes.

Result:
Stateless classes are instantiable in Pkl, codegen-java, and codegen-kotlin.


🔄 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/734 **Author:** [@odenix](https://github.com/odenix) **Created:** 10/24/2024 **Status:** ✅ Merged **Merged:** 10/24/2024 **Merged by:** [@bioball](https://github.com/bioball) **Base:** `main` ← **Head:** `stateless-classes` --- ### 📝 Commits (1) - [`3843175`](https://github.com/apple/pkl/commit/3843175e52011c77c4a6ca8b7016b4717b7161dc) codegen-java: Make stateless classes instantiable ### 📊 Changes **2 files changed** (+92 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/JavaCodeGenerator.kt` (+3 -2) 📝 `pkl-codegen-java/src/test/kotlin/org/pkl/codegen/java/JavaCodeGeneratorTest.kt` (+89 -2) </details> ### 📄 Description Last codegen PR for now. :-) Motivation: Currently, the condition for making a generated Java class instantiable is "class is neither abstract nor stateless". (An instantiable class receives a public constructor and equals/hashCode/toString/with methods.) This is inconsistent with Pkl and codegen-kotlin, both of which support instantiation of stateless classes. Changes: Widen condition for making a class instantiable to "class is neither abstract nor a stateless final module class". This is consistent with codegen-kotlin, which generates object declarations (only) for stateless final module classes. Result: Stateless classes are instantiable in Pkl, codegen-java, and codegen-kotlin. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 01:26:14 +01:00
adam closed this issue 2025-12-30 01:26:14 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#700