[lombok] Config keys are case-insensitive

#KT-46531 Fixed
This commit is contained in:
Andrey Zinovyev
2021-05-07 11:09:28 +03:00
committed by teamcityserver
parent c898805ac5
commit 57d3f98ece
3 changed files with 45 additions and 6 deletions
@@ -9,11 +9,13 @@ import java.io.File
class LombokConfig(private val config: Map<String, List<String>>) {
fun getString(key: String): String? = config[key]?.firstOrNull()
fun getString(key: String): String? = getValue(key)?.firstOrNull()
fun getBoolean(key: String): Boolean? = getString(key)?.toBoolean()
fun getMultiString(key: String): List<String>? = config[key]
fun getMultiString(key: String): List<String>? = getValue(key)
private fun getValue(key: String): List<String>? = config[normalizeKey(key)]
companion object {
@@ -67,22 +69,25 @@ class ConfigBuilder {
private val state: MutableMap<String, List<String>> = mutableMapOf()
fun setValue(name: String, value: String) {
state[name] = listOf(value)
state[normalizeKey(name)] = listOf(value)
}
fun clearValue(name: String) {
state.remove(name)
state.remove(normalizeKey(name))
}
fun plusValue(name: String, value: String) {
state.merge(name, listOf(value)) { a, b -> a + b }
state.merge(normalizeKey(name), listOf(value)) { a, b -> a + b }
}
fun minusValue(name: String, value: String) {
state.merge(name, listOf(value)) { a, b -> a - b }
state.merge(normalizeKey(name), listOf(value)) { a, b -> a - b }
}
fun build(): LombokConfig = LombokConfig(state)
}
//lombok config keys are case insensitive
private fun normalizeKey(key: String): String = key.lowercase()
@@ -0,0 +1,29 @@
//FILE: GetterTest.java
import lombok.AccessLevel;
import lombok.Getter;
public class GetterTest {
@Getter private boolean primitiveBoolean;
void test() {
getPrimitiveBoolean();
}
}
//FILE: test.kt
class Test {
fun run() {
val obj = GetterTest()
obj.primitiveBoolean
obj.getPrimitiveBoolean()
}
}
//FILE: lombok.config
#lombok config keys are case insensitive
lombok.getter.noisprefix=true
@@ -64,6 +64,11 @@ public class LombokCompileTestGenerated extends AbstractLombokCompileTest {
runTest("plugins/lombok/lombok-compiler-plugin/testData/compile/configAccessorsOverride.kt");
}
@TestMetadata("configCaseInsensitive.kt")
public void testConfigCaseInsensitive() throws Exception {
runTest("plugins/lombok/lombok-compiler-plugin/testData/compile/configCaseInsensitive.kt");
}
@TestMetadata("configSimple.kt")
public void testConfigSimple() throws Exception {
runTest("plugins/lombok/lombok-compiler-plugin/testData/compile/configSimple.kt");