mirror of
https://github.com/HighCapable/SweetProperty.git
synced 2025-09-04 01:35:37 +08:00
feat: let generator use typed value
This commit is contained in:
@@ -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()
|
||||
)
|
||||
|
||||
/**
|
||||
|
@@ -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())
|
||||
|
Reference in New Issue
Block a user