diff --git a/core/src/main/kotlin/com/strumenta/kolasu/mapping/Support.kt b/core/src/main/kotlin/com/strumenta/kolasu/mapping/Support.kt index 271950fd..51097d13 100644 --- a/core/src/main/kotlin/com/strumenta/kolasu/mapping/Support.kt +++ b/core/src/main/kotlin/com/strumenta/kolasu/mapping/Support.kt @@ -1,5 +1,6 @@ package com.strumenta.kolasu.mapping +import com.strumenta.kolasu.model.Node import com.strumenta.kolasu.parsing.getOriginalText import com.strumenta.kolasu.transformation.ASTTransformer import org.antlr.v4.runtime.ParserRuleContext @@ -12,8 +13,8 @@ import org.antlr.v4.runtime.ParserRuleContext * JPostIncrementExpr(translateCasted(expression().first())) * ``` */ -fun ASTTransformer.translateCasted(original: Any): T { - val result = transform(original) +inline fun ASTTransformer.translateCasted(original: Any): T { + val result = transform(original, expectedType = T::class) if (result is Nothing) { throw IllegalStateException("Transformation produced Nothing") } @@ -29,8 +30,9 @@ fun ASTTransformer.translateCasted(original: Any): T { * JExtendsType(translateCasted(pt.typeType()), translateList(pt.annotation())) * ``` */ -fun ASTTransformer.translateList(original: Collection?): MutableList { - return original?.map { transformIntoNodes(it) as List }?.flatten()?.toMutableList() ?: mutableListOf() +inline fun ASTTransformer.translateList(original: Collection?): MutableList { + return original?.map { transformIntoNodes(it, expectedType = T::class) as List }?.flatten()?.toMutableList() + ?: mutableListOf() } /** @@ -46,8 +48,15 @@ fun ASTTransformer.translateList(original: Collection?): MutableLis * ) * ``` */ -fun ASTTransformer.translateOptional(original: Any?): T? { - return original?.let { transform(it) as T } +inline fun ASTTransformer.translateOptional(original: Any?): T? { + return original?.let { + val transformed = transform(it, expectedType = T::class) + if (transformed == null) { + return null + } else { + transformed as T + } + } } /** diff --git a/core/src/main/kotlin/com/strumenta/kolasu/transformation/IdentityTransformation.kt b/core/src/main/kotlin/com/strumenta/kolasu/transformation/IdentityTransformation.kt new file mode 100644 index 00000000..ca5f4f70 --- /dev/null +++ b/core/src/main/kotlin/com/strumenta/kolasu/transformation/IdentityTransformation.kt @@ -0,0 +1,62 @@ +package com.strumenta.kolasu.transformation + +import com.strumenta.kolasu.mapping.translateList +import com.strumenta.kolasu.model.Node +import java.lang.reflect.ParameterizedType +import kotlin.reflect.KClass +import kotlin.reflect.KParameter +import kotlin.reflect.full.isSubclassOf +import kotlin.reflect.full.memberProperties +import kotlin.reflect.full.primaryConstructor +import kotlin.reflect.jvm.javaType + +val IDENTTITY_TRANSFORMATION: ( + source: Any?, + parent: Node?, + expectedType: KClass, + astTransformer: ASTTransformer +) -> List = { + source: Any?, parent: Node?, expectedType: KClass, astTransformer: ASTTransformer -> + when (source) { + null -> { + emptyList() + } + is Node -> { + val kClass = source.javaClass.kotlin + val primaryConstructor = kClass.primaryConstructor + ?: throw IllegalStateException( + "No primary constructor found for $kClass: cannot apply " + + "identity transformation" + ) + val params = mutableMapOf() + primaryConstructor.parameters.forEach { parameter -> + val mt = parameter.type.javaType + val correspondingProperty = source.javaClass.kotlin.memberProperties.find { + it.name == parameter.name + } ?: throw IllegalStateException( + "Cannot find property named as parameter $parameter" + ) + val originalValue = correspondingProperty.get(source) + // mt is ParameterizedType && mt.rawType == List::class.java -> mutableListOf() + when { + (parameter.type.classifier as KClass<*>).isSubclassOf(Node::class) -> { + params[parameter] = astTransformer.transform(originalValue) + } + mt is ParameterizedType && mt.rawType == List::class.java && + (mt.actualTypeArguments.first() as? Class<*>)?.kotlin?.isSubclassOf(Node::class) == true -> { + params[parameter] = astTransformer.translateList(originalValue as List) + } + else -> params[parameter] = originalValue + } + } + + val newInstance = primaryConstructor.callBy(params) as Node + newInstance.parent = parent + newInstance.origin = source + listOf(newInstance) + } + else -> { + throw IllegalArgumentException("An Identity Transformation expect to receive a Node") + } + } +} diff --git a/core/src/main/kotlin/com/strumenta/kolasu/transformation/Transformation.kt b/core/src/main/kotlin/com/strumenta/kolasu/transformation/Transformation.kt index b1caf765..6495af4e 100644 --- a/core/src/main/kotlin/com/strumenta/kolasu/transformation/Transformation.kt +++ b/core/src/main/kotlin/com/strumenta/kolasu/transformation/Transformation.kt @@ -258,7 +258,13 @@ open class ASTTransformer( * with the origin FailingASTTransformation. If the flag is not set, then the transformation will just * fail. */ - val faultTollerant: Boolean = !throwOnUnmappedNode + val faultTollerant: Boolean = !throwOnUnmappedNode, + val defaultTransformation: ( + ( + source: Any?, parent: Node?, expectedType: KClass, + astTransformer: ASTTransformer + ) -> List + )? = null ) { /** * Factories that map from source tree node to target tree node. @@ -272,8 +278,8 @@ open class ASTTransformer( * This ensures that the generated value is a single Node or null. */ @JvmOverloads - fun transform(source: Any?, parent: Node? = null): Node? { - val result = transformIntoNodes(source, parent) + fun transform(source: Any?, parent: Node? = null, expectedType: KClass = Node::class): Node? { + val result = transformIntoNodes(source, parent, expectedType) return when (result.size) { 0 -> null 1 -> { @@ -314,7 +320,9 @@ open class ASTTransformer( node.parent = parent } } else { - if (allowGenericNode) { + if (defaultTransformation != null) { + nodes = defaultTransformation.invoke(source, parent, expectedType, this) + } else if (allowGenericNode) { val origin = asOrigin(source) nodes = listOf(GenericNode(parent).withOrigin(origin)) issues.add( diff --git a/core/src/test/kotlin/com/strumenta/kolasu/transformation/ASTTransformerTest.kt b/core/src/test/kotlin/com/strumenta/kolasu/transformation/ASTTransformerTest.kt index 46d3c50c..8d77b7cd 100644 --- a/core/src/test/kotlin/com/strumenta/kolasu/transformation/ASTTransformerTest.kt +++ b/core/src/test/kotlin/com/strumenta/kolasu/transformation/ASTTransformerTest.kt @@ -1,6 +1,9 @@ package com.strumenta.kolasu.transformation +import com.strumenta.kolasu.mapping.translateCasted +import com.strumenta.kolasu.mapping.translateList import com.strumenta.kolasu.model.Node +import com.strumenta.kolasu.model.children import com.strumenta.kolasu.model.hasValidParents import com.strumenta.kolasu.model.withOrigin import com.strumenta.kolasu.testing.assertASTsAreEqual @@ -349,11 +352,195 @@ class ASTTransformerTest { ) assertIs(bazRoot1.stmts[0].origin) } -} + @Test + fun testIdentityTransformation() { + val transformer = ASTTransformer(defaultTransformation = IDENTTITY_TRANSFORMATION) + + val original = BarRoot( + stmts = mutableListOf( + BarStmt("a"), + BarStmt("b") + ) + ) + val transformed = transformer.transform(original) as Node + assertASTsAreEqual( + original, + transformed + ) + } + + @Test + fun testPartialIdentityTransformation() { + val transformer1 = ASTTransformer(defaultTransformation = IDENTTITY_TRANSFORMATION) + transformer1.registerNodeFactory(BarRoot::class) { original: BarRoot, astTransformer: ASTTransformer, _ -> + FooRoot( + desc = "#children = ${original.children.size}", + stmts = astTransformer.translateList(original.stmts) + ) + } + val original = BarRoot( + stmts = mutableListOf( + BarStmt("a"), + BarStmt("b") + ) + ) + val transformed = transformer1.transform(original) as FooRoot + assertASTsAreEqual( + FooRoot( + "#children = 2", + mutableListOf( + BarStmt("a"), + BarStmt("b") + ) + ), + transformed + ) + } + + @Test + fun testIdentityTransformationOfIntermediateNodes() { + val transformer1 = ASTTransformer(defaultTransformation = IDENTTITY_TRANSFORMATION) + transformer1.registerNodeFactory(BarRoot::class) { original: BarRoot, astTransformer: ASTTransformer, _ -> + FooRoot( + desc = "#children = ${original.children.size}", + stmts = astTransformer.translateList(original.stmts) + ) + } + val original = AA( + a = "my_a", + child = AB( + b = "my_b", + child = AC( + c = "my_c", + children = mutableListOf( + AD("my_d1"), + AD("my_d2"), + AD("my_d3") + ) + ) + ) + ) + // All identity + assertASTsAreEqual( + AA( + a = "my_a", + child = AB( + b = "my_b", + child = AC( + c = "my_c", + children = mutableListOf( + AD("my_d1"), + AD("my_d2"), + AD("my_d3") + ) + ) + ) + ), + transformer1.transform(original) as AA + ) + // All identity besides AA + transformer1.registerNodeFactory(AA::class) { original, t, _ -> + BA("your_" + original.a.removePrefix("my_"), t.translateCasted(original.child)) + } + assertASTsAreEqual( + BA( + a = "your_a", + child = AB( + b = "my_b", + child = AC( + c = "my_c", + children = mutableListOf( + AD("my_d1"), + AD("my_d2"), + AD("my_d3") + ) + ) + ) + ), + transformer1.transform(original) as AA + ) + // All identity besides AA and AB + transformer1.registerNodeFactory(AB::class) { original, t, _ -> + BB("your_" + original.b.removePrefix("my_"), t.translateCasted(original.child)) + } + assertASTsAreEqual( + BA( + a = "your_a", + child = BB( + b = "your_b", + child = AC( + c = "my_c", + children = mutableListOf( + AD("my_d1"), + AD("my_d2"), + AD("my_d3") + ) + ) + ) + ), + transformer1.transform(original) as AA + ) + // All identity besides AA and AB and AD + transformer1.registerNodeFactory(AD::class) { original, t, _ -> + BD("your_" + original.d.removePrefix("my_")) + } + assertASTsAreEqual( + BA( + a = "your_a", + child = BB( + b = "your_b", + child = AC( + c = "my_c", + children = mutableListOf( + BD("your_d1"), + BD("your_d2"), + BD("your_d3") + ) + ) + ) + ), + transformer1.transform(original) as AA + ) + } + + @Test + fun testIdentityTransformationOfIntermediateNodesWithOrigin() { + val transformer1 = ASTTransformer(defaultTransformation = IDENTTITY_TRANSFORMATION) + transformer1.registerNodeFactory(AA::class) { original, t, _ -> + BA("your_" + original.a.removePrefix("my_"), t.translateCasted(original.child)) + } + val original = AA( + a = "my_a", + child = AB( + b = "my_b", + child = AC( + c = "my_c", + children = mutableListOf( + AD("my_d1") + ) + ) + ) + ) + val transformedAST = transformer1.transform(original) as AA + // verify that the origin is set correctly + assert(transformedAST.origin == original) + } +} data class BazRoot(var stmts: MutableList = mutableListOf()) : Node() data class BazStmt(val desc: String? = null) : Node() data class BarRoot(var stmts: MutableList = mutableListOf()) : Node() data class BarStmt(val desc: String) : Node() + +data class FooRoot(var desc: String, var stmts: MutableList = mutableListOf()) : Node() + +open class AA(var a: String, val child: AB) : Node() +open class AB(var b: String, val child: AC) : Node() +open class AC(var c: String, val children: MutableList) : Node() +open class AD(var d: String) : Node() + +class BA(a: String, child: AB) : AA(a, child) +class BB(b: String, child: AC) : AB(b, child) +class BD(d: String) : AD(d) diff --git a/gradle.properties b/gradle.properties index dc9b75c3..ff8ea3ff 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=1.5.75-SNAPSHOT +version=1.5.77-SNAPSHOT # Note that we use the EXACT same version of Kotlin as the one included in Gradle, to avoid # conflicts kotlin_version=1.8.20 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f387ad74..00440c9c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,8 +4,8 @@ superPublish = { id = "com.vanniktech.maven.publish", version = "0.22.0" } ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "11.5.1" } [versions] -lwjava = "0.3.0" -lwkotlin = "0.3.0" +lwjava = "0.3.1" +lwkotlin = "0.3.2" kotestVersion= "1.3.3" [libraries] diff --git a/lionweb-gen-gradle/src/main/kotlin/com/strumenta/kolasu/lionwebgen/LionWebGradlePlugin.kt b/lionweb-gen-gradle/src/main/kotlin/com/strumenta/kolasu/lionwebgen/LionWebGradlePlugin.kt index b4acc1bb..80324f1f 100644 --- a/lionweb-gen-gradle/src/main/kotlin/com/strumenta/kolasu/lionwebgen/LionWebGradlePlugin.kt +++ b/lionweb-gen-gradle/src/main/kotlin/com/strumenta/kolasu/lionwebgen/LionWebGradlePlugin.kt @@ -3,6 +3,7 @@ package com.strumenta.kolasu.lionwebgen import com.google.devtools.ksp.gradle.KspExtension import com.strumenta.kolasu.lionweb.ASTGenerator import com.strumenta.kolasu.lionweb.KotlinCodeProcessor +import com.strumenta.kolasu.lionweb.LIONWEB_VERSION_USED_BY_KOLASU import com.strumenta.kolasu.lionweb.StarLasuLWLanguage import io.lionweb.lioncore.java.language.Language import io.lionweb.lioncore.java.serialization.JsonSerialization @@ -46,7 +47,8 @@ class LionWebGradlePlugin : Plugin { println("processing languageFile $languageFile") when (languageFile.extension) { "json" -> { - val jsonser = SerializationProvider.getStandardJsonSerialization() + val jsonser = SerializationProvider.getStandardJsonSerialization( + LIONWEB_VERSION_USED_BY_KOLASU) jsonser.instanceResolver.addTree(StarLasuLWLanguage) val language = jsonser.deserializeToNodes(FileInputStream(languageFile)).first() as Language val existingKotlinClasses = KotlinCodeProcessor().classesDeclaredInDir(project.file("src/main/kotlin")) @@ -164,7 +166,7 @@ class LionWebGradlePlugin : Plugin { addKolasuModule("lionweb-gen") project.dependencies.add("ksp", "com.strumenta.kolasu:kolasu-lionweb-ksp:${project.kolasuVersion}") project.dependencies.add("api", "com.github.ajalt.clikt:clikt:3.5.0") - project.dependencies.add("api", "io.lionweb.lionweb-java:lionweb-java-2023.1-core:${project.lionwebJavaVersion}") + project.dependencies.add("api", "io.lionweb.lionweb-java:lionweb-java-2024.1-core:${project.lionwebJavaVersion}") } } \ No newline at end of file diff --git a/lionweb-gen-gradle/src/test/resources/properties-language.json b/lionweb-gen-gradle/src/test/resources/properties-language.json index 77b385a6..128e518a 100644 --- a/lionweb-gen-gradle/src/test/resources/properties-language.json +++ b/lionweb-gen-gradle/src/test/resources/properties-language.json @@ -1,5 +1,5 @@ { - "serializationFormatVersion": "2024.1", + "serializationFormatVersion": "2023.1", "languages": [ { "version": "1", @@ -11,14 +11,14 @@ "id": "starlasu_language_io-lionweb-Properties", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Language" }, "properties": [ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "io.lionweb.Properties" @@ -26,7 +26,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Language-version" }, "value": "1" @@ -34,7 +34,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties" @@ -44,7 +44,7 @@ { "containment": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Language-entities" }, "children": [ @@ -62,7 +62,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Language-dependsOn" }, "targets": [ @@ -80,14 +80,14 @@ "id": "starlasu_language_io-lionweb-Properties_PropertiesFile", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-abstract" }, "value": "false" @@ -95,7 +95,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "PropertiesFile" @@ -103,7 +103,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_PropertiesFile" @@ -113,7 +113,7 @@ { "containment": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Classifier-features" }, "children": [ @@ -125,7 +125,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-extends" }, "targets": [ @@ -138,7 +138,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-implements" }, "targets": [] @@ -151,14 +151,14 @@ "id": "starlasu_language_io-lionweb-Properties_PropertiesFile_props", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Containment" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Link-multiple" }, "value": "true" @@ -166,7 +166,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Feature-optional" }, "value": "true" @@ -174,7 +174,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "props" @@ -182,7 +182,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_PropertiesFile_props" @@ -193,7 +193,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Link-type" }, "targets": [ @@ -211,14 +211,14 @@ "id": "starlasu_language_io-lionweb-Properties_Property", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-abstract" }, "value": "false" @@ -226,7 +226,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "Property" @@ -234,7 +234,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_Property" @@ -244,7 +244,7 @@ { "containment": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Classifier-features" }, "children": [ @@ -257,7 +257,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-extends" }, "targets": [ @@ -270,7 +270,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-implements" }, "targets": [] @@ -283,14 +283,14 @@ "id": "starlasu_language_io-lionweb-Properties_Property_name", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Property" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Feature-optional" }, "value": "false" @@ -298,7 +298,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "name" @@ -306,7 +306,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_Property_name" @@ -317,13 +317,13 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Property-type" }, "targets": [ { "resolveInfo": "String", - "reference": "LionCore-builtins-String-2024-1" + "reference": "LionCore-builtins-String" } ] } @@ -335,14 +335,14 @@ "id": "starlasu_language_io-lionweb-Properties_Property_value", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Containment" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Link-multiple" }, "value": "false" @@ -350,7 +350,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Feature-optional" }, "value": "true" @@ -358,7 +358,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "value" @@ -366,7 +366,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_Property_value" @@ -377,7 +377,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Link-type" }, "targets": [ @@ -395,14 +395,14 @@ "id": "starlasu_language_io-lionweb-Properties_Value", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-abstract" }, "value": "true" @@ -410,7 +410,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "Value" @@ -418,7 +418,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_Value" @@ -428,7 +428,7 @@ { "containment": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Classifier-features" }, "children": [] @@ -438,7 +438,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-extends" }, "targets": [ @@ -451,7 +451,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-implements" }, "targets": [] @@ -464,14 +464,14 @@ "id": "starlasu_language_io-lionweb-Properties_BooleanValue", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-abstract" }, "value": "false" @@ -479,7 +479,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "BooleanValue" @@ -487,7 +487,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_BooleanValue" @@ -497,7 +497,7 @@ { "containment": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Classifier-features" }, "children": [ @@ -509,7 +509,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-extends" }, "targets": [ @@ -522,7 +522,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-implements" }, "targets": [] @@ -535,14 +535,14 @@ "id": "starlasu_language_io-lionweb-Properties_BooleanValue_value", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Property" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Feature-optional" }, "value": "false" @@ -550,7 +550,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "value" @@ -558,7 +558,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_BooleanValue_value" @@ -569,13 +569,13 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Property-type" }, "targets": [ { "resolveInfo": "Boolean", - "reference": "LionCore-builtins-Boolean-2024-1" + "reference": "LionCore-builtins-Boolean" } ] } @@ -587,14 +587,14 @@ "id": "starlasu_language_io-lionweb-Properties_DecValue", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-abstract" }, "value": "false" @@ -602,7 +602,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "DecValue" @@ -610,7 +610,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_DecValue" @@ -620,7 +620,7 @@ { "containment": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Classifier-features" }, "children": [ @@ -632,7 +632,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-extends" }, "targets": [ @@ -645,7 +645,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-implements" }, "targets": [] @@ -658,14 +658,14 @@ "id": "starlasu_language_io-lionweb-Properties_DecValue_value", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Property" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Feature-optional" }, "value": "false" @@ -673,7 +673,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "value" @@ -681,7 +681,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_DecValue_value" @@ -692,13 +692,13 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Property-type" }, "targets": [ { "resolveInfo": "String", - "reference": "LionCore-builtins-String-2024-1" + "reference": "LionCore-builtins-String" } ] } @@ -710,14 +710,14 @@ "id": "starlasu_language_io-lionweb-Properties_IntValue", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-abstract" }, "value": "false" @@ -725,7 +725,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "IntValue" @@ -733,7 +733,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_IntValue" @@ -743,7 +743,7 @@ { "containment": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Classifier-features" }, "children": [ @@ -755,7 +755,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-extends" }, "targets": [ @@ -768,7 +768,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-implements" }, "targets": [] @@ -781,14 +781,14 @@ "id": "starlasu_language_io-lionweb-Properties_IntValue_value", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Property" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Feature-optional" }, "value": "false" @@ -796,7 +796,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "value" @@ -804,7 +804,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_IntValue_value" @@ -815,13 +815,13 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Property-type" }, "targets": [ { "resolveInfo": "String", - "reference": "LionCore-builtins-String-2024-1" + "reference": "LionCore-builtins-String" } ] } @@ -833,14 +833,14 @@ "id": "starlasu_language_io-lionweb-Properties_StringValue", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-abstract" }, "value": "false" @@ -848,7 +848,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "StringValue" @@ -856,7 +856,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_StringValue" @@ -866,7 +866,7 @@ { "containment": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Classifier-features" }, "children": [ @@ -878,7 +878,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-extends" }, "targets": [ @@ -891,7 +891,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-implements" }, "targets": [] @@ -904,14 +904,14 @@ "id": "starlasu_language_io-lionweb-Properties_StringValue_value", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Property" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Feature-optional" }, "value": "false" @@ -919,7 +919,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "value" @@ -927,7 +927,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_StringValue_value" @@ -938,13 +938,13 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Property-type" }, "targets": [ { "resolveInfo": "String", - "reference": "LionCore-builtins-String-2024-1" + "reference": "LionCore-builtins-String" } ] } diff --git a/lionweb-gen/src/main/kotlin/com/strumenta/kolasu/lionweb/ASTGenerator.kt b/lionweb-gen/src/main/kotlin/com/strumenta/kolasu/lionweb/ASTGenerator.kt index 11ae9f81..9e1c1170 100644 --- a/lionweb-gen/src/main/kotlin/com/strumenta/kolasu/lionweb/ASTGenerator.kt +++ b/lionweb-gen/src/main/kotlin/com/strumenta/kolasu/lionweb/ASTGenerator.kt @@ -224,10 +224,10 @@ class ASTGenerator(val packageName: String, val language: LWLanguage) { classifier.id == StarLasuLWLanguage.ASTNode.id -> { Node::class.java.asTypeName() } - classifier.id == LionCoreBuiltins.getNode().id -> { + classifier.id == LionCoreBuiltins.getNode(LIONWEB_VERSION_USED_BY_KOLASU).id -> { Node::class.java.asTypeName() } - classifier.id == LionCoreBuiltins.getINamed().id -> { + classifier.id == LionCoreBuiltins.getINamed(LIONWEB_VERSION_USED_BY_KOLASU).id -> { Named::class.java.asTypeName() } classifier.id == StarLasuLWLanguage.Position.id -> { @@ -244,13 +244,13 @@ class ASTGenerator(val packageName: String, val language: LWLanguage) { private fun typeName(dataType: DataType<*>): TypeName { return when { - dataType == LionCoreBuiltins.getString() -> { + dataType == LionCoreBuiltins.getString(LIONWEB_VERSION_USED_BY_KOLASU) -> { ClassName.bestGuess("kotlin.String") } - dataType == LionCoreBuiltins.getBoolean() -> { + dataType == LionCoreBuiltins.getBoolean(LIONWEB_VERSION_USED_BY_KOLASU) -> { Boolean::class.java.asTypeName() } - dataType == LionCoreBuiltins.getInteger() -> { + dataType == LionCoreBuiltins.getInteger(LIONWEB_VERSION_USED_BY_KOLASU) -> { ClassName.bestGuess("kotlin.Int") } dataType.language == this.language -> { diff --git a/lionweb-gen/src/main/kotlin/com/strumenta/kolasu/lionweb/ASTGeneratorCLI.kt b/lionweb-gen/src/main/kotlin/com/strumenta/kolasu/lionweb/ASTGeneratorCLI.kt index 1b90d362..347bef71 100644 --- a/lionweb-gen/src/main/kotlin/com/strumenta/kolasu/lionweb/ASTGeneratorCLI.kt +++ b/lionweb-gen/src/main/kotlin/com/strumenta/kolasu/lionweb/ASTGeneratorCLI.kt @@ -19,7 +19,7 @@ class ASTGeneratorCommand : CliktCommand() { override fun run() { val existingKotlinClasses = KotlinCodeProcessor().classesDeclaredInDir(existingKotlinCode) - val jsonser = SerializationProvider.getStandardJsonSerialization() + val jsonser = SerializationProvider.getStandardJsonSerialization(LIONWEB_VERSION_USED_BY_KOLASU) jsonser.instanceResolver.addTree(StarLasuLWLanguage) val language = jsonser.deserializeToNodes(FileInputStream(languageFile)).first() as Language val ktFiles = ASTGenerator(packageName, language).generateClasses(existingKotlinClasses) diff --git a/lionweb-gen/src/test/kotlin/ASTGeneratorTest.kt b/lionweb-gen/src/test/kotlin/ASTGeneratorTest.kt index 58bc834f..af84bbd4 100644 --- a/lionweb-gen/src/test/kotlin/ASTGeneratorTest.kt +++ b/lionweb-gen/src/test/kotlin/ASTGeneratorTest.kt @@ -1,4 +1,5 @@ import com.strumenta.kolasu.lionweb.ASTGenerator +import com.strumenta.kolasu.lionweb.LIONWEB_VERSION_USED_BY_KOLASU import com.strumenta.kolasu.lionweb.LWLanguage import com.strumenta.kolasu.lionweb.StarLasuLWLanguage import io.lionweb.lioncore.java.language.Interface @@ -14,7 +15,7 @@ class ASTGeneratorTest { @Test fun allASTClassesAreGeneratedAsExpected() { val inputStream = this.javaClass.getResourceAsStream("/properties-language.json") - val jsonser = SerializationProvider.getStandardJsonSerialization() + val jsonser = SerializationProvider.getStandardJsonSerialization(LIONWEB_VERSION_USED_BY_KOLASU) jsonser.instanceResolver.addTree(StarLasuLWLanguage) val propertiesLanguage = jsonser.deserializeToNodes(inputStream).first() as Language val generated = ASTGenerator("com.strumenta.properties", propertiesLanguage).generateClasses() @@ -72,7 +73,9 @@ public data class StringValue( Interface().apply { name = "MyInterface" key = "MyKey" - addFeature(Property.createRequired("someFlag", LionCoreBuiltins.getBoolean())) + addFeature( + Property.createRequired("someFlag", LionCoreBuiltins.getBoolean(LIONWEB_VERSION_USED_BY_KOLASU)) + ) } ) val generated = ASTGenerator("com.strumenta.example", dummyLanguage).generateClasses() diff --git a/lionweb-gen/src/test/resources/properties-language.json b/lionweb-gen/src/test/resources/properties-language.json index 0ee0803f..01df29db 100644 --- a/lionweb-gen/src/test/resources/properties-language.json +++ b/lionweb-gen/src/test/resources/properties-language.json @@ -1,5 +1,5 @@ { - "serializationFormatVersion": "2024.1", + "serializationFormatVersion": "2023.1", "languages": [ { "version": "1", @@ -12,14 +12,14 @@ "id": "starlasu_language_io-lionweb-Properties", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Language" }, "properties": [ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "io.lionweb.Properties" @@ -27,7 +27,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Language-version" }, "value": "1" @@ -35,7 +35,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties" @@ -45,7 +45,7 @@ { "containment": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Language-entities" }, "children": [ @@ -63,7 +63,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Language-dependsOn" }, "targets": [ @@ -81,14 +81,14 @@ "id": "starlasu_language_io-lionweb-Properties_PropertiesFile", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-abstract" }, "value": "false" @@ -96,7 +96,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "PropertiesFile" @@ -104,7 +104,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_PropertiesFile" @@ -114,7 +114,7 @@ { "containment": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Classifier-features" }, "children": [ @@ -126,7 +126,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-extends" }, "targets": [ @@ -139,7 +139,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-implements" }, "targets": [] @@ -152,14 +152,14 @@ "id": "starlasu_language_io-lionweb-Properties_PropertiesFile_props", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Containment" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Link-multiple" }, "value": "true" @@ -167,7 +167,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Feature-optional" }, "value": "true" @@ -175,7 +175,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "props" @@ -183,7 +183,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_PropertiesFile_props" @@ -194,7 +194,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Link-type" }, "targets": [ @@ -212,14 +212,14 @@ "id": "starlasu_language_io-lionweb-Properties_Property", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-abstract" }, "value": "false" @@ -227,7 +227,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "Property" @@ -235,7 +235,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_Property" @@ -245,7 +245,7 @@ { "containment": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Classifier-features" }, "children": [ @@ -258,7 +258,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-extends" }, "targets": [ @@ -271,7 +271,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-implements" }, "targets": [] @@ -284,14 +284,14 @@ "id": "starlasu_language_io-lionweb-Properties_Property_name", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Property" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Feature-optional" }, "value": "false" @@ -299,7 +299,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "name" @@ -307,7 +307,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_Property_name" @@ -318,13 +318,13 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Property-type" }, "targets": [ { "resolveInfo": "String", - "reference": "LionCore-builtins-String-2024-1" + "reference": "LionCore-builtins-String" } ] } @@ -336,14 +336,14 @@ "id": "starlasu_language_io-lionweb-Properties_Property_value", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Containment" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Link-multiple" }, "value": "false" @@ -351,7 +351,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Feature-optional" }, "value": "true" @@ -359,7 +359,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "value" @@ -367,7 +367,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_Property_value" @@ -378,7 +378,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Link-type" }, "targets": [ @@ -396,14 +396,14 @@ "id": "starlasu_language_io-lionweb-Properties_Value", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-abstract" }, "value": "true" @@ -411,7 +411,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "Value" @@ -419,7 +419,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_Value" @@ -429,7 +429,7 @@ { "containment": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Classifier-features" }, "children": [] @@ -439,7 +439,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-extends" }, "targets": [ @@ -452,7 +452,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-implements" }, "targets": [] @@ -465,14 +465,14 @@ "id": "starlasu_language_io-lionweb-Properties_BooleanValue", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-abstract" }, "value": "false" @@ -480,7 +480,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "BooleanValue" @@ -488,7 +488,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_BooleanValue" @@ -498,7 +498,7 @@ { "containment": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Classifier-features" }, "children": [ @@ -510,7 +510,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-extends" }, "targets": [ @@ -523,7 +523,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-implements" }, "targets": [] @@ -536,14 +536,14 @@ "id": "starlasu_language_io-lionweb-Properties_BooleanValue_value", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Property" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Feature-optional" }, "value": "false" @@ -551,7 +551,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "value" @@ -559,7 +559,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_BooleanValue_value" @@ -570,13 +570,13 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Property-type" }, "targets": [ { "resolveInfo": "Boolean", - "reference": "LionCore-builtins-Boolean-2024-1" + "reference": "LionCore-builtins-Boolean" } ] } @@ -588,14 +588,14 @@ "id": "starlasu_language_io-lionweb-Properties_DecValue", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-abstract" }, "value": "false" @@ -603,7 +603,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "DecValue" @@ -611,7 +611,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_DecValue" @@ -621,7 +621,7 @@ { "containment": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Classifier-features" }, "children": [ @@ -633,7 +633,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-extends" }, "targets": [ @@ -646,7 +646,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-implements" }, "targets": [] @@ -659,14 +659,14 @@ "id": "starlasu_language_io-lionweb-Properties_DecValue_value", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Property" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Feature-optional" }, "value": "false" @@ -674,7 +674,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "value" @@ -682,7 +682,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_DecValue_value" @@ -693,13 +693,13 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Property-type" }, "targets": [ { "resolveInfo": "String", - "reference": "LionCore-builtins-String-2024-1" + "reference": "LionCore-builtins-String" } ] } @@ -711,14 +711,14 @@ "id": "starlasu_language_io-lionweb-Properties_IntValue", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-abstract" }, "value": "false" @@ -726,7 +726,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "IntValue" @@ -734,7 +734,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_IntValue" @@ -744,7 +744,7 @@ { "containment": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Classifier-features" }, "children": [ @@ -756,7 +756,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-extends" }, "targets": [ @@ -769,7 +769,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-implements" }, "targets": [] @@ -782,14 +782,14 @@ "id": "starlasu_language_io-lionweb-Properties_IntValue_value", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Property" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Feature-optional" }, "value": "false" @@ -797,7 +797,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "value" @@ -805,7 +805,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_IntValue_value" @@ -816,13 +816,13 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Property-type" }, "targets": [ { "resolveInfo": "String", - "reference": "LionCore-builtins-String-2024-1" + "reference": "LionCore-builtins-String" } ] } @@ -834,14 +834,14 @@ "id": "starlasu_language_io-lionweb-Properties_StringValue", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-abstract" }, "value": "false" @@ -849,7 +849,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "StringValue" @@ -857,7 +857,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_StringValue" @@ -867,7 +867,7 @@ { "containment": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Classifier-features" }, "children": [ @@ -879,7 +879,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-extends" }, "targets": [ @@ -892,7 +892,7 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Concept-implements" }, "targets": [] @@ -905,14 +905,14 @@ "id": "starlasu_language_io-lionweb-Properties_StringValue_value", "classifier": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Property" }, "properties": [ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Feature-optional" }, "value": "false" @@ -920,7 +920,7 @@ { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "value" @@ -928,7 +928,7 @@ { "property": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "IKeyed-key" }, "value": "io-lionweb-Properties_StringValue_value" @@ -939,13 +939,13 @@ { "reference": { "language": "LionCore-M3", - "version": "2024.1", + "version": "2023.1", "key": "Property-type" }, "targets": [ { "resolveInfo": "String", - "reference": "LionCore-builtins-String-2024-1" + "reference": "LionCore-builtins-String" } ] } diff --git a/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebFluentInterface.kt b/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebFluentInterface.kt index a0068861..95a0add6 100644 --- a/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebFluentInterface.kt +++ b/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebFluentInterface.kt @@ -2,53 +2,11 @@ package com.strumenta.kolasu.lionweb import com.strumenta.kolasu.model.Multiplicity import io.lionweb.lioncore.java.language.Concept -import io.lionweb.lioncore.java.language.DataType import io.lionweb.lioncore.java.language.IKeyed -import io.lionweb.lioncore.java.language.Interface -import io.lionweb.lioncore.java.language.Language -import io.lionweb.lioncore.java.language.Property import io.lionweb.lioncore.java.model.Node import io.lionweb.lioncore.java.model.impl.DynamicNode import kotlin.random.Random -// TODO: use equivalent methods from LionWeb Kotlin - -fun Language.addInterface(name: String): Interface { - val intf = - Interface( - this, - name, - this.idForContainedElement(name), - this.keyForContainedElement(name) - ) - this.addElement(intf) - return intf -} - -fun Concept.addProperty( - name: String, - type: DataType<*>, - multiplicity: Multiplicity = Multiplicity.SINGULAR -): Property { - require(multiplicity != Multiplicity.MANY) - val property = - Property().apply { - this.name = name - this.id = "${this@addProperty.id!!.removeSuffix("-id")}-$name-id" - this.key = "${this@addProperty.key!!.removeSuffix("-key")}-$name-key" - this.type = type - this.setOptional( - when (multiplicity) { - Multiplicity.SINGULAR -> false - Multiplicity.MANY -> true - Multiplicity.OPTIONAL -> true - } - ) - } - this.addFeature(property) - return property -} - val Multiplicity.optional get() = this == Multiplicity.OPTIONAL || this == Multiplicity.MANY diff --git a/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebLanguageConverter.kt b/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebLanguageConverter.kt index 83aab690..2f8d75e4 100644 --- a/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebLanguageConverter.kt +++ b/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebLanguageConverter.kt @@ -52,8 +52,8 @@ class LionWebLanguageConverter { val starLasuKLanguage = KolasuLanguage(StarLasuLWLanguage.name) languages.associate(starLasuKLanguage, StarLasuLWLanguage) registerMapping(Node::class, StarLasuLWLanguage.ASTNode) - registerMapping(Named::class, LionCoreBuiltins.getINamed()) - registerMapping(PossiblyNamed::class, LionCoreBuiltins.getINamed()) + registerMapping(Named::class, LionCoreBuiltins.getINamed(LIONWEB_VERSION_USED_BY_KOLASU)) + registerMapping(PossiblyNamed::class, LionCoreBuiltins.getINamed(LIONWEB_VERSION_USED_BY_KOLASU)) registerMapping(CommonElement::class, StarLasuLWLanguage.CommonElement) registerMapping(BehaviorDeclaration::class, StarLasuLWLanguage.BehaviorDeclaration) registerMapping(Documentation::class, StarLasuLWLanguage.Documentation) @@ -78,7 +78,7 @@ class LionWebLanguageConverter { } fun exportToLionWeb(kolasuLanguage: KolasuLanguage): LWLanguage { - val lionwebLanguage = LWLanguage() + val lionwebLanguage = LWLanguage(LIONWEB_VERSION_USED_BY_KOLASU) lionwebLanguage.version = "1" lionwebLanguage.name = kolasuLanguage.qualifiedName lionwebLanguage.key = kolasuLanguage.qualifiedName.replace('.', '-') @@ -185,7 +185,7 @@ class LionWebLanguageConverter { this.languages.associate(kolasuLanguage, lwLanguage) kolasuLanguage.astClasses.forEach { astClass -> var classifier: Classifier<*>? = null - val annotation = astClass.annotations.filterIsInstance(LionWebAssociation::class.java).firstOrNull() + val annotation = astClass.annotations.filterIsInstance().firstOrNull() if (annotation != null) { classifier = lwLanguage.elements.filterIsInstance(Classifier::class.java).find { it.key == annotation.key @@ -328,10 +328,10 @@ class LionWebLanguageConverter { private fun toLWDataType(kType: KType, lionwebLanguage: LWLanguage): DataType<*> { return when (kType) { - Int::class.createType() -> LionCoreBuiltins.getInteger() - Long::class.createType() -> LionCoreBuiltins.getInteger() - String::class.createType() -> LionCoreBuiltins.getString() - Boolean::class.createType() -> LionCoreBuiltins.getBoolean() + Int::class.createType() -> LionCoreBuiltins.getInteger(LIONWEB_VERSION_USED_BY_KOLASU) + Long::class.createType() -> LionCoreBuiltins.getInteger(LIONWEB_VERSION_USED_BY_KOLASU) + String::class.createType() -> LionCoreBuiltins.getString(LIONWEB_VERSION_USED_BY_KOLASU) + Boolean::class.createType() -> LionCoreBuiltins.getBoolean(LIONWEB_VERSION_USED_BY_KOLASU) Char::class.createType() -> StarLasuLWLanguage.Char else -> { val kClass = kType.classifier as KClass<*> diff --git a/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebModelConverter.kt b/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebModelConverter.kt index aff2664a..d14e85e7 100644 --- a/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebModelConverter.kt +++ b/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebModelConverter.kt @@ -465,7 +465,7 @@ class LionWebModelConverter( fun prepareSerialization( serialization: AbstractSerialization = - SerializationProvider.getStandardJsonSerialization() + SerializationProvider.getStandardJsonSerialization(LIONWEB_VERSION_USED_BY_KOLASU) ): AbstractSerialization { StarLasuLWLanguage MetamodelRegistry.prepareJsonSerialization(serialization) @@ -740,7 +740,7 @@ class LionWebModelConverter( constructor.callBy(params) as T } catch (e: Exception) { throw RuntimeException( - "Issue instantiating using constructor $constructor with params " + + "Issue instantiating using constructor ${kClass.qualifiedName}.$constructor with params " + "${params.map { "${it.key.name}=${it.value}" }}", e ) @@ -886,7 +886,7 @@ class ParsingResultWithTokens( source: Source? = null ) : ParsingResult(issues, root, code, incompleteNode, firstStage, time, source) -class IssueNode : BaseNode() { +class IssueNode : BaseNode(LIONWEB_VERSION_USED_BY_KOLASU) { var type: EnumerationValue? by property("type") var message: String? by property("message") var severity: EnumerationValue? by property("severity") @@ -897,7 +897,7 @@ class IssueNode : BaseNode() { } } -class ParsingResultNode(val source: Source?) : BaseNode() { +class ParsingResultNode(val source: Source?) : BaseNode(LIONWEB_VERSION_USED_BY_KOLASU) { override fun calculateID(): String? { return try { SimpleSourceIdProvider().sourceId(source) + "_ParsingResult" diff --git a/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/StarLasuLWLanguage.kt b/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/StarLasuLWLanguage.kt index 824a7f4f..222d18e5 100644 --- a/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/StarLasuLWLanguage.kt +++ b/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/StarLasuLWLanguage.kt @@ -7,10 +7,10 @@ import com.strumenta.kolasu.parsing.KolasuToken import com.strumenta.kolasu.parsing.TokenCategory import com.strumenta.kolasu.validation.IssueSeverity import com.strumenta.kolasu.validation.IssueType +import io.lionweb.lioncore.java.LionWebVersion import io.lionweb.lioncore.java.language.Annotation import io.lionweb.lioncore.java.language.Concept import io.lionweb.lioncore.java.language.Enumeration -import io.lionweb.lioncore.java.language.EnumerationLiteral import io.lionweb.lioncore.java.language.Interface import io.lionweb.lioncore.java.language.Language import io.lionweb.lioncore.java.language.LionCoreBuiltins @@ -22,8 +22,10 @@ import io.lionweb.lioncore.java.serialization.PrimitiveValuesSerialization.Primi import io.lionweb.lioncore.java.serialization.PrimitiveValuesSerialization.PrimitiveSerializer import io.lionweb.lioncore.kotlin.MetamodelRegistry import io.lionweb.lioncore.kotlin.Multiplicity +import io.lionweb.lioncore.kotlin.addLiteral import io.lionweb.lioncore.kotlin.createConcept import io.lionweb.lioncore.kotlin.createContainment +import io.lionweb.lioncore.kotlin.createInterface import io.lionweb.lioncore.kotlin.createPrimitiveType import io.lionweb.lioncore.kotlin.createProperty import io.lionweb.lioncore.kotlin.createReference @@ -42,11 +44,13 @@ import com.strumenta.kolasu.validation.Issue as KIssue private const val PLACEHOLDER_NODE = "PlaceholderNode" +val LIONWEB_VERSION_USED_BY_KOLASU = LionWebVersion.v2023_1 + /** * When this object is referenced the initialization is performed. When that happens the serializers and deserializers * for Position and other primitive types are registered in the MetamodelRegistry. */ -object StarLasuLWLanguage : Language("com.strumenta.StarLasu") { +object StarLasuLWLanguage : Language(LIONWEB_VERSION_USED_BY_KOLASU, "com.strumenta.StarLasu") { val CommonElement: Interface val Issue: Concept @@ -67,21 +71,24 @@ object StarLasuLWLanguage : Language("com.strumenta.StarLasu") { addPlaceholderNodeAnnotation(astNode) - CommonElement = addInterface(KCommonElement::class.simpleName!!) - addInterface(KBehaviorDeclaration::class.simpleName!!).apply { addExtendedInterface(CommonElement) } - addInterface(KDocumentation::class.simpleName!!).apply { addExtendedInterface(CommonElement) } - addInterface(KEntityDeclaration::class.simpleName!!).apply { addExtendedInterface(CommonElement) } - addInterface(KEntityGroupDeclaration::class.simpleName!!).apply { addExtendedInterface(CommonElement) } - addInterface(KExpression::class.simpleName!!).apply { addExtendedInterface(CommonElement) } - addInterface(KParameter::class.simpleName!!).apply { addExtendedInterface(CommonElement) } - addInterface(KPlaceholderElement::class.simpleName!!).apply { addExtendedInterface(CommonElement) } - addInterface(KStatement::class.simpleName!!).apply { addExtendedInterface(CommonElement) } - addInterface(KTypeAnnotation::class.simpleName!!).apply { addExtendedInterface(CommonElement) } + CommonElement = createInterface(KCommonElement::class.simpleName!!) + createInterface(KBehaviorDeclaration::class.simpleName!!).apply { addExtendedInterface(CommonElement) } + createInterface(KDocumentation::class.simpleName!!).apply { addExtendedInterface(CommonElement) } + createInterface(KEntityDeclaration::class.simpleName!!).apply { addExtendedInterface(CommonElement) } + createInterface(KEntityGroupDeclaration::class.simpleName!!).apply { addExtendedInterface(CommonElement) } + createInterface(KExpression::class.simpleName!!).apply { addExtendedInterface(CommonElement) } + createInterface(KParameter::class.simpleName!!).apply { addExtendedInterface(CommonElement) } + createInterface(KPlaceholderElement::class.simpleName!!).apply { addExtendedInterface(CommonElement) } + createInterface(KStatement::class.simpleName!!).apply { addExtendedInterface(CommonElement) } + createInterface(KTypeAnnotation::class.simpleName!!).apply { addExtendedInterface(CommonElement) } Issue = createConcept(KIssue::class.simpleName!!).apply { - addProperty(KIssue::type.name, addEnumerationFromClass(this@StarLasuLWLanguage, IssueType::class)) - createProperty(KIssue::message.name, LionCoreBuiltins.getString()) - addProperty(KIssue::severity.name, addEnumerationFromClass(this@StarLasuLWLanguage, IssueSeverity::class)) + createProperty(KIssue::type.name, addEnumerationFromClass(this@StarLasuLWLanguage, IssueType::class)) + createProperty(KIssue::message.name, LionCoreBuiltins.getString(lionWebVersion)) + createProperty( + KIssue::severity.name, + addEnumerationFromClass(this@StarLasuLWLanguage, IssueSeverity::class) + ) createProperty(KIssue::position.name, position, Multiplicity.OPTIONAL) } @@ -89,10 +96,14 @@ object StarLasuLWLanguage : Language("com.strumenta.StarLasu") { ParsingResult = createConcept(KParsingResult::class.simpleName!!).apply { createContainment(KParsingResult<*>::issues.name, Issue, Multiplicity.ZERO_TO_MANY) createContainment(KParsingResult<*>::root.name, ASTNode, Multiplicity.OPTIONAL) - createProperty(KParsingResult<*>::code.name, LionCoreBuiltins.getString(), Multiplicity.OPTIONAL) + createProperty( + KParsingResult<*>::code.name, + LionCoreBuiltins.getString(lionWebVersion), + Multiplicity.OPTIONAL + ) createProperty( ParsingResultWithTokens<*>::tokens.name, - MetamodelRegistry.getPrimitiveType(TokensList::class)!!, + MetamodelRegistry.getPrimitiveType(TokensList::class, LIONWEB_VERSION_USED_BY_KOLASU)!!, Multiplicity.OPTIONAL ) } @@ -108,7 +119,7 @@ object StarLasuLWLanguage : Language("com.strumenta.StarLasu") { idForContainedElement(PLACEHOLDER_NODE), keyForContainedElement(PLACEHOLDER_NODE) ) - placeholderNodeAnnotation.annotates = LionCore.getConcept() + placeholderNodeAnnotation.annotates = LionCore.getConcept(lionWebVersion) val placeholderNodeAnnotationType = Enumeration( this, @@ -116,24 +127,13 @@ object StarLasuLWLanguage : Language("com.strumenta.StarLasu") { ).apply { this.id = "${placeholderNodeAnnotation.id!!.removeSuffix("-id")}-$name-id" this.key = "${placeholderNodeAnnotation.key!!.removeSuffix("-key")}-$name-key" - val enumeration = this - addLiteral( - EnumerationLiteral(this, "MissingASTTransformation").apply { - this.id = "${enumeration.id!!.removeSuffix("-id")}-$name-id" - this.key = "${enumeration.id!!.removeSuffix("-key")}-$name-key" - } - ) - addLiteral( - EnumerationLiteral(this, "FailingASTTransformation").apply { - this.id = "${enumeration.id!!.removeSuffix("-id")}-$name-id" - this.key = "${enumeration.id!!.removeSuffix("-key")}-$name-key" - } - ) + addLiteral("MissingASTTransformation") + addLiteral("FailingASTTransformation") } addElement(placeholderNodeAnnotationType) val reference = - Reference().apply { + Reference(lionWebVersion).apply { this.name = "originalNode" this.id = "${placeholderNodeAnnotation.id!!.removeSuffix("-id")}-$name-id" this.key = "${placeholderNodeAnnotation.key!!.removeSuffix("-key")}-$name-key" @@ -142,7 +142,7 @@ object StarLasuLWLanguage : Language("com.strumenta.StarLasu") { this.setMultiple(false) } placeholderNodeAnnotation.addFeature(reference) - val type = Property().apply { + val type = Property(lionWebVersion).apply { this.name = "type" this.id = "${placeholderNodeAnnotation.id!!.removeSuffix("-id")}-$name-id" this.key = "${placeholderNodeAnnotation.key!!.removeSuffix("-key")}-$name-key" @@ -150,11 +150,11 @@ object StarLasuLWLanguage : Language("com.strumenta.StarLasu") { this.setOptional(false) } placeholderNodeAnnotation.addFeature(type) - val message = Property().apply { + val message = Property(lionWebVersion).apply { this.name = "message" this.id = "${placeholderNodeAnnotation.id!!.removeSuffix("-id")}-$name-id" this.key = "${placeholderNodeAnnotation.key!!.removeSuffix("-key")}-$name-key" - this.type = LionCoreBuiltins.getString() + this.type = LionCoreBuiltins.getString(LIONWEB_VERSION_USED_BY_KOLASU) this.setOptional(false) } placeholderNodeAnnotation.addFeature(message) @@ -288,7 +288,7 @@ private fun registerSerializersAndDeserializersInMetamodelRegistry() { TokensList(tokens) } } - val tlpt = MetamodelRegistry.getPrimitiveType(TokensList::class) + val tlpt = MetamodelRegistry.getPrimitiveType(TokensList::class, LIONWEB_VERSION_USED_BY_KOLASU) ?: throw IllegalStateException("Unknown primitive type class ${TokensList::class}") MetamodelRegistry.addSerializerAndDeserializer(tlpt, tokensListPrimitiveSerializer, tokensListPrimitiveDeserializer) } diff --git a/lionweb/src/test/kotlin/com/strumenta/kolasu/lionweb/LionWebLanguageConverterTest.kt b/lionweb/src/test/kotlin/com/strumenta/kolasu/lionweb/LionWebLanguageConverterTest.kt index 96513a2f..0ac00db5 100644 --- a/lionweb/src/test/kotlin/com/strumenta/kolasu/lionweb/LionWebLanguageConverterTest.kt +++ b/lionweb/src/test/kotlin/com/strumenta/kolasu/lionweb/LionWebLanguageConverterTest.kt @@ -67,7 +67,7 @@ class LionWebLanguageConverterTest { val simpleRootID = simpleRoot.getPropertyByName("id")!! assertEquals("id", simpleRootID.name) assertEquals(false, simpleRootID.isOptional) - assertEquals(LionCoreBuiltins.getInteger(), simpleRootID.type) + assertEquals(LionCoreBuiltins.getInteger(LIONWEB_VERSION_USED_BY_KOLASU), simpleRootID.type) val simpleRootChildren = simpleRoot.getContainmentByName("childrez")!! assertEquals("childrez", simpleRootChildren.name) @@ -85,14 +85,18 @@ class LionWebLanguageConverterTest { assertSame(lwLanguage, simpleNodeA.language) assertEquals(simpleDecl, simpleNodeA.extendedConcept) assertEquals(listOf(StarLasuLWLanguage.EntityDeclaration), simpleNodeA.extendedConcept!!.implemented) - assertEquals(listOf(LionCoreBuiltins.getINamed(), myRelevantInterface), simpleNodeA.implemented) + assertEquals( + listOf(LionCoreBuiltins.getINamed(LIONWEB_VERSION_USED_BY_KOLASU), myRelevantInterface), + simpleNodeA.implemented + ) assertEquals(false, simpleNodeA.isAbstract) assertEquals(2, simpleNodeA.features.size) assertEquals(6, simpleNodeA.allFeatures().size) assertEquals( true, - LionCoreBuiltins.getINamed().getPropertyByName("name") in simpleNodeA.allFeatures() + LionCoreBuiltins.getINamed(LIONWEB_VERSION_USED_BY_KOLASU) + .getPropertyByName("name") in simpleNodeA.allFeatures() ) val simpleNodeARef = simpleNodeA.getReferenceByName("ref")!! @@ -117,7 +121,7 @@ class LionWebLanguageConverterTest { val simpleNodeBValue = simpleNodeB.getPropertyByName("value")!! assertEquals("value", simpleNodeBValue.name) assertEquals(false, simpleNodeBValue.isOptional) - assertEquals(LionCoreBuiltins.getString(), simpleNodeBValue.type) + assertEquals(LionCoreBuiltins.getString(LIONWEB_VERSION_USED_BY_KOLASU), simpleNodeBValue.type) val validationResult = LanguageValidator().validate(lwLanguage) assertEquals(true, validationResult.isSuccessful, validationResult.issues.toString()) @@ -163,7 +167,7 @@ class LionWebLanguageConverterTest { val simpleRootID = simpleRoot.getPropertyByName("id")!! assertEquals("id", simpleRootID.name) assertEquals(false, simpleRootID.isOptional) - assertEquals(LionCoreBuiltins.getInteger(), simpleRootID.type) + assertEquals(LionCoreBuiltins.getInteger(LIONWEB_VERSION_USED_BY_KOLASU), simpleRootID.type) val simpleRootChildren = simpleRoot.getContainmentByName("childrez")!! assertEquals("childrez", simpleRootChildren.name) @@ -182,14 +186,18 @@ class LionWebLanguageConverterTest { assertEquals(false, simpleNodeA.isPartition) assertSame(lwLanguage, simpleNodeA.language) assertEquals(simpleDecl, simpleNodeA.extendedConcept) - assertEquals(listOf(LionCoreBuiltins.getINamed(), myRelevantInterface), simpleNodeA.implemented) + assertEquals( + listOf(LionCoreBuiltins.getINamed(LIONWEB_VERSION_USED_BY_KOLASU), myRelevantInterface), + simpleNodeA.implemented + ) assertEquals(false, simpleNodeA.isAbstract) assertEquals(2, simpleNodeA.features.size) assertEquals(6, simpleNodeA.allFeatures().size) assertEquals( true, - LionCoreBuiltins.getINamed().getPropertyByName("name") in simpleNodeA.allFeatures() + LionCoreBuiltins.getINamed(LIONWEB_VERSION_USED_BY_KOLASU) + .getPropertyByName("name") in simpleNodeA.allFeatures() ) val simpleNodeARef = simpleNodeA.getReferenceByName("ref")!! @@ -215,7 +223,7 @@ class LionWebLanguageConverterTest { val simpleNodeBValue = simpleNodeB.getPropertyByName("value")!! assertEquals("value", simpleNodeBValue.name) assertEquals(false, simpleNodeBValue.isOptional) - assertEquals(LionCoreBuiltins.getString(), simpleNodeBValue.type) + assertEquals(LionCoreBuiltins.getString(LIONWEB_VERSION_USED_BY_KOLASU), simpleNodeBValue.type) val validationResult = LanguageValidator().validate(lwLanguage) assertEquals(true, validationResult.isSuccessful, validationResult.issues.toString()) diff --git a/lionweb/src/test/kotlin/com/strumenta/kolasu/lionweb/LionWebModelConverterTest.kt b/lionweb/src/test/kotlin/com/strumenta/kolasu/lionweb/LionWebModelConverterTest.kt index e6c49662..bf5d058a 100644 --- a/lionweb/src/test/kotlin/com/strumenta/kolasu/lionweb/LionWebModelConverterTest.kt +++ b/lionweb/src/test/kotlin/com/strumenta/kolasu/lionweb/LionWebModelConverterTest.kt @@ -54,7 +54,7 @@ data class NodeWithEnum( class LionWebModelConverterTest { val serialized = """{ - "serializationFormatVersion": "2024.1", + "serializationFormatVersion": "2023.1", "languages": [ { "key": "com-strumenta-SimpleLang", @@ -66,7 +66,7 @@ class LionWebModelConverterTest { }, { "key": "LionCore-builtins", - "version": "2024.1" + "version": "2023.1" } ], "nodes": [ @@ -141,7 +141,7 @@ class LionWebModelConverterTest { { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "A1" @@ -257,7 +257,7 @@ class LionWebModelConverterTest { { "property": { "language": "LionCore-builtins", - "version": "2024.1", + "version": "2023.1", "key": "LionCore-builtins-INamed-name" }, "value": "A3" @@ -422,7 +422,7 @@ class LionWebModelConverterTest { assertEquals("A1", refValue3[0].resolveInfo) assertSame(child1, refValue3[0].referred) - val js = SerializationProvider.getStandardJsonSerialization() + val js = SerializationProvider.getStandardJsonSerialization(LIONWEB_VERSION_USED_BY_KOLASU) assertJSONsAreEqual(serialized, js.serializeTreeToJsonString(lwAST)) } @@ -563,7 +563,7 @@ class LionWebModelConverterTest { assertEquals("ZUM", (exportedN3.getPropertyValueByName("e") as EnumerationValue).enumerationLiteral.name) assertEquals(null, exportedN4.getPropertyValueByName("e")) - val jsonSerialization = SerializationProvider.getStandardJsonSerialization() + val jsonSerialization = SerializationProvider.getStandardJsonSerialization(LIONWEB_VERSION_USED_BY_KOLASU) converter.prepareSerialization(jsonSerialization) jsonSerialization.serializeTreesToJsonString(exportedN1) } @@ -709,7 +709,7 @@ class LionWebModelConverterTest { .withPosition(Position(Point(3, 5), Point(27, 200))) .setSourceForTree(LionWebSource("MySource")) val lwNode = mc.exportModelToLionWeb(n1) - val jsonSerialization = SerializationProvider.getStandardJsonSerialization() + val jsonSerialization = SerializationProvider.getStandardJsonSerialization(LIONWEB_VERSION_USED_BY_KOLASU) mc.prepareSerialization(jsonSerialization) val serializationBlock = jsonSerialization.serializeNodesToSerializationBlock(lwNode) assertEquals( @@ -733,7 +733,7 @@ class LionWebModelConverterTest { .withPosition(Position(Point(3, 5), Point(27, 200))) .setSourceForTree(LionWebSource("MySource")) val lwNode = mc.exportModelToLionWeb(n1) - val jsonSerialization = SerializationProvider.getStandardJsonSerialization() + val jsonSerialization = SerializationProvider.getStandardJsonSerialization(LIONWEB_VERSION_USED_BY_KOLASU) jsonSerialization.enableDynamicNodes() mc.prepareSerialization(jsonSerialization) val json = jsonSerialization.serializeNodesToJsonString(lwNode) diff --git a/lionwebrepo-client/src/functionalTest/kotlin/com/strumenta/kolasu/lionwebclient/KolasuTodoLanguage.kt b/lionwebrepo-client/src/functionalTest/kotlin/com/strumenta/kolasu/lionwebclient/KolasuTodoLanguage.kt index 9d629bca..55c8ddd0 100644 --- a/lionwebrepo-client/src/functionalTest/kotlin/com/strumenta/kolasu/lionwebclient/KolasuTodoLanguage.kt +++ b/lionwebrepo-client/src/functionalTest/kotlin/com/strumenta/kolasu/lionwebclient/KolasuTodoLanguage.kt @@ -2,6 +2,7 @@ package com.strumenta.kolasu.lionwebclient import com.strumenta.kolasu.ids.NodeIdProvider import com.strumenta.kolasu.language.KolasuLanguage +import com.strumenta.kolasu.lionweb.LIONWEB_VERSION_USED_BY_KOLASU import com.strumenta.kolasu.model.ASTRoot import com.strumenta.kolasu.model.Named import com.strumenta.kolasu.model.Node @@ -19,7 +20,7 @@ import io.lionweb.lioncore.kotlin.createContainment import io.lionweb.lioncore.kotlin.lwLanguage val todoAccountLanguage = - lwLanguage("todoAccountLanguage").apply { + lwLanguage("todoAccountLanguage", lionWebVersion = LIONWEB_VERSION_USED_BY_KOLASU).apply { createConcept("TodoAccount").apply { createContainment("projects", LionCoreBuiltins.getNode(), Multiplicity.ZERO_TO_MANY) } diff --git a/lionwebrepo-client/src/functionalTest/kotlin/com/strumenta/kolasu/lionwebclient/TodoFunctionalTest.kt b/lionwebrepo-client/src/functionalTest/kotlin/com/strumenta/kolasu/lionwebclient/TodoFunctionalTest.kt index 8dbaba8d..ce71ca5d 100644 --- a/lionwebrepo-client/src/functionalTest/kotlin/com/strumenta/kolasu/lionwebclient/TodoFunctionalTest.kt +++ b/lionwebrepo-client/src/functionalTest/kotlin/com/strumenta/kolasu/lionwebclient/TodoFunctionalTest.kt @@ -1,5 +1,6 @@ package com.strumenta.kolasu.lionwebclient +import com.strumenta.kolasu.lionweb.LIONWEB_VERSION_USED_BY_KOLASU import com.strumenta.kolasu.model.ReferenceByName import com.strumenta.kolasu.model.SyntheticSource import com.strumenta.kolasu.model.assignParents @@ -10,7 +11,7 @@ import kotlin.test.Test import kotlin.test.assertEquals @Testcontainers -class TodoFunctionalTest : AbstractRepoClientFunctionalTest() { +class TodoFunctionalTest : AbstractRepoClientFunctionalTest(lionWebVersion = LIONWEB_VERSION_USED_BY_KOLASU) { @Test fun noPartitionsOnNewModelRepository() { val kolasuClient = KolasuClient(port = modelRepository!!.firstMappedPort) diff --git a/lionwebrepo-client/src/main/kotlin/com/strumenta/kolasu/lionwebclient/KolasuClient.kt b/lionwebrepo-client/src/main/kotlin/com/strumenta/kolasu/lionwebclient/KolasuClient.kt index d29ab3fe..febf4e51 100644 --- a/lionwebrepo-client/src/main/kotlin/com/strumenta/kolasu/lionwebclient/KolasuClient.kt +++ b/lionwebrepo-client/src/main/kotlin/com/strumenta/kolasu/lionwebclient/KolasuClient.kt @@ -5,6 +5,7 @@ import com.strumenta.kolasu.ids.NodeIdProvider import com.strumenta.kolasu.ids.caching import com.strumenta.kolasu.language.KolasuLanguage import com.strumenta.kolasu.lionweb.KNode +import com.strumenta.kolasu.lionweb.LIONWEB_VERSION_USED_BY_KOLASU import com.strumenta.kolasu.lionweb.LWLanguage import com.strumenta.kolasu.lionweb.LWNode import com.strumenta.kolasu.lionweb.LionWebModelConverter @@ -79,6 +80,7 @@ class KolasuClient( connectTimeOutInSeconds = connectTimeOutInSeconds, callTimeoutInSeconds = callTimeoutInSeconds, authorizationToken = authorizationToken, + lionWebVersion = LIONWEB_VERSION_USED_BY_KOLASU ) private val serializationDecorators = mutableListOf() @@ -108,7 +110,7 @@ class KolasuClient( } private fun calculateSerialization() : JsonSerialization { - val jsonSerialization = SerializationProvider.getStandardJsonSerialization() + val jsonSerialization = SerializationProvider.getStandardJsonSerialization(LIONWEB_VERSION_USED_BY_KOLASU) serializationDecorators.forEach { serializationDecorator -> serializationDecorator.invoke(jsonSerialization) } return jsonSerialization }