[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
This commit is contained in:
Andrey Zinovyev
2021-05-07 12:46:07 +03:00
committed by teamcityserver
parent 57d3f98ece
commit 468fc86a3f
3 changed files with 41 additions and 5 deletions
@@ -26,11 +26,12 @@ fun AnnotationDescriptor.getStringArgument(argumentName: String): String? {
return extractString(argument)
}
fun AnnotationDescriptor.getStringArrayArgument(argumentName: String): List<String>? {
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<String>? =
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
@@ -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
@@ -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");