Skip to content

Commit 071e31b

Browse files
committed
handle duplicate concept member names
If there is a property and a child link with the same name then "_property"/"_child" is appended. This usually happens when a property is replaced by a node, but the property is keep for compatibility reasons. The property is then usually deprecated.
1 parent a3d1f3e commit 071e31b

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

metamodel-generator/src/main/kotlin/org/modelix/metamodel/generator/ConceptInLanguage.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class LanguageSet(languages: List<LanguageData>) {
6363
fun directFeatures(): List<FeatureInConcept> = (concept.properties + concept.children + concept.references)
6464
.map { FeatureInConcept(this, it) }
6565

66-
fun allFeatures(): List<FeatureInConcept> = (allSuperConcepts() + this).flatMap { it.directFeatures() }.distinct()
66+
fun allFeatures(): List<FeatureInConcept> = allSuperConceptsAndSelf().flatMap { it.directFeatures() }.distinct()
6767
fun directFeaturesAndConflicts(): List<FeatureInConcept> =
6868
(directFeatures() + resolveMultipleInheritanceConflicts().flatMap { it.key.allFeatures() })
6969
.distinct().groupBy { it.validName }.values.map { it.first() }
@@ -111,8 +111,19 @@ private val reservedPropertyNames: Set<String> = setOf(
111111
) + IConcept::class.members.map { it.name }
112112

113113
data class FeatureInConcept(val concept: LanguageSet.ConceptInLanguage, val data: IConceptFeatureData) {
114-
val validName: String = if (reservedPropertyNames.contains(data.name)) data.name + "_" else data.name
114+
val validName: String by lazy {
115+
if (reservedPropertyNames.contains(originalName) || hasNameConflict()) {
116+
originalName + "_" + when (data) {
117+
is PropertyData -> "property"
118+
is ReferenceLinkData -> "reference"
119+
is ChildLinkData -> if (data.multiple) "children" else "child"
120+
}
121+
} else {
122+
originalName
123+
}
124+
}
115125
val originalName: String = data.name
126+
private fun hasNameConflict() = concept.allFeatures().any { it.originalName == originalName && it != this }
116127
}
117128

118129
fun String.parseConceptRef(contextLanguage: LanguageData): ConceptRef {

metamodel-generator/src/main/kotlin/org/modelix/metamodel/generator/MetaModelDefinition.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ data class ConceptData(
4141
val extends: List<String> = emptyList(),
4242
)
4343

44-
interface IConceptFeatureData {
44+
sealed interface IConceptFeatureData {
4545
val uid: String?
4646
val name: String
4747
}

0 commit comments

Comments
 (0)