mirror of
https://github.com/apple/pkl.git
synced 2026-03-21 00:29:07 +01:00
codegen-kotlin: Don't generate equals/hashCode/toString/copy/:Serializable for abstract classes (#714)
* codegen-kotlin: Don't generate equals/hashCode/toString/copy/:Serializable for abstract classes * Polish KotlinCodeGeneratorTest - use `assertContains()` instead of `assertThat().contains()` - remove redundant `trimIndent()` and `trimMargin()` calls - rename `javaCode` to `kotlinCode` * Overhaul KotlinCodeGeneratorTest - introduce classes KotlinSourceCode and KotlinSourceCodeAssert - change assertions to use KotlinSourceCodeAssert via `assertThat(kotlinCode)` - use explicit trimIndent() and trimMargin() for multiline string literals - IntelliJ editor desperately wants to insert trimIndent() - can be used by kotlinc and ktfmt - format code in the exact way it falls out of the IntelliJ editor (successfully destroyed by ktfmt)
This commit is contained in:
@@ -485,12 +485,13 @@ class KotlinCodeGenerator(
|
||||
builder.addProperty(generateProperty(name, property))
|
||||
}
|
||||
|
||||
generateCopyMethods(builder)
|
||||
|
||||
builder
|
||||
.addFunction(generateEqualsMethod())
|
||||
.addFunction(generateHashCodeMethod())
|
||||
.addFunction(generateToStringMethod())
|
||||
if (!pClass.isAbstract) {
|
||||
generateCopyMethods(builder)
|
||||
builder
|
||||
.addFunction(generateEqualsMethod())
|
||||
.addFunction(generateHashCodeMethod())
|
||||
.addFunction(generateToStringMethod())
|
||||
}
|
||||
|
||||
return builder
|
||||
}
|
||||
@@ -530,7 +531,7 @@ class KotlinCodeGenerator(
|
||||
}
|
||||
|
||||
private fun TypeSpec.Builder.ensureSerializable(): TypeSpec.Builder {
|
||||
if (!options.implementSerializable) {
|
||||
if (!options.implementSerializable || modifiers.contains(KModifier.ABSTRACT)) {
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user