mirror of
https://github.com/HighCapable/Gropify.git
synced 2025-12-10 23:33:46 +08:00
refactor: separate escaping logic for JavaPoet and KotlinPoet code generation
This commit is contained in:
@@ -27,8 +27,8 @@ import com.highcapable.gropify.plugin.config.proxy.GropifyConfig
|
|||||||
import com.highcapable.gropify.plugin.generator.config.GenerateConfig
|
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.escapeForJavaPoet
|
||||||
import com.highcapable.gropify.plugin.generator.extension.toOptimize
|
import com.highcapable.gropify.plugin.generator.extension.toOptimize
|
||||||
import com.highcapable.gropify.plugin.generator.extension.toPoetGenerationContent
|
|
||||||
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
|
||||||
@@ -71,7 +71,7 @@ internal class JavaCodeGenerator {
|
|||||||
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.toPoetGenerationContent())
|
initializer(currentValue.codeValue.escapeForJavaPoet())
|
||||||
}.build()
|
}.build()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ import com.highcapable.gropify.plugin.config.proxy.GropifyConfig
|
|||||||
import com.highcapable.gropify.plugin.generator.config.GenerateConfig
|
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.escapeForKotlinPoet
|
||||||
import com.highcapable.gropify.plugin.generator.extension.toOptimize
|
import com.highcapable.gropify.plugin.generator.extension.toOptimize
|
||||||
import com.highcapable.gropify.plugin.generator.extension.toPoetGenerationContent
|
|
||||||
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
|
||||||
@@ -72,7 +72,7 @@ internal class KotlinCodeGenerator {
|
|||||||
|
|
||||||
if (config.isRestrictedAccessEnabled) addModifiers(KModifier.INTERNAL)
|
if (config.isRestrictedAccessEnabled) addModifiers(KModifier.INTERNAL)
|
||||||
addModifiers(KModifier.CONST)
|
addModifiers(KModifier.CONST)
|
||||||
initializer(currentValue.codeValue.toPoetGenerationContent())
|
initializer(currentValue.codeValue.escapeForKotlinPoet())
|
||||||
}.build())
|
}.build())
|
||||||
}
|
}
|
||||||
}.build())
|
}.build())
|
||||||
|
|||||||
@@ -70,8 +70,15 @@ internal fun PropertyOptimizeMap.toUnderscores(): PropertyOptimizeMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Escape percentage signs and replace spaces to middle dot for code generation.
|
* Escape percentage signs for Javapoet code generation.
|
||||||
* @receiver [String]
|
* @receiver [String]
|
||||||
* @return [String]
|
* @return [String]
|
||||||
*/
|
*/
|
||||||
internal fun String.toPoetGenerationContent() = replace(" ", "·").replace("%", "%%")
|
internal fun String.escapeForJavaPoet() = replace("$", "$$")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escape percentage signs and replace spaces to middle dot for Kotlinpoet code generation.
|
||||||
|
* @receiver [String]
|
||||||
|
* @return [String]
|
||||||
|
*/
|
||||||
|
internal fun String.escapeForKotlinPoet() = replace("%", "%%").replace("$", "\\$").replace(" ", "·")
|
||||||
Reference in New Issue
Block a user