[PR #793] [MERGED] codegen-kotlin: Generate toString() methods consistent with data classes #739

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

📋 Pull Request Information

Original PR: https://github.com/apple/pkl/pull/793
Author: @odenix
Created: 11/8/2024
Status: Merged
Merged: 11/14/2024
Merged by: @bioball

Base: mainHead: kotlin-tostring


📝 Commits (3)

  • 9cee7cc codegen-kotlin: Generate toString() methods consistent with data classes
  • 197c68e Rename KotlinCodegenOptions to KotlinCodeGeneratorOptions
  • 2a43194 Incorporate review feedback

📊 Changes

6 files changed (+86 additions, -279 deletions)

View changed files

📝 pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/CliKotlinCodeGeneratorOptions.kt (+2 -2)
📝 pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/KotlinCodeGenerator.kt (+25 -91)
📝 pkl-codegen-kotlin/src/test/kotlin/org/pkl/codegen/kotlin/KotlinCodeGeneratorTest.kt (+51 -64)
📝 pkl-codegen-kotlin/src/test/resources/org/pkl/codegen/kotlin/Inheritance.kotlin (+4 -45)
📝 pkl-codegen-kotlin/src/test/resources/org/pkl/codegen/kotlin/Kdoc.kotlin (+1 -23)
📝 pkl-codegen-kotlin/src/test/resources/org/pkl/codegen/kotlin/PropertyTypes.kotlin (+3 -54)

📄 Description

Note to reviewers: The second commit is a rename refactoring.

codegen-kotlin: Generate toString() methods consistent with data classes

Motivation:
codegen-kotlin generates a mix of data classes and regular classes.
For regular classes, toString() methods are also generated.
However, the output of generated toString() methods
differs from the output of default toString() methods of data classes.

Changes:
Generate toString() methods that produce the same output
as default toString() methods of data classes.

Result:

  • Less and simpler code is generated.
  • Object graphs containing a mix of data classes and regular classes are formatted consistently.
  • Fixes #717.

🔄 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/793 **Author:** [@odenix](https://github.com/odenix) **Created:** 11/8/2024 **Status:** ✅ Merged **Merged:** 11/14/2024 **Merged by:** [@bioball](https://github.com/bioball) **Base:** `main` ← **Head:** `kotlin-tostring` --- ### 📝 Commits (3) - [`9cee7cc`](https://github.com/apple/pkl/commit/9cee7ccff88c957c9e05658a51bc8e8d718ebece) codegen-kotlin: Generate toString() methods consistent with data classes - [`197c68e`](https://github.com/apple/pkl/commit/197c68ed1af4267e2a1fbd7db6fbd87e6e82ab6b) Rename KotlinCodegenOptions to KotlinCodeGeneratorOptions - [`2a43194`](https://github.com/apple/pkl/commit/2a43194fc6bb4c96350226dde90aa6be4910feee) Incorporate review feedback ### 📊 Changes **6 files changed** (+86 additions, -279 deletions) <details> <summary>View changed files</summary> 📝 `pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/CliKotlinCodeGeneratorOptions.kt` (+2 -2) 📝 `pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/KotlinCodeGenerator.kt` (+25 -91) 📝 `pkl-codegen-kotlin/src/test/kotlin/org/pkl/codegen/kotlin/KotlinCodeGeneratorTest.kt` (+51 -64) 📝 `pkl-codegen-kotlin/src/test/resources/org/pkl/codegen/kotlin/Inheritance.kotlin` (+4 -45) 📝 `pkl-codegen-kotlin/src/test/resources/org/pkl/codegen/kotlin/Kdoc.kotlin` (+1 -23) 📝 `pkl-codegen-kotlin/src/test/resources/org/pkl/codegen/kotlin/PropertyTypes.kotlin` (+3 -54) </details> ### 📄 Description Note to reviewers: The second commit is a rename refactoring. codegen-kotlin: Generate toString() methods consistent with data classes Motivation: codegen-kotlin generates a mix of data classes and regular classes. For regular classes, toString() methods are also generated. However, the output of generated toString() methods differs from the output of default toString() methods of data classes. Changes: Generate toString() methods that produce the same output as default toString() methods of data classes. Result: - Less and simpler code is generated. - Object graphs containing a mix of data classes and regular classes are formatted consistently. - Fixes #717. --- <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:28 +01:00
adam closed this issue 2025-12-30 01:26:28 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#739