mirror of
https://github.com/HighCapable/SweetProperty.git
synced 2025-09-06 02:35:28 +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) =
|
private fun TypeSpec.Builder.addFinalValueMethod(accessorsName: String, methodName: String, value: Any) =
|
||||||
addMethod(
|
addMethod(
|
||||||
MethodSpec.methodBuilder("get${methodName.capitalize()}")
|
MethodSpec.methodBuilder("get${methodName.capitalize()}").apply {
|
||||||
.addJavadoc("Resolve the \"$accessorsName\" value \"$value\"")
|
val typedValue = value.parseTypedValue(configs.isEnableTypeAutoConversion)
|
||||||
.addModifiers(Modifier.PUBLIC, Modifier.FINAL).apply {
|
addJavadoc("Resolve the \"$accessorsName\" value ${typedValue.second}")
|
||||||
val typedValue = value.parseTypedValue(configs.isEnableTypeAutoConversion)
|
addModifiers(Modifier.PUBLIC, Modifier.FINAL)
|
||||||
returns(typedValue.first.java)
|
.returns(typedValue.first.java)
|
||||||
addStatement("return ${typedValue.second}")
|
.addStatement("return ${typedValue.second}")
|
||||||
}.build()
|
}.build()
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -70,7 +70,7 @@ internal class PropertiesSourcesGenerator {
|
|||||||
keyValues.forEach { (key, value) ->
|
keyValues.forEach { (key, value) ->
|
||||||
val typedValue = value.parseTypedValue(configs.isEnableTypeAutoConversion)
|
val typedValue = value.parseTypedValue(configs.isEnableTypeAutoConversion)
|
||||||
addProperty(PropertySpec.builder(key.firstNumberToLetter().underscore(), typedValue.first).apply {
|
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)
|
if (configs.isEnableRestrictedAccess) addModifiers(KModifier.INTERNAL)
|
||||||
addModifiers(KModifier.CONST)
|
addModifiers(KModifier.CONST)
|
||||||
initializer(typedValue.second.toKotlinPoetSpace())
|
initializer(typedValue.second.toKotlinPoetSpace())
|
||||||
|
Reference in New Issue
Block a user