File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed
main/kotlin/org/modelix/metamodel/generator
test/kotlin/org/modelix/metamodel/generator Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -62,8 +62,8 @@ internal class ProcessedLanguageSet(dataList: List<LanguageData>) : IProcessedLa
62
62
private fun process () {
63
63
initIndexes()
64
64
resolveConceptReferences()
65
- fixRoleConflicts()
66
65
collectConceptMetaProperties()
66
+ fixRoleConflicts()
67
67
}
68
68
69
69
private fun collectConceptMetaProperties () {
@@ -128,8 +128,9 @@ internal class ProcessedLanguageSet(dataList: List<LanguageData>) : IProcessedLa
128
128
sameInHierarchyConflicts.forEach { it.generatedName + = " _" + it.concept.name }
129
129
130
130
// replace illegal names
131
+ val illegalNames = reservedPropertyNames + conceptMetaProperties
131
132
allConcepts.flatMap { it.getOwnRoles() }.forEach {
132
- if (reservedPropertyNames .contains(it.generatedName)) {
133
+ if (illegalNames .contains(it.generatedName)) {
133
134
it.generatedName + = getTypeSuffix(it)
134
135
}
135
136
}
Original file line number Diff line number Diff line change @@ -124,4 +124,35 @@ class KotlinGeneratorTest {
124
124
outputDir.deleteRecursively()
125
125
}
126
126
}
127
+
128
+ @OptIn(ExperimentalPathApi ::class )
129
+ @Test
130
+ fun `avoids name clashes for concept meta properties` () {
131
+ val input = """
132
+ name: org.modelix.entities
133
+ concepts:
134
+ - name: Entity
135
+ properties:
136
+ - name: alias
137
+ children: []
138
+ metaProperties:
139
+ alias: this should conflict with the property of the same name
140
+ enums: []
141
+ """ .trimIndent()
142
+
143
+ val language = Yaml .default.decodeFromString<LanguageData >(input)
144
+ val outputDir = createTempDirectory()
145
+ try {
146
+ MetaModelGenerator (outputDir).generate(LanguageSet (listOf (language)).process())
147
+
148
+ val fileContents = outputDir.resolve(" org/modelix/entities/Entity.kt" ).readText()
149
+ assertContains(
150
+ fileContents,
151
+ " alias_property" ,
152
+ message = " The alias property must have been disambiguated by appending the type to the name." ,
153
+ )
154
+ } finally {
155
+ outputDir.deleteRecursively()
156
+ }
157
+ }
127
158
}
You can’t perform that action at this time.
0 commit comments