build(generator): ast enum content for numbers
Take into account cases, when enum value can be a number.
This commit is contained in:
1 parent
588903f7f7
commit
7b8ca029c0
1 file changed
+13
-2
@@ -10,7 +10,6 @@ fun astEnumContent(markerAnnotation: CtAnnotation<*>): List<String> {
|
||||
|
||||
val file = markerAnnotation.getValueAsString(A_VALUE_FILE)!!
|
||||
val qualType = markerAnnotation.getValueAsString(A_VALUE_QUAL_TYPE)!!
|
||||
val sanitizeName = markerAnnotation.getValueAsString(A_VALUE_SANITIZE_NAME)?.takeIf(String::isNotEmpty) ?: qualType
|
||||
val astRoot = AstParser.readFromResource(file)
|
||||
|
||||
val enums = astRoot.decls.filterDecls0 {
|
||||
@@ -24,7 +23,7 @@ fun astEnumContent(markerAnnotation: CtAnnotation<*>): List<String> {
|
||||
|
||||
f.setModifiers<Nothing>(setOf(ModifierKind.PUBLIC, ModifierKind.STATIC, ModifierKind.FINAL))
|
||||
f.setType<Nothing>(factory.createTypeParam("int"))
|
||||
f.setSimpleName<Nothing>(e.name.replace(sanitizeName, ""))
|
||||
f.setSimpleName<Nothing>(sanitizeName(markerAnnotation.getValueSanitizeName(qualType), e.name))
|
||||
buildString {
|
||||
if (e.docComment != null) {
|
||||
appendLine(e.docComment)
|
||||
@@ -49,6 +48,18 @@ fun astEnumContent(markerAnnotation: CtAnnotation<*>): List<String> {
|
||||
return result
|
||||
}
|
||||
|
||||
private fun CtAnnotation<*>.getValueSanitizeName(default: String): String {
|
||||
return getValueAsString(A_VALUE_SANITIZE_NAME)?.takeIf(String::isNotEmpty) ?: default
|
||||
}
|
||||
|
||||
private fun sanitizeName(aValueSanitizeName: String, name: String): String {
|
||||
var result = name.replace(aValueSanitizeName, "").trim()
|
||||
if (result.toIntOrNull() != null) {
|
||||
result = "_$result"
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private fun sanitizeDocComment(doc: String): String {
|
||||
return doc
|
||||
.replace("*/", "* /")
|
||||
|
||||
Reference in new issue
Block a user