From 468fc86a3fcf686f608f0617abd2a4b1a422c907 Mon Sep 17 00:00:00 2001 From: Andrey Zinovyev Date: Fri, 7 May 2021 12:46:07 +0300 Subject: [PATCH] [lombok] Fix fallback to config for array annotation's parameter If annotation's parameter is not explicitly defined, it should be taken from config #KT-46529 Fixed --- .../kotlin/lombok/utils/annotationUtils.kt | 11 +++---- .../compile/accessorsStripPrefixCombined.kt | 30 +++++++++++++++++++ .../lombok/LombokCompileTestGenerated.java | 5 ++++ 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 plugins/lombok/lombok-compiler-plugin/testData/compile/accessorsStripPrefixCombined.kt diff --git a/plugins/lombok/lombok-compiler-plugin/src/org/jetbrains/kotlin/lombok/utils/annotationUtils.kt b/plugins/lombok/lombok-compiler-plugin/src/org/jetbrains/kotlin/lombok/utils/annotationUtils.kt index ae99965c00c..314f272559f 100644 --- a/plugins/lombok/lombok-compiler-plugin/src/org/jetbrains/kotlin/lombok/utils/annotationUtils.kt +++ b/plugins/lombok/lombok-compiler-plugin/src/org/jetbrains/kotlin/lombok/utils/annotationUtils.kt @@ -26,11 +26,12 @@ fun AnnotationDescriptor.getStringArgument(argumentName: String): String? { return extractString(argument) } -fun AnnotationDescriptor.getStringArrayArgument(argumentName: String): List? { - val argument = allValueArguments[Name.identifier(argumentName)] ?: return emptyList() - if (argument !is ArrayValue) throw RuntimeException("Argument should be ArrayValue, got $argument") - return argument.value.map(::extractString) -} +fun AnnotationDescriptor.getStringArrayArgument(argumentName: String): List? = + when (val argument = allValueArguments[Name.identifier(argumentName)]) { + null -> null + is ArrayValue -> argument.value.map(::extractString) + else -> throw RuntimeException("Argument should be ArrayValue, got $argument") + } private fun extractString(argument: ConstantValue<*>) = when (argument) { is EnumValue -> argument.enumEntryName.identifier diff --git a/plugins/lombok/lombok-compiler-plugin/testData/compile/accessorsStripPrefixCombined.kt b/plugins/lombok/lombok-compiler-plugin/testData/compile/accessorsStripPrefixCombined.kt new file mode 100644 index 00000000000..9dc69812c90 --- /dev/null +++ b/plugins/lombok/lombok-compiler-plugin/testData/compile/accessorsStripPrefixCombined.kt @@ -0,0 +1,30 @@ +//KT-46529 + +//FILE: PrefixJava.java + +import lombok.*; +import lombok.experimental.*; + +@Getter @Setter @Accessors(chain = false, fluent = true, prefix = {"pxo"}) +public class PrefixJava { + private String pxaPropA = "A"; + @Accessors(chain = true) private String pxoPropC = "C"; + @Accessors private String pxaPropD = "D"; +} + + +//FILE: test.kt + +class Test { + fun run() { + //not generated because doesn't have prefix from class level @Accessors + //assertEquals(PrefixJava().propA, "A") + //not generated because doesn't have prefix from config + //assertEquals(PrefixJava().propC, "C") + assertEquals(PrefixJava().propD, "D") + } + +} + +//FILE: lombok.config +lombok.accessors.prefix += pxa diff --git a/plugins/lombok/lombok-compiler-plugin/tests/org/jetbrains/kotlin/lombok/LombokCompileTestGenerated.java b/plugins/lombok/lombok-compiler-plugin/tests/org/jetbrains/kotlin/lombok/LombokCompileTestGenerated.java index 526223f4399..2c74b502cf8 100644 --- a/plugins/lombok/lombok-compiler-plugin/tests/org/jetbrains/kotlin/lombok/LombokCompileTestGenerated.java +++ b/plugins/lombok/lombok-compiler-plugin/tests/org/jetbrains/kotlin/lombok/LombokCompileTestGenerated.java @@ -30,6 +30,11 @@ public class LombokCompileTestGenerated extends AbstractLombokCompileTest { runTest("plugins/lombok/lombok-compiler-plugin/testData/compile/accessorsStripPrefix.kt"); } + @TestMetadata("accessorsStripPrefixCombined.kt") + public void testAccessorsStripPrefixCombined() throws Exception { + runTest("plugins/lombok/lombok-compiler-plugin/testData/compile/accessorsStripPrefixCombined.kt"); + } + @TestMetadata("accessorsStripPrefixConfig.kt") public void testAccessorsStripPrefixConfig() throws Exception { runTest("plugins/lombok/lombok-compiler-plugin/testData/compile/accessorsStripPrefixConfig.kt");