1+ import jetbrains.mps.lang.core.L_jetbrains_mps_lang_core
2+ import jetbrains.mps.lang.editor.*
3+ import org.modelix.metamodel.TypedLanguagesRegistry
4+ import org.modelix.metamodel.typed
5+ import org.modelix.metamodel.untyped
6+ import org.modelix.model.ModelFacade
7+ import org.modelix.model.api.INode
8+ import org.modelix.model.api.getRootNode
9+ import org.modelix.model.data.ModelData
10+ import java.io.File
11+ import kotlin.test.Test
12+ import kotlin.test.assertContains
13+ import kotlin.test.assertEquals
14+
15+ class GeneratedApiTest {
16+
17+ @Test
18+ fun `can handle enums` () {
19+ val branch = ModelFacade .toLocalBranch(ModelFacade .newLocalTree())
20+ TypedLanguagesRegistry .register(L_jetbrains_mps_lang_editor )
21+ TypedLanguagesRegistry .register(L_jetbrains_mps_lang_core )
22+ val data = ModelData .fromJson(File (" build/metamodel/exported-modules/jetbrains.mps.baseLanguage.blTypes.json" ).readText())
23+ branch.runWrite {
24+ data.load(branch)
25+ val node = findNodeWithStyleAttribute(branch.getRootNode())!! .typed(C_FontStyleStyleClassItem .getInstanceInterface())
26+ assertContains(_FontStyle_Enum .values(), node.style)
27+ val enumValue = _FontStyle_Enum .BOLD_ITALIC
28+ node.style = enumValue
29+ assertEquals(enumValue, node.untyped().typed(C_FontStyleStyleClassItem .getInstanceInterface()).style)
30+ }
31+ }
32+
33+ private fun findNodeWithStyleAttribute (node : INode ) : INode ? {
34+ var found = node.allChildren.find { it.getPropertyRoles().contains(" style" ) }
35+ if (found != null ) return found
36+
37+ for (child in node.allChildren) {
38+ found = findNodeWithStyleAttribute(child)
39+ if (found != null ) {
40+ return found
41+ }
42+ }
43+ return null
44+ }
45+
46+ }
0 commit comments