From e0109b0afc980e1fec03c32e545272f5d82d11cb Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Fri, 14 Nov 2025 17:22:21 +0800 Subject: [PATCH] refactor: update Javadoc and replace toPoetNoEscape with toPoetGenerationContent --- .../gropify/plugin/generator/BuildscriptGenerator.kt | 9 ++++----- .../gropify/plugin/generator/JavaCodeGenerator.kt | 9 ++++----- .../gropify/plugin/generator/KotlinCodeGenerator.kt | 9 ++++----- .../gropify/plugin/generator/extension/Generator.kt | 11 ++--------- 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/gropify-gradle-plugin/src/main/kotlin/com/highcapable/gropify/plugin/generator/BuildscriptGenerator.kt b/gropify-gradle-plugin/src/main/kotlin/com/highcapable/gropify/plugin/generator/BuildscriptGenerator.kt index b3bb42f..cd158b1 100644 --- a/gropify-gradle-plugin/src/main/kotlin/com/highcapable/gropify/plugin/generator/BuildscriptGenerator.kt +++ b/gropify-gradle-plugin/src/main/kotlin/com/highcapable/gropify/plugin/generator/BuildscriptGenerator.kt @@ -31,7 +31,6 @@ import com.highcapable.gropify.plugin.extension.accessors.proxy.ExtensionAccesso import com.highcapable.gropify.plugin.generator.extension.PropertyMap import com.highcapable.gropify.plugin.generator.extension.PropertyTypeValue import com.highcapable.gropify.plugin.generator.extension.toOptimize -import com.highcapable.gropify.plugin.generator.extension.toPoetNoEscape import com.highcapable.gropify.utils.extension.capitalize import com.highcapable.gropify.utils.extension.firstNumberToLetter import com.highcapable.gropify.utils.extension.uncapitalize @@ -95,7 +94,7 @@ internal class BuildscriptGenerator { private fun createClassSpec(name: String, accessorsName: String = "", isInner: Boolean = true) = TypeSpec.classBuilder(if (isInner) name.capitalized() else name).apply { if (isInner) { - addJavadoc("The \"$accessorsName\" accessors.") + addJavadoc("The \$S accessors.", accessorsName) addSuperinterface(classOf()) addModifiers(Modifier.PUBLIC, Modifier.STATIC) @@ -117,14 +116,14 @@ internal class BuildscriptGenerator { private fun TypeSpec.Builder.addSuccessiveField(accessorsName: String, className: String) = addField( FieldSpec.builder(className.capitalized().asClassType(), className.uncapitalized(), Modifier.PRIVATE, Modifier.FINAL).apply { - addJavadoc("Create the \"$accessorsName\" accessors.") + addJavadoc("Create the \$S accessors.", accessorsName) }.build() ) private fun TypeSpec.Builder.addSuccessiveMethod(accessorsName: String, methodName: String, className: String) = addMethod( MethodSpec.methodBuilder("get${getOrCreateUsedSuccessiveMethodName(methodName, className).capitalize()}").apply { - addJavadoc("Resolve the \"$accessorsName\" accessors.") + addJavadoc("Resolve the \$S accessors.", accessorsName) addModifiers(Modifier.PUBLIC, Modifier.FINAL) returns(className.capitalized().asClassType()) @@ -137,7 +136,7 @@ internal class BuildscriptGenerator { MethodSpec.methodBuilder("get${getOrCreateUsedSuccessiveMethodName(methodName, className).capitalize()}").apply { val safeValueForJavadoc = value.codeValue.replace("$", "$$") - addJavadoc("Resolve the \"$accessorsName\" value \"${value.raw.toPoetNoEscape()}\".") + addJavadoc("Resolve the \$S value \$S.", accessorsName, value.raw) addModifiers(Modifier.PUBLIC, Modifier.FINAL) returns(value.type.java) diff --git a/gropify-gradle-plugin/src/main/kotlin/com/highcapable/gropify/plugin/generator/JavaCodeGenerator.kt b/gropify-gradle-plugin/src/main/kotlin/com/highcapable/gropify/plugin/generator/JavaCodeGenerator.kt index f5d2704..a253a08 100644 --- a/gropify-gradle-plugin/src/main/kotlin/com/highcapable/gropify/plugin/generator/JavaCodeGenerator.kt +++ b/gropify-gradle-plugin/src/main/kotlin/com/highcapable/gropify/plugin/generator/JavaCodeGenerator.kt @@ -28,8 +28,7 @@ import com.highcapable.gropify.plugin.generator.config.GenerateConfig import com.highcapable.gropify.plugin.generator.config.SourceCodeSpec import com.highcapable.gropify.plugin.generator.extension.PropertyMap import com.highcapable.gropify.plugin.generator.extension.toOptimize -import com.highcapable.gropify.plugin.generator.extension.toPoetNoEscape -import com.highcapable.gropify.plugin.generator.extension.toPoetSpace +import com.highcapable.gropify.plugin.generator.extension.toPoetGenerationContent import com.highcapable.gropify.plugin.generator.extension.toUnderscores import com.highcapable.gropify.utils.extension.firstNumberToLetter import com.palantir.javapoet.ClassName @@ -66,13 +65,13 @@ internal class JavaCodeGenerator { addField( FieldSpec.builder(currentValue.type.java, key.firstNumberToLetter()).apply { - addJavadoc("Resolve the \"${currentKey.toPoetNoEscape()}\" value \"${currentValue.raw.toPoetNoEscape()}\".") + addJavadoc("Resolve the \$S value \$S.", currentKey, currentValue.raw) if (!config.isRestrictedAccessEnabled) addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL) else addModifiers(Modifier.STATIC, Modifier.FINAL) - initializer(currentValue.codeValue.toPoetNoEscape().toPoetSpace()) + initializer(currentValue.codeValue.toPoetGenerationContent()) }.build() ) } @@ -88,5 +87,5 @@ internal class JavaCodeGenerator { ) }.build() SourceCodeSpec(SourceCodeSpec.Type.Java, javaFile) - }.getOrElse { Gropify.error("Failed to generated Java file.\n$it") } + }.getOrElse { Gropify.error("Failed to generated Java file.\n${it.stackTraceToString()}") } } \ No newline at end of file diff --git a/gropify-gradle-plugin/src/main/kotlin/com/highcapable/gropify/plugin/generator/KotlinCodeGenerator.kt b/gropify-gradle-plugin/src/main/kotlin/com/highcapable/gropify/plugin/generator/KotlinCodeGenerator.kt index a922c0e..98140b0 100644 --- a/gropify-gradle-plugin/src/main/kotlin/com/highcapable/gropify/plugin/generator/KotlinCodeGenerator.kt +++ b/gropify-gradle-plugin/src/main/kotlin/com/highcapable/gropify/plugin/generator/KotlinCodeGenerator.kt @@ -28,8 +28,7 @@ import com.highcapable.gropify.plugin.generator.config.GenerateConfig import com.highcapable.gropify.plugin.generator.config.SourceCodeSpec import com.highcapable.gropify.plugin.generator.extension.PropertyMap import com.highcapable.gropify.plugin.generator.extension.toOptimize -import com.highcapable.gropify.plugin.generator.extension.toPoetNoEscape -import com.highcapable.gropify.plugin.generator.extension.toPoetSpace +import com.highcapable.gropify.plugin.generator.extension.toPoetGenerationContent import com.highcapable.gropify.plugin.generator.extension.toUnderscores import com.highcapable.gropify.utils.extension.firstNumberToLetter import com.squareup.kotlinpoet.FileSpec @@ -69,16 +68,16 @@ internal class KotlinCodeGenerator { val currentValue = value.second addProperty(PropertySpec.builder(key.firstNumberToLetter(), currentValue.type).apply { - addKdoc("Resolve the \"${currentKey.toPoetNoEscape()}\" value \"${currentValue.raw.toPoetNoEscape()}\".") + addKdoc("Resolve the %S value %S.", currentKey, currentValue.raw) if (config.isRestrictedAccessEnabled) addModifiers(KModifier.INTERNAL) addModifiers(KModifier.CONST) - initializer(currentValue.codeValue.toPoetNoEscape().toPoetSpace()) + initializer(currentValue.codeValue.toPoetGenerationContent()) }.build()) } }.build()) }.build() SourceCodeSpec(SourceCodeSpec.Type.Kotlin, fileSpec) - }.getOrElse { Gropify.error("Failed to generated Kotlin file.\n$it") } + }.getOrElse { Gropify.error("Failed to generated Kotlin file.\n${it.stackTraceToString()}") } } \ No newline at end of file diff --git a/gropify-gradle-plugin/src/main/kotlin/com/highcapable/gropify/plugin/generator/extension/Generator.kt b/gropify-gradle-plugin/src/main/kotlin/com/highcapable/gropify/plugin/generator/extension/Generator.kt index 8d4a3b4..efabeb1 100644 --- a/gropify-gradle-plugin/src/main/kotlin/com/highcapable/gropify/plugin/generator/extension/Generator.kt +++ b/gropify-gradle-plugin/src/main/kotlin/com/highcapable/gropify/plugin/generator/extension/Generator.kt @@ -70,15 +70,8 @@ internal fun PropertyOptimizeMap.toUnderscores(): PropertyOptimizeMap { } /** - * Replace spaces to middle dot for code generation. + * Escape percentage signs and replace spaces to middle dot for code generation. * @receiver [String] * @return [String] */ -internal fun String.toPoetSpace() = replace(" ", "·") - -/** - * Escape percentage signs for code generation. - * @receiver [String] - * @return [String] - */ -internal fun String.toPoetNoEscape() = replace("%", "%%") \ No newline at end of file +internal fun String.toPoetGenerationContent() = replace(" ", "·").replace("%", "%%") \ No newline at end of file