From 6c5835bc72400f8378ca5655fa6a76859f3fffc1 Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Sat, 4 Nov 2023 01:40:50 +0800 Subject: [PATCH] feat: remove auto conversion if it's an interpolation --- .../plugin/generator/factory/GeneratorFactory.kt | 6 ++++++ .../sweetproperty/plugin/helper/PropertiesDeployHelper.kt | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sweetproperty-gradle-plugin/src/main/java/com/highcapable/sweetproperty/plugin/generator/factory/GeneratorFactory.kt b/sweetproperty-gradle-plugin/src/main/java/com/highcapable/sweetproperty/plugin/generator/factory/GeneratorFactory.kt index c5b0f23..eedf499 100644 --- a/sweetproperty-gradle-plugin/src/main/java/com/highcapable/sweetproperty/plugin/generator/factory/GeneratorFactory.kt +++ b/sweetproperty-gradle-plugin/src/main/java/com/highcapable/sweetproperty/plugin/generator/factory/GeneratorFactory.kt @@ -29,6 +29,12 @@ internal typealias PropertyMap = MutableMap /** 属性键值规则类型定义 */ internal typealias PropertyValueRule = (value: String) -> String +/** + * 移除键值内容自动转换类型的引号 + * @return [String] + */ +internal fun String.removeAutoConversion() = removeSurrounding("\"").removeSurrounding("'") + /** * 解析到键值内容类型 * @param isAutoConversion 是否自动转换类型 diff --git a/sweetproperty-gradle-plugin/src/main/java/com/highcapable/sweetproperty/plugin/helper/PropertiesDeployHelper.kt b/sweetproperty-gradle-plugin/src/main/java/com/highcapable/sweetproperty/plugin/helper/PropertiesDeployHelper.kt index 1d3a664..21bede2 100644 --- a/sweetproperty-gradle-plugin/src/main/java/com/highcapable/sweetproperty/plugin/helper/PropertiesDeployHelper.kt +++ b/sweetproperty-gradle-plugin/src/main/java/com/highcapable/sweetproperty/plugin/helper/PropertiesDeployHelper.kt @@ -36,6 +36,7 @@ import com.highcapable.sweetproperty.plugin.config.type.GenerateLocationType import com.highcapable.sweetproperty.plugin.generator.PropertiesAccessorsGenerator import com.highcapable.sweetproperty.plugin.generator.PropertiesSourcesGenerator import com.highcapable.sweetproperty.plugin.generator.factory.PropertyMap +import com.highcapable.sweetproperty.plugin.generator.factory.removeAutoConversion import com.highcapable.sweetproperty.utils.camelcase import com.highcapable.sweetproperty.utils.code.entity.MavenPomData import com.highcapable.sweetproperty.utils.code.factory.compile @@ -293,7 +294,8 @@ internal object PropertiesDeployHelper { fun String.resolveValue(): String = replaceInterpolation { matchKey -> if (resolveKeys.size > 5) SError.make("Key \"$key\" has been called recursively multiple times of those $resolveKeys") resolveKeys.add(matchKey) - val resolveValue = if (configs.isEnableValueInterpolation) resolveKeyValues[matchKey] ?: "" else matchKey + var resolveValue = if (configs.isEnableValueInterpolation) resolveKeyValues[matchKey] ?: "" else matchKey + resolveValue = resolveValue.removeAutoConversion() if (resolveValue.hasInterpolation()) resolveValue.resolveValue() else resolveValue }