[Lombok K1] Fix name convention for @With on boolean fields
^KT-53370 Fixed
This commit is contained in:
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.lombok.config.LombokAnnotations.With
|
||||
import org.jetbrains.kotlin.lombok.config.toDescriptorVisibility
|
||||
import org.jetbrains.kotlin.lombok.utils.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.typeUtil.isBoolean
|
||||
|
||||
class WithProcessor : Processor {
|
||||
override fun contribute(classDescriptor: ClassDescriptor, partsBuilder: SyntheticPartsBuilder) {
|
||||
@@ -32,7 +33,14 @@ class WithProcessor : Processor {
|
||||
): SimpleFunctionDescriptor? {
|
||||
if (with.visibility == AccessLevel.NONE) return null
|
||||
|
||||
val functionName = "with" + toPropertyNameCapitalized(field.name.identifier)
|
||||
val rawPropertyName = field.name.identifier
|
||||
val propertyName = if (field.type.isBoolean() && rawPropertyName.startsWith("is")) {
|
||||
rawPropertyName.removePrefix("is")
|
||||
} else {
|
||||
rawPropertyName
|
||||
}
|
||||
|
||||
val functionName = "with" + toPropertyNameCapitalized(propertyName)
|
||||
|
||||
return classDescriptor.createFunction(
|
||||
Name.identifier(functionName),
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// ISSUE: KT-53451, KT-53370
|
||||
|
||||
// FILE: UserData.java
|
||||
import lombok.*;
|
||||
|
||||
public class UserData {
|
||||
@With @Getter
|
||||
private final String name;
|
||||
|
||||
@With @Getter
|
||||
private final boolean isSome;
|
||||
|
||||
@With @Getter
|
||||
private final boolean hasFlag;
|
||||
|
||||
@With @Getter
|
||||
private final boolean justAnother;
|
||||
|
||||
public UserData(String name, boolean isSome, boolean hasFlag, boolean justAnother) {
|
||||
this.name = name;
|
||||
this.isSome = isSome;
|
||||
this.hasFlag = hasFlag;
|
||||
this.justAnother = justAnother;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun box(): String {
|
||||
val user = UserData("Bob", false, false, false)
|
||||
val modifiedUser = user
|
||||
.withName("Alex")
|
||||
.withSome(true)
|
||||
.withHasFlag(true)
|
||||
.withJustAnother(true)
|
||||
|
||||
return if (modifiedUser.name == "Alex" && modifiedUser.isSome && modifiedUser.isHasFlag && modifiedUser.isJustAnother) {
|
||||
"OK"
|
||||
} else {
|
||||
"Error"
|
||||
}
|
||||
}
|
||||
Generated
+6
@@ -162,4 +162,10 @@ public class BlackBoxCodegenTestForLombokGenerated extends AbstractBlackBoxCodeg
|
||||
public void testWith() throws Exception {
|
||||
runTest("plugins/lombok/testData/box/with.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("withBooleanField.kt")
|
||||
public void testWithBooleanField() throws Exception {
|
||||
runTest("plugins/lombok/testData/box/withBooleanField.kt");
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+6
@@ -162,4 +162,10 @@ public class FirBlackBoxCodegenTestForLombokGenerated extends AbstractFirBlackBo
|
||||
public void testWith() throws Exception {
|
||||
runTest("plugins/lombok/testData/box/with.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("withBooleanField.kt")
|
||||
public void testWithBooleanField() throws Exception {
|
||||
runTest("plugins/lombok/testData/box/withBooleanField.kt");
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+6
@@ -162,4 +162,10 @@ public class IrBlackBoxCodegenTestForLombokGenerated extends AbstractIrBlackBoxC
|
||||
public void testWith() throws Exception {
|
||||
runTest("plugins/lombok/testData/box/with.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("withBooleanField.kt")
|
||||
public void testWithBooleanField() throws Exception {
|
||||
runTest("plugins/lombok/testData/box/withBooleanField.kt");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user