From bca313c41bd40662237f1854dc7be8b107b4a3c0 Mon Sep 17 00:00:00 2001 From: Meinte Boersma Date: Tue, 2 Jul 2019 17:30:32 +0200 Subject: [PATCH] don't assume that all of lang.structure is indexed --- mps-inspector/pom.xml | 2 +- .../nl/dslconsultancy/mps/inspector/domain.kt | 8 +- .../mps/inspector/xml/modelXml.kt | 2 +- .../mps/inspector/xml/structureXml.kt | 77 +++++++++++-------- .../mps/inspector/xml/jsonModelTests.kt | 20 ++--- .../src/test/resources/tryOnOwn.json | 12 +++ mps-open-source/.mps/modules.xml | 6 +- 7 files changed, 77 insertions(+), 50 deletions(-) diff --git a/mps-inspector/pom.xml b/mps-inspector/pom.xml index 9a838d7..a5a139e 100644 --- a/mps-inspector/pom.xml +++ b/mps-inspector/pom.xml @@ -5,7 +5,7 @@ nl.dslconsultancy.mps mps-inspector - 0.2.0 + 0.2.1 jar MPS Inspector diff --git a/mps-inspector/src/main/kotlin/nl/dslconsultancy/mps/inspector/domain.kt b/mps-inspector/src/main/kotlin/nl/dslconsultancy/mps/inspector/domain.kt index c7f443f..a227ffc 100644 --- a/mps-inspector/src/main/kotlin/nl/dslconsultancy/mps/inspector/domain.kt +++ b/mps-inspector/src/main/kotlin/nl/dslconsultancy/mps/inspector/domain.kt @@ -37,7 +37,13 @@ fun Language.structureModelPath(): Path = path.parent.resolve("models").resolve( fun Language.structure(): Structure { if (cachedStructure == null) { - cachedStructure = modelXmlFromDisk(structureModelPath()).asStructure() + try { + cachedStructure = modelXmlFromDisk(structureModelPath()).asStructure() + } catch (e: Exception) { + System.err.println("could not read structure model XML file for language '$name'; due to:") + System.err.println(e.message) + e.printStackTrace(System.err) + } } return cachedStructure!! } diff --git a/mps-inspector/src/main/kotlin/nl/dslconsultancy/mps/inspector/xml/modelXml.kt b/mps-inspector/src/main/kotlin/nl/dslconsultancy/mps/inspector/xml/modelXml.kt index f68eaa6..a6dd315 100644 --- a/mps-inspector/src/main/kotlin/nl/dslconsultancy/mps/inspector/xml/modelXml.kt +++ b/mps-inspector/src/main/kotlin/nl/dslconsultancy/mps/inspector/xml/modelXml.kt @@ -160,7 +160,7 @@ fun modelXmlWithoutNodesFromDisk(path: Path): ModelXmlWithoutNodes = xmlFromDisk fun ModelXml.metaConcepts(): List = registry?.languages?.flatMap { it.metaConcepts } ?: emptyList() -fun Iterable.named(name: String): MetaConceptXml = single { it.name.lastSection() == name } +fun Iterable.named(name: String): MetaConceptXml? = firstOrNull { it.name.lastSection() == name } fun Iterable.byIndex(index: String): MetaConceptXml = single { it.index == index } diff --git a/mps-inspector/src/main/kotlin/nl/dslconsultancy/mps/inspector/xml/structureXml.kt b/mps-inspector/src/main/kotlin/nl/dslconsultancy/mps/inspector/xml/structureXml.kt index 942627d..0789bf7 100644 --- a/mps-inspector/src/main/kotlin/nl/dslconsultancy/mps/inspector/xml/structureXml.kt +++ b/mps-inspector/src/main/kotlin/nl/dslconsultancy/mps/inspector/xml/structureXml.kt @@ -7,7 +7,7 @@ fun ModelXml.asStructure(): Structure { val metaConcepts = metaConcepts() val memois = hashMapOf() val modelXml = this - val supported = listOf("ConceptDeclaration", "InterfaceConceptDeclaration").map { metaConcepts.named(it).index } + val supported = listOf("ConceptDeclaration", "InterfaceConceptDeclaration").mapNotNull { metaConcepts.named(it) }.map { it.index } return Structure( elements = modelXml.nodes.filter { supported.contains(it.concept) }.map { it.fromXml(metaConcepts, memois) as StructuralElement } ) @@ -23,58 +23,67 @@ private fun NodeXml.fromXml(metaConcepts: List, memois: Map memois.of(nodeXml to Concept( - name = nodeXml.thisProperty(metaConcepts.named("INamedConcept").properties.named("name"))!!, - isInterface = false, - rootable = nodeXml.thisProperty(metaConcepts.named("ConceptDeclaration").properties.named("rootable")).orEmpty() == "true", - alias = nodeXml.thisProperty(metaConcepts.named("AbstractConceptDeclaration").properties.named("conceptAlias")), - shortDescription = nodeXml.thisProperty(metaConcepts.named("AbstractConceptDeclaration").properties.named("conceptShortDescription")), - deprecated = isDeprecated() - )).apply { - extends = nodeXml.thisReference(metaConcepts.named("ConceptDeclaration").references.named("extends"))?.resolve - implements = nodeXml.theseChildren(metaConcepts.named("ConceptDeclaration").children.named("implements")).mapNotNull { - it.thisReference( - metaConcepts.named("InterfaceConceptReference").references.named("intfc") - )?.resolve + "ConceptDeclaration" -> { + val conceptDeclaration = metaConcepts.named("ConceptDeclaration")!! + memois.of(nodeXml to Concept( + name = nodeXml.thisProperty(iNamedConcept.properties.named("name"))!!, + isInterface = false, + rootable = nodeXml.thisProperty(conceptDeclaration.properties.named("rootable")).orEmpty() == "true", + alias = nodeXml.thisProperty(abstractConceptDeclaration.properties.named("conceptAlias")), + shortDescription = nodeXml.thisProperty(abstractConceptDeclaration.properties.named("conceptShortDescription")), + deprecated = isDeprecated() + )).apply { + extends = nodeXml.thisReference(conceptDeclaration.references.named("extends"))?.resolve + implements = nodeXml.theseChildren(conceptDeclaration.children.named("implements")).mapNotNull { + it.thisReference( + metaConcepts.named("InterfaceConceptReference")?.references?.named("intfc") + )?.resolve + } + features = listOf( + nodeXml.theseChildren(abstractConceptDeclaration.children.named("propertyDeclaration")).map { it.fromXml(metaConcepts, memois) as Feature }, + nodeXml.theseChildren(abstractConceptDeclaration.children.named("linkDeclaration")).map { it.fromXml(metaConcepts, memois) as Feature } + ).flatten() } - features = listOf( - nodeXml.theseChildren(metaConcepts.named("AbstractConceptDeclaration").children.named("propertyDeclaration")).map { it.fromXml(metaConcepts, memois) as Feature }, - nodeXml.theseChildren(metaConcepts.named("AbstractConceptDeclaration").children.named("linkDeclaration")).map { it.fromXml(metaConcepts, memois) as Feature } - ).flatten() } "InterfaceConceptDeclaration" -> memois.of(nodeXml to Concept( - name = nodeXml.thisProperty(metaConcepts.named("INamedConcept").properties.named("name"))!!, + name = nodeXml.thisProperty(iNamedConcept.properties.named("name"))!!, isInterface = true, rootable = false, - alias = nodeXml.thisProperty(metaConcepts.named("AbstractConceptDeclaration").properties.named("conceptAlias")), - shortDescription = nodeXml.thisProperty(metaConcepts.named("AbstractConceptDeclaration").properties.named("conceptShortDescription")), + alias = nodeXml.thisProperty(abstractConceptDeclaration.properties.named("conceptAlias")), + shortDescription = nodeXml.thisProperty(abstractConceptDeclaration.properties.named("conceptShortDescription")), deprecated = isDeprecated() )).apply { - implements = nodeXml.theseChildren(metaConcepts.named("InterfaceConceptDeclaration").children.named("extends")).mapNotNull { + implements = nodeXml.theseChildren(metaConcepts.named("InterfaceConceptDeclaration")?.children?.named("extends")).mapNotNull { it.thisReference( - metaConcepts.named("InterfaceConceptReference").references.named("intfc") + metaConcepts.named("InterfaceConceptReference")?.references?.named("intfc") )?.resolve } features = listOf( - nodeXml.theseChildren(metaConcepts.named("AbstractConceptDeclaration").children.named("propertyDeclaration")).map { it.fromXml(metaConcepts, memois) as Feature }, - nodeXml.theseChildren(metaConcepts.named("AbstractConceptDeclaration").children.named("linkDeclaration")).map { it.fromXml(metaConcepts, memois) as Feature } + nodeXml.theseChildren(abstractConceptDeclaration.children.named("propertyDeclaration")).map { it.fromXml(metaConcepts, memois) as Feature }, + nodeXml.theseChildren(abstractConceptDeclaration.children.named("linkDeclaration")).map { it.fromXml(metaConcepts, memois) as Feature } ).flatten() } - "LinkDeclaration" -> memois.of(nodeXml to Link( - name = thisProperty(metaConcepts.named("LinkDeclaration").properties.named("role"))!!, - deprecated = isDeprecated(), - reference = thisProperty(metaConcepts.named("LinkDeclaration").properties.named("metaClass"))!! == "reference", - cardinality = thisProperty(metaConcepts.named("LinkDeclaration").properties.named("sourceCardinality")) ?: "0..1", - targetType = thisReference(metaConcepts.named("LinkDeclaration").references.named("target"))!!.resolve!! - )) + "LinkDeclaration" -> { + val linkDeclaration = metaConcepts.named("LinkDeclaration")!! + memois.of(nodeXml to Link( + name = thisProperty(linkDeclaration.properties.named("role"))!!, + deprecated = isDeprecated(), + reference = thisProperty(linkDeclaration.properties.named("metaClass"))!! == "reference", + cardinality = thisProperty(linkDeclaration.properties.named("sourceCardinality")) ?: "0..1", + targetType = thisReference(linkDeclaration.references.named("target"))!!.resolve!! + )) + } "PropertyDeclaration" -> memois.of(nodeXml to Property( - name = nodeXml.thisProperty(metaConcepts.named("INamedConcept").properties.named("name"))!!, + name = nodeXml.thisProperty(iNamedConcept.properties.named("name"))!!, deprecated = isDeprecated() )) else -> throw Error("concept without Kotlin class: ${metaConcept.name}") diff --git a/mps-inspector/src/test/kotlin/nl/dslconsultancy/mps/inspector/xml/jsonModelTests.kt b/mps-inspector/src/test/kotlin/nl/dslconsultancy/mps/inspector/xml/jsonModelTests.kt index 653d8e1..90d492b 100644 --- a/mps-inspector/src/test/kotlin/nl/dslconsultancy/mps/inspector/xml/jsonModelTests.kt +++ b/mps-inspector/src/test/kotlin/nl/dslconsultancy/mps/inspector/xml/jsonModelTests.kt @@ -6,7 +6,7 @@ import java.nio.file.Paths import kotlin.test.Test import kotlin.test.assertEquals -fun NodeXml.fromXml(concepts: List, memois: Map): Any { +private fun NodeXml.fromXml(concepts: List, memois: Map): Any { val nodeXml = this val precomputed = memois[nodeXml.id] if (precomputed != null) { @@ -15,30 +15,30 @@ fun NodeXml.fromXml(concepts: List, memois: Map): A val concept = concepts.byIndex(nodeXml.concept) return when (concept.name.lastSection()) { "JsonArray" -> memois.of(nodeXml to JsonArray()).apply { - items = nodeXml.theseChildren(concepts.named("JsonArray").children.named("items")).map { it.fromXml(concepts, memois) as IJsonValue } + items = nodeXml.theseChildren(concepts.named("JsonArray")!!.children.named("items")).map { it.fromXml(concepts, memois) as IJsonValue } } "JsonBoolean" -> memois.of(nodeXml to JsonBoolean( - value = nodeXml.thisProperty(concepts.named("JsonBoolean").properties.named("value")) == "true" + value = nodeXml.thisProperty(concepts.named("JsonBoolean")!!.properties.named("value")) == "true" )) "JsonFile" -> memois.of(nodeXml to JsonFile( - name = nodeXml.thisProperty(concepts.named("INamedConcept").properties.named("name"))!! + name = nodeXml.thisProperty(concepts.named("INamedConcept")!!.properties.named("name"))!! )).apply { - contents = nodeXml.theseChildren(concepts.named("JsonFile").children.named("contents")).firstOrNull()?.fromXml(concepts, memois) as IJsonValue + contents = nodeXml.theseChildren(concepts.named("JsonFile")!!.children.named("contents")).firstOrNull()?.fromXml(concepts, memois) as IJsonValue } "JsonNull" -> memois.of(nodeXml to IJsonValue.JsonNull) "JsonNumber" -> memois.of(nodeXml to JsonNumber( - value = nodeXml.thisProperty(concepts.named("JsonNumber").properties.named("value"))!! + value = nodeXml.thisProperty(concepts.named("JsonNumber")!!.properties.named("value"))!! )) "JsonObject" -> memois.of(nodeXml to JsonObject()).apply { - pairs = nodeXml.theseChildren(concepts.named("JsonObject").children.named("pairs")).map { it.fromXml(concepts, memois) as JsonPair } + pairs = nodeXml.theseChildren(concepts.named("JsonObject")!!.children.named("pairs")).map { it.fromXml(concepts, memois) as JsonPair } } "JsonPair" -> memois.of(nodeXml to JsonPair( - name = nodeXml.thisProperty(concepts.named("INamedConcept").properties.named("name"))!! + name = nodeXml.thisProperty(concepts.named("INamedConcept")!!.properties.named("name"))!! )).apply { - value = nodeXml.theseChildren(concepts.named("JsonPair").children.named("value")).firstOrNull()?.fromXml(concepts, memois) as IJsonValue + value = nodeXml.theseChildren(concepts.named("JsonPair")!!.children.named("value")).firstOrNull()?.fromXml(concepts, memois) as IJsonValue } "JsonString" -> memois.of(nodeXml to JsonString( - value = nodeXml.thisProperty(concepts.named("JsonString").properties.named("value"))!! + value = nodeXml.thisProperty(concepts.named("JsonString")!!.properties.named("value"))!! )) else -> throw Error("concept without Kotlin class: ${concept.name}") } diff --git a/mps-inspector/src/test/resources/tryOnOwn.json b/mps-inspector/src/test/resources/tryOnOwn.json index 386bb84..f42ebf3 100644 --- a/mps-inspector/src/test/resources/tryOnOwn.json +++ b/mps-inspector/src/test/resources/tryOnOwn.json @@ -14,6 +14,18 @@ { "languageName": "JsonSchema", "generationPath": "src/generated" + }, + { + "languageName": "WSDL", + "generationPath": "src/generated" + }, + { + "languageName": "XSD", + "generationPath": "src/generated" + }, + { + "languageName": "XmlWithExtension", + "generationPath": "src/generated" } ] } diff --git a/mps-open-source/.mps/modules.xml b/mps-open-source/.mps/modules.xml index c9d0e89..1c21dad 100644 --- a/mps-open-source/.mps/modules.xml +++ b/mps-open-source/.mps/modules.xml @@ -1,14 +1,14 @@ - + - - + +