Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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?>): 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 {
Expand Down
9 changes: 5 additions & 4 deletions src/main/kotlin/creator/step/MainClassStep.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ class MainClassStep(parent: NewProjectWizardStep) : AbstractNewProjectWizardStep
val buildSystemProps = findStep<BuildSystemPropertiesStep<*>>()

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<AbstractModNameStep>().name.toJavaClassName()
val group = buildSystemProps.groupId.toPackageName()
val artifact = buildSystemProps.artifactId.toPackageName()
val mainClassName = findStep<AbstractModNameStep>().name.toJavaClassName()

return "$group.$artifact.$mainClassName"
}

val classNameProperty = propertyGraph.lazyProperty(::suggestMainClassName)
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/creator/ClassFqnCreatorPropertyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
Loading