Skip to content

Commit 6a385dc

Browse files
committed
feat: Fix field name and java_outer_classname file option
1 parent db88e44 commit 6a385dc

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/main/kotlin/com/fnakhsan/toprotobufconverter/converter/parser/KotlinDataTypeParser.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ class KotlinDataTypeParser : DataTypeParser {
6363
.replace("java.lang.", ""), numericPref = numericPref
6464
)
6565
} else if (this.presentableText.contains("Map")) {
66-
val mapValue = this.presentableText.removePrefix("Map<").removeSuffix(">").replace(" ", "").split(",")
66+
val mapValue =
67+
this.presentableText.removePrefix("Map<").removeSuffix(">").replace(" ", "").split(",")
6768
parseDataType(fieldTypeName = mapValue.first(), numericPref = numericPref)
6869
val key = fieldType
6970
parseDataType(fieldTypeName = mapValue.last(), numericPref = numericPref)
@@ -80,7 +81,10 @@ class KotlinDataTypeParser : DataTypeParser {
8081
if (fieldOptions.isNotEmpty()) {
8182
suffix.append(" [").append(fieldOptions.joinToString(", ")).append("]")
8283
}
83-
return prefix.toString() + fieldType + " " + field.name + " = " + id.toString() + suffix.toString() + SEMICOLON
84+
val lowerSnakeCaseFieldName = field.name.replace(Regex("([A-Z])")) {
85+
"_${it.value.lowercase()}"
86+
}
87+
return "$prefix$fieldType $lowerSnakeCaseFieldName = $id$suffix$SEMICOLON"
8488
}
8589

8690
override fun parseDataType(fieldTypeName: String, numericPref: NumericPreferencesVM): String {

src/main/kotlin/com/fnakhsan/toprotobufconverter/converter/processor/KotlinToProtobufProcessor.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.fnakhsan.toprotobufconverter.core.models.VersionVW
2424
import com.intellij.psi.PsiField
2525
import org.jetbrains.kotlin.idea.testIntegration.framework.KotlinPsiBasedTestFramework.Companion.asKtClassOrObject
2626
import org.jetbrains.kotlin.psi.KtFile
27+
import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly
2728

2829
class KotlinToProtobufProcessor(private val projectModel: ProjectModel, private val conversionModel: ConversionModel) :
2930
ProtobufTemplateHelper {
@@ -55,7 +56,10 @@ class KotlinToProtobufProcessor(private val projectModel: ProjectModel, private
5556
override fun getFileOption(): String = StringBuilder().apply {
5657
append(String.format(JAVA_PACKAGE, projectModel.packageName?.replace("/", ".")))
5758
append(String.format(JAVA_MULTIPLE_FILE, true))
58-
append(String.format(JAVA_OUTER_CLASSNAME, projectModel.virtualFile.nameWithoutExtension))
59+
append(
60+
String.format(JAVA_OUTER_CLASSNAME,
61+
conversionModel.rootFileName.split("_").joinToString("") { it.capitalizeAsciiOnly() })
62+
)
5963
}.toString()
6064

6165
override fun getMessage(name: String, body: String): String =

0 commit comments

Comments
 (0)