mirror of
https://github.com/HighCapable/Gropify.git
synced 2025-12-12 00:03:56 +08:00
refactor: update Javadoc and replace toPoetNoEscape with toPoetGenerationContent
This commit is contained in:
@@ -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.PropertyMap
|
||||||
import com.highcapable.gropify.plugin.generator.extension.PropertyTypeValue
|
import com.highcapable.gropify.plugin.generator.extension.PropertyTypeValue
|
||||||
import com.highcapable.gropify.plugin.generator.extension.toOptimize
|
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.capitalize
|
||||||
import com.highcapable.gropify.utils.extension.firstNumberToLetter
|
import com.highcapable.gropify.utils.extension.firstNumberToLetter
|
||||||
import com.highcapable.gropify.utils.extension.uncapitalize
|
import com.highcapable.gropify.utils.extension.uncapitalize
|
||||||
@@ -95,7 +94,7 @@ internal class BuildscriptGenerator {
|
|||||||
private fun createClassSpec(name: String, accessorsName: String = "", isInner: Boolean = true) =
|
private fun createClassSpec(name: String, accessorsName: String = "", isInner: Boolean = true) =
|
||||||
TypeSpec.classBuilder(if (isInner) name.capitalized() else name).apply {
|
TypeSpec.classBuilder(if (isInner) name.capitalized() else name).apply {
|
||||||
if (isInner) {
|
if (isInner) {
|
||||||
addJavadoc("The \"$accessorsName\" accessors.")
|
addJavadoc("The \$S accessors.", accessorsName)
|
||||||
|
|
||||||
addSuperinterface(classOf<ExtensionAccessors>())
|
addSuperinterface(classOf<ExtensionAccessors>())
|
||||||
addModifiers(Modifier.PUBLIC, Modifier.STATIC)
|
addModifiers(Modifier.PUBLIC, Modifier.STATIC)
|
||||||
@@ -117,14 +116,14 @@ internal class BuildscriptGenerator {
|
|||||||
|
|
||||||
private fun TypeSpec.Builder.addSuccessiveField(accessorsName: String, className: String) = addField(
|
private fun TypeSpec.Builder.addSuccessiveField(accessorsName: String, className: String) = addField(
|
||||||
FieldSpec.builder(className.capitalized().asClassType(), className.uncapitalized(), Modifier.PRIVATE, Modifier.FINAL).apply {
|
FieldSpec.builder(className.capitalized().asClassType(), className.uncapitalized(), Modifier.PRIVATE, Modifier.FINAL).apply {
|
||||||
addJavadoc("Create the \"$accessorsName\" accessors.")
|
addJavadoc("Create the \$S accessors.", accessorsName)
|
||||||
}.build()
|
}.build()
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun TypeSpec.Builder.addSuccessiveMethod(accessorsName: String, methodName: String, className: String) =
|
private fun TypeSpec.Builder.addSuccessiveMethod(accessorsName: String, methodName: String, className: String) =
|
||||||
addMethod(
|
addMethod(
|
||||||
MethodSpec.methodBuilder("get${getOrCreateUsedSuccessiveMethodName(methodName, className).capitalize()}").apply {
|
MethodSpec.methodBuilder("get${getOrCreateUsedSuccessiveMethodName(methodName, className).capitalize()}").apply {
|
||||||
addJavadoc("Resolve the \"$accessorsName\" accessors.")
|
addJavadoc("Resolve the \$S accessors.", accessorsName)
|
||||||
|
|
||||||
addModifiers(Modifier.PUBLIC, Modifier.FINAL)
|
addModifiers(Modifier.PUBLIC, Modifier.FINAL)
|
||||||
returns(className.capitalized().asClassType())
|
returns(className.capitalized().asClassType())
|
||||||
@@ -137,7 +136,7 @@ internal class BuildscriptGenerator {
|
|||||||
MethodSpec.methodBuilder("get${getOrCreateUsedSuccessiveMethodName(methodName, className).capitalize()}").apply {
|
MethodSpec.methodBuilder("get${getOrCreateUsedSuccessiveMethodName(methodName, className).capitalize()}").apply {
|
||||||
val safeValueForJavadoc = value.codeValue.replace("$", "$$")
|
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)
|
addModifiers(Modifier.PUBLIC, Modifier.FINAL)
|
||||||
returns(value.type.java)
|
returns(value.type.java)
|
||||||
|
|||||||
@@ -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.config.SourceCodeSpec
|
||||||
import com.highcapable.gropify.plugin.generator.extension.PropertyMap
|
import com.highcapable.gropify.plugin.generator.extension.PropertyMap
|
||||||
import com.highcapable.gropify.plugin.generator.extension.toOptimize
|
import com.highcapable.gropify.plugin.generator.extension.toOptimize
|
||||||
import com.highcapable.gropify.plugin.generator.extension.toPoetNoEscape
|
import com.highcapable.gropify.plugin.generator.extension.toPoetGenerationContent
|
||||||
import com.highcapable.gropify.plugin.generator.extension.toPoetSpace
|
|
||||||
import com.highcapable.gropify.plugin.generator.extension.toUnderscores
|
import com.highcapable.gropify.plugin.generator.extension.toUnderscores
|
||||||
import com.highcapable.gropify.utils.extension.firstNumberToLetter
|
import com.highcapable.gropify.utils.extension.firstNumberToLetter
|
||||||
import com.palantir.javapoet.ClassName
|
import com.palantir.javapoet.ClassName
|
||||||
@@ -66,13 +65,13 @@ internal class JavaCodeGenerator {
|
|||||||
|
|
||||||
addField(
|
addField(
|
||||||
FieldSpec.builder(currentValue.type.java, key.firstNumberToLetter()).apply {
|
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)
|
if (!config.isRestrictedAccessEnabled)
|
||||||
addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
|
addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
|
||||||
else addModifiers(Modifier.STATIC, Modifier.FINAL)
|
else addModifiers(Modifier.STATIC, Modifier.FINAL)
|
||||||
|
|
||||||
initializer(currentValue.codeValue.toPoetNoEscape().toPoetSpace())
|
initializer(currentValue.codeValue.toPoetGenerationContent())
|
||||||
}.build()
|
}.build()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -88,5 +87,5 @@ internal class JavaCodeGenerator {
|
|||||||
)
|
)
|
||||||
}.build()
|
}.build()
|
||||||
SourceCodeSpec(SourceCodeSpec.Type.Java, javaFile)
|
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()}") }
|
||||||
}
|
}
|
||||||
@@ -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.config.SourceCodeSpec
|
||||||
import com.highcapable.gropify.plugin.generator.extension.PropertyMap
|
import com.highcapable.gropify.plugin.generator.extension.PropertyMap
|
||||||
import com.highcapable.gropify.plugin.generator.extension.toOptimize
|
import com.highcapable.gropify.plugin.generator.extension.toOptimize
|
||||||
import com.highcapable.gropify.plugin.generator.extension.toPoetNoEscape
|
import com.highcapable.gropify.plugin.generator.extension.toPoetGenerationContent
|
||||||
import com.highcapable.gropify.plugin.generator.extension.toPoetSpace
|
|
||||||
import com.highcapable.gropify.plugin.generator.extension.toUnderscores
|
import com.highcapable.gropify.plugin.generator.extension.toUnderscores
|
||||||
import com.highcapable.gropify.utils.extension.firstNumberToLetter
|
import com.highcapable.gropify.utils.extension.firstNumberToLetter
|
||||||
import com.squareup.kotlinpoet.FileSpec
|
import com.squareup.kotlinpoet.FileSpec
|
||||||
@@ -69,16 +68,16 @@ internal class KotlinCodeGenerator {
|
|||||||
val currentValue = value.second
|
val currentValue = value.second
|
||||||
|
|
||||||
addProperty(PropertySpec.builder(key.firstNumberToLetter(), currentValue.type).apply {
|
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)
|
if (config.isRestrictedAccessEnabled) addModifiers(KModifier.INTERNAL)
|
||||||
addModifiers(KModifier.CONST)
|
addModifiers(KModifier.CONST)
|
||||||
initializer(currentValue.codeValue.toPoetNoEscape().toPoetSpace())
|
initializer(currentValue.codeValue.toPoetGenerationContent())
|
||||||
}.build())
|
}.build())
|
||||||
}
|
}
|
||||||
}.build())
|
}.build())
|
||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
SourceCodeSpec(SourceCodeSpec.Type.Kotlin, fileSpec)
|
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()}") }
|
||||||
}
|
}
|
||||||
@@ -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]
|
* @receiver [String]
|
||||||
* @return [String]
|
* @return [String]
|
||||||
*/
|
*/
|
||||||
internal fun String.toPoetSpace() = replace(" ", "·")
|
internal fun String.toPoetGenerationContent() = replace(" ", "·").replace("%", "%%")
|
||||||
|
|
||||||
/**
|
|
||||||
* Escape percentage signs for code generation.
|
|
||||||
* @receiver [String]
|
|
||||||
* @return [String]
|
|
||||||
*/
|
|
||||||
internal fun String.toPoetNoEscape() = replace("%", "%%")
|
|
||||||
Reference in New Issue
Block a user