feat: let generator use typed value

This commit is contained in:
2023-09-04 02:00:16 +08:00
parent 6a0c581ccb
commit e113c45a5d
2 changed files with 8 additions and 8 deletions

View File

@@ -194,13 +194,13 @@ internal class PropertiesAccessorsGenerator {
*/
private fun TypeSpec.Builder.addFinalValueMethod(accessorsName: String, methodName: String, value: Any) =
addMethod(
MethodSpec.methodBuilder("get${methodName.capitalize()}")
.addJavadoc("Resolve the \"$accessorsName\" value \"$value\"")
.addModifiers(Modifier.PUBLIC, Modifier.FINAL).apply {
val typedValue = value.parseTypedValue(configs.isEnableTypeAutoConversion)
returns(typedValue.first.java)
addStatement("return ${typedValue.second}")
}.build()
MethodSpec.methodBuilder("get${methodName.capitalize()}").apply {
val typedValue = value.parseTypedValue(configs.isEnableTypeAutoConversion)
addJavadoc("Resolve the \"$accessorsName\" value ${typedValue.second}")
addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.returns(typedValue.first.java)
.addStatement("return ${typedValue.second}")
}.build()
)
/**

View File

@@ -70,7 +70,7 @@ internal class PropertiesSourcesGenerator {
keyValues.forEach { (key, value) ->
val typedValue = value.parseTypedValue(configs.isEnableTypeAutoConversion)
addProperty(PropertySpec.builder(key.firstNumberToLetter().underscore(), typedValue.first).apply {
addKdoc("Resolve the \"$key\" value \"$value\"")
addKdoc("Resolve the \"$key\" value ${typedValue.second}")
if (configs.isEnableRestrictedAccess) addModifiers(KModifier.INTERNAL)
addModifiers(KModifier.CONST)
initializer(typedValue.second.toKotlinPoetSpace())