User: rednesto Date: 09 Aug 24 09:46 Revision: 640f2e26027a7b059fcd0e0f1a96e2e57c295be2 Summary: Differentiate between unknown derivation method and derivation creation errors TeamCity URL: https://ci.mcdev.io/viewModification.html?tab=vcsModificationFiles&modId=9574&personal=false Index: src/main/kotlin/creator/custom/derivation/PropertyDerivation.kt =================================================================== --- src/main/kotlin/creator/custom/derivation/PropertyDerivation.kt (revision b7fa3ecaac3c5a3372473ae8d35d00a4628d8713) +++ src/main/kotlin/creator/custom/derivation/PropertyDerivation.kt (revision 640f2e26027a7b059fcd0e0f1a96e2e57c295be2) @@ -28,6 +28,11 @@ fun derive(parentValues: List): Any? } +object UnknownDerivation : PreparedDerivation { + + override fun derive(parentValues: List): Any? = null +} + interface PropertyDerivationFactory { fun create( Index: src/main/kotlin/creator/custom/types/ClassFqnCreatorProperty.kt =================================================================== --- src/main/kotlin/creator/custom/types/ClassFqnCreatorProperty.kt (revision b7fa3ecaac3c5a3372473ae8d35d00a4628d8713) +++ src/main/kotlin/creator/custom/types/ClassFqnCreatorProperty.kt (revision 640f2e26027a7b059fcd0e0f1a96e2e57c295be2) @@ -27,6 +27,7 @@ import com.demonwav.mcdev.creator.custom.TemplateValidationReporter import com.demonwav.mcdev.creator.custom.derivation.PreparedDerivation import com.demonwav.mcdev.creator.custom.derivation.SuggestClassNamePropertyDerivation +import com.demonwav.mcdev.creator.custom.derivation.UnknownDerivation import com.demonwav.mcdev.creator.custom.model.ClassFqn import com.intellij.ui.dsl.builder.COLUMNS_LARGE import com.intellij.ui.dsl.builder.Panel @@ -63,7 +64,7 @@ SuggestClassNamePropertyDerivation.create(reporter, parents, derives) } - else -> null + else -> UnknownDerivation } class Factory : CreatorPropertyFactory { Index: src/main/kotlin/creator/custom/types/CreatorProperty.kt =================================================================== --- src/main/kotlin/creator/custom/types/CreatorProperty.kt (revision b7fa3ecaac3c5a3372473ae8d35d00a4628d8713) +++ src/main/kotlin/creator/custom/types/CreatorProperty.kt (revision 640f2e26027a7b059fcd0e0f1a96e2e57c295be2) @@ -27,6 +27,7 @@ import com.demonwav.mcdev.creator.custom.TemplateValidationReporter import com.demonwav.mcdev.creator.custom.derivation.PreparedDerivation import com.demonwav.mcdev.creator.custom.derivation.SelectPropertyDerivation +import com.demonwav.mcdev.creator.custom.derivation.UnknownDerivation import com.intellij.ide.util.projectWizard.WizardContext import com.intellij.openapi.diagnostic.thisLogger import com.intellij.openapi.observable.properties.GraphProperty @@ -145,20 +146,20 @@ } derivation = setupDerivation(reporter, descriptor.derives) - if (derivation == null) { + if (derivation == UnknownDerivation) { reporter.fatal("Unknown method derivation: ${descriptor.derives}") - } - + } else if (derivation != null) { - @Suppress("UNCHECKED_CAST") - graphProperty.set(derive(collectDerivationParentValues(reporter), descriptor.derives) as T) - for (parent in parents) { - val parentProperty = properties[parent]!! - graphProperty.dependsOn(parentProperty.graphProperty, descriptor.derives.whenModified != false) { - @Suppress("UNCHECKED_CAST") - derive(collectDerivationParentValues(), descriptor.derives) as T - } - } - } + @Suppress("UNCHECKED_CAST") + graphProperty.set(derive(collectDerivationParentValues(reporter), descriptor.derives) as T) + for (parent in parents) { + val parentProperty = properties[parent]!! + graphProperty.dependsOn(parentProperty.graphProperty, descriptor.derives.whenModified != false) { + @Suppress("UNCHECKED_CAST") + derive(collectDerivationParentValues(), descriptor.derives) as T + } + } + } + } if (descriptor.inheritFrom != null) { val parentProperty = properties[descriptor.inheritFrom] @@ -173,10 +174,13 @@ } } + /** + * @return [UnknownDerivation] if the derivation method is unknown, `null` if the derivation is invalid. + */ protected open fun setupDerivation( reporter: TemplateValidationReporter, derives: PropertyDerivation - ): PreparedDerivation? = null + ): PreparedDerivation? = UnknownDerivation protected fun makeStorageKey(discriminator: String? = null): String { val base = "${javaClass.name}.property.${descriptor.name}.${descriptor.type}" Index: src/main/kotlin/creator/custom/types/IntegerCreatorProperty.kt =================================================================== --- src/main/kotlin/creator/custom/types/IntegerCreatorProperty.kt (revision b7fa3ecaac3c5a3372473ae8d35d00a4628d8713) +++ src/main/kotlin/creator/custom/types/IntegerCreatorProperty.kt (revision 640f2e26027a7b059fcd0e0f1a96e2e57c295be2) @@ -27,6 +27,7 @@ import com.demonwav.mcdev.creator.custom.derivation.PreparedDerivation import com.demonwav.mcdev.creator.custom.derivation.RecommendJavaVersionForMcVersionPropertyDerivation import com.demonwav.mcdev.creator.custom.derivation.SelectPropertyDerivation +import com.demonwav.mcdev.creator.custom.derivation.UnknownDerivation import com.intellij.ui.dsl.builder.COLUMNS_LARGE import com.intellij.ui.dsl.builder.Panel import com.intellij.ui.dsl.builder.bindIntText @@ -67,7 +68,7 @@ SelectPropertyDerivation.create(reporter, emptyList(), derives) } - else -> null + else -> UnknownDerivation } class Factory : CreatorPropertyFactory { Index: src/main/kotlin/creator/custom/types/SemanticVersionCreatorProperty.kt =================================================================== --- src/main/kotlin/creator/custom/types/SemanticVersionCreatorProperty.kt (revision b7fa3ecaac3c5a3372473ae8d35d00a4628d8713) +++ src/main/kotlin/creator/custom/types/SemanticVersionCreatorProperty.kt (revision 640f2e26027a7b059fcd0e0f1a96e2e57c295be2) @@ -27,6 +27,7 @@ import com.demonwav.mcdev.creator.custom.derivation.ExtractVersionMajorMinorPropertyDerivation import com.demonwav.mcdev.creator.custom.derivation.PreparedDerivation import com.demonwav.mcdev.creator.custom.derivation.SelectPropertyDerivation +import com.demonwav.mcdev.creator.custom.derivation.UnknownDerivation import com.demonwav.mcdev.util.SemanticVersion import com.intellij.ui.dsl.builder.COLUMNS_SHORT import com.intellij.ui.dsl.builder.Panel @@ -67,7 +68,7 @@ SelectPropertyDerivation.create(reporter, emptyList(), derives) } - else -> null + else -> UnknownDerivation } override fun convertSelectDerivationResult(original: Any?): Any? { Index: src/main/kotlin/creator/custom/types/StringCreatorProperty.kt =================================================================== --- src/main/kotlin/creator/custom/types/StringCreatorProperty.kt (revision b7fa3ecaac3c5a3372473ae8d35d00a4628d8713) +++ src/main/kotlin/creator/custom/types/StringCreatorProperty.kt (revision 640f2e26027a7b059fcd0e0f1a96e2e57c295be2) @@ -28,6 +28,7 @@ import com.demonwav.mcdev.creator.custom.derivation.PreparedDerivation import com.demonwav.mcdev.creator.custom.derivation.ReplacePropertyDerivation import com.demonwav.mcdev.creator.custom.derivation.SelectPropertyDerivation +import com.demonwav.mcdev.creator.custom.derivation.UnknownDerivation import com.intellij.openapi.observable.properties.GraphProperty import com.intellij.ui.dsl.builder.COLUMNS_LARGE import com.intellij.ui.dsl.builder.Panel @@ -77,7 +78,7 @@ SelectPropertyDerivation.create(reporter, emptyList(), derives) } - else -> null + else -> UnknownDerivation } override fun buildSimpleUi(panel: Panel) {