diff --git a/src/main/kotlin/creator/custom/derivation/SuggestClassNamePropertyDerivation.kt b/src/main/kotlin/creator/custom/derivation/SuggestClassNamePropertyDerivation.kt index c105d6c59..8dc7209a0 100644 --- a/src/main/kotlin/creator/custom/derivation/SuggestClassNamePropertyDerivation.kt +++ b/src/main/kotlin/creator/custom/derivation/SuggestClassNamePropertyDerivation.kt @@ -25,16 +25,21 @@ import com.demonwav.mcdev.creator.custom.TemplateValidationReporter import com.demonwav.mcdev.creator.custom.model.BuildSystemCoordinates import com.demonwav.mcdev.creator.custom.model.ClassFqn import com.demonwav.mcdev.creator.custom.types.CreatorProperty -import com.demonwav.mcdev.util.capitalize -import com.demonwav.mcdev.util.decapitalize +import com.intellij.openapi.util.text.StringUtil class SuggestClassNamePropertyDerivation : PreparedDerivation { override fun derive(parentValues: List): Any { val coords = parentValues[0] as BuildSystemCoordinates val name = parentValues[1] as String - val sanitizedName = name.split(NOT_JAVA_IDENTIFIER).joinToString("", transform = String::capitalize) - return ClassFqn("${coords.groupId}.${sanitizedName.decapitalize()}.$sanitizedName") + + val sanitizedName = name.split(NOT_JAVA_IDENTIFIER) + .joinToString("", transform = { StringUtil.capitalizeWords(it,true) }) + + val packageGroup = coords.groupId.lowercase() + val packageArtifact = sanitizedName.lowercase() + + return ClassFqn("$packageGroup.$packageArtifact.$sanitizedName") } companion object : PropertyDerivationFactory { diff --git a/src/main/kotlin/creator/step/MainClassStep.kt b/src/main/kotlin/creator/step/MainClassStep.kt index 59ed5061b..ccda8562b 100644 --- a/src/main/kotlin/creator/step/MainClassStep.kt +++ b/src/main/kotlin/creator/step/MainClassStep.kt @@ -41,13 +41,14 @@ class MainClassStep(parent: NewProjectWizardStep) : AbstractNewProjectWizardStep val buildSystemProps = findStep>() if (buildSystemProps.artifactId.contains('.')) { - // if the artifact id is invalid, don't confuse ourselves by copying its dots return className } - return buildSystemProps.groupId.toPackageName() + - "." + buildSystemProps.artifactId.toPackageName() + - "." + findStep().name.toJavaClassName() + val group = buildSystemProps.groupId.toPackageName() + val artifact = buildSystemProps.artifactId.toPackageName() + val mainClassName = findStep().name.toJavaClassName() + + return "$group.$artifact.$mainClassName" } val classNameProperty = propertyGraph.lazyProperty(::suggestMainClassName) diff --git a/src/test/kotlin/creator/ClassFqnCreatorPropertyTest.kt b/src/test/kotlin/creator/ClassFqnCreatorPropertyTest.kt index 60971578a..345ff89a3 100644 --- a/src/test/kotlin/creator/ClassFqnCreatorPropertyTest.kt +++ b/src/test/kotlin/creator/ClassFqnCreatorPropertyTest.kt @@ -96,6 +96,6 @@ class ClassFqnCreatorPropertyTest : CreatorTemplateProcessorTestBase() { buildCoordsProperty.graphProperty.set(BuildSystemCoordinates("com.example.project", "example-project", "1.0")) nameProperty.graphProperty.set("My Project") - assertEquals(ClassFqn("com.example.project.myProject.MyProject"), fqnProperty.get()) + assertEquals(ClassFqn("com.example.project.myproject.MyProject"), fqnProperty.get()) } }