Skip to content

Commit

Permalink
Add support in EMF for all new Marker Interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomassetti committed Jul 15, 2024
1 parent 07c9761 commit bdd76b3
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 21 deletions.
33 changes: 24 additions & 9 deletions emf/src/main/kotlin/com/strumenta/kolasu/emf/KolasuMetamodel.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package com.strumenta.kolasu.emf

import com.strumenta.kolasu.model.BehaviorDeclaration
import com.strumenta.kolasu.model.Documentation
import com.strumenta.kolasu.model.EntityDeclaration
import com.strumenta.kolasu.model.EntityGroupDeclaration
import com.strumenta.kolasu.model.Expression
import com.strumenta.kolasu.model.Parameter
import com.strumenta.kolasu.model.Statement
import com.strumenta.kolasu.model.TypeAnnotation
import com.strumenta.kolasu.validation.IssueSeverity
import com.strumenta.kolasu.validation.IssueType
import org.eclipse.emf.ecore.EClass
import org.eclipse.emf.ecore.EPackage
import org.eclipse.emf.ecore.EcoreFactory
import org.eclipse.emf.ecore.EcorePackage
import java.io.File
import kotlin.reflect.KClass

val STARLASU_METAMODEL by lazy { createStarlasuMetamodel() }
val ASTNODE_ECLASS by lazy { STARLASU_METAMODEL.eClassifiers.find { it.name == "ASTNode" }!! as EClass }
Expand Down Expand Up @@ -85,15 +94,15 @@ private fun createStarlasuMetamodel(): EPackage {
addContainment("position", position, 0, 1)
}

ePackage.createEClass("Statement").apply {
this.isInterface = true
}
ePackage.createEClass("Expression").apply {
this.isInterface = true
}
ePackage.createEClass("EntityDeclaration").apply {
this.isInterface = true
}
ePackage.addCorrespondingTo(Statement::class)
ePackage.addCorrespondingTo(Expression::class)
ePackage.addCorrespondingTo(EntityDeclaration::class)
ePackage.addCorrespondingTo(EntityGroupDeclaration::class)
ePackage.addCorrespondingTo(TypeAnnotation::class)
ePackage.addCorrespondingTo(BehaviorDeclaration::class)
ePackage.addCorrespondingTo(Parameter::class)
ePackage.addCorrespondingTo(Documentation::class)

ePackage.createEClass("PlaceholderElement").apply {
this.isInterface = true
addAttribute("placeholderName", stringDT, 0, 1)
Expand Down Expand Up @@ -197,3 +206,9 @@ fun main() {
STARLASU_METAMODEL.saveEcore(File("kolasu-2.0.xmi"))
STARLASU_METAMODEL.saveAsJson(File("kolasu-2.0.json"))
}

fun EPackage.addCorrespondingTo(kClass: KClass<*>): EClass {
return this.createEClass(kClass.simpleName!!).apply {
this.isInterface = kClass.java.isInterface
}
}
31 changes: 19 additions & 12 deletions emf/src/main/kotlin/com/strumenta/kolasu/emf/Metamodel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ class KolasuClassHandler(val kolasuKClass: KClass<*>, val kolasuEClass: EClass)
}

override fun external(): Boolean = true

companion object {
fun forKClass(kclass: KClass<*>): KolasuClassHandler {
return KolasuClassHandler(
kclass,
STARLASU_METAMODEL
.getEClass(kclass.simpleName!!)
)
}
}
}

class KolasuDataTypeHandler(val kolasuKClass: KClass<*>, val kolasuDataType: EDataType) : EDataTypeHandler {
Expand All @@ -78,18 +88,15 @@ val PossiblyNamedHandler = KolasuClassHandler(PossiblyNamed::class, STARLASU_MET
val ReferenceByNameHandler = KolasuClassHandler(ReferenceByName::class, STARLASU_METAMODEL.getEClass("ReferenceByName"))
val ResultHandler = KolasuClassHandler(Result::class, STARLASU_METAMODEL.getEClass("Result"))

val StatementHandler = KolasuClassHandler(Statement::class, STARLASU_METAMODEL.getEClass("Statement"))
val ExpressionHandler = KolasuClassHandler(Expression::class, STARLASU_METAMODEL.getEClass("Expression"))
val EntityDeclarationHandler = KolasuClassHandler(
EntityDeclaration::class,
STARLASU_METAMODEL
.getEClass("EntityDeclaration")
)
val PlaceholderElementHandler = KolasuClassHandler(
PlaceholderElement::class,
STARLASU_METAMODEL
.getEClass("PlaceholderElement")
)
val StatementHandler = KolasuClassHandler.forKClass(Statement::class)
val ExpressionHandler = KolasuClassHandler.forKClass(Expression::class)
val EntityDeclarationHandler = KolasuClassHandler.forKClass(EntityDeclaration::class)
val EntityGroupDeclarationHandler = KolasuClassHandler.forKClass(EntityGroupDeclaration::class)
val TypeAnnotationHandler = KolasuClassHandler.forKClass(TypeAnnotation::class)
val PlaceholderElementHandler = KolasuClassHandler.forKClass(PlaceholderElement::class)
val BehaviorDeclarationHandler = KolasuClassHandler.forKClass(BehaviorDeclaration::class)
val ParameterHandler = KolasuClassHandler.forKClass(Parameter::class)
val DocumentationHandler = KolasuClassHandler.forKClass(Documentation::class)

val ErrorNodeHandler = KolasuClassHandler(ErrorNode::class, STARLASU_METAMODEL.getEClass("ErrorNode"))
val GenericErrorNodeHandler = KolasuClassHandler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ class MetamodelBuilder(
eclassTypeHandlers.add(StatementHandler)
eclassTypeHandlers.add(ExpressionHandler)
eclassTypeHandlers.add(EntityDeclarationHandler)
eclassTypeHandlers.add(EntityGroupDeclarationHandler)
eclassTypeHandlers.add(TypeAnnotationHandler)
eclassTypeHandlers.add(BehaviorDeclarationHandler)
eclassTypeHandlers.add(ParameterHandler)
eclassTypeHandlers.add(DocumentationHandler)
eclassTypeHandlers.add(PlaceholderElementHandler)

eclassTypeHandlers.add(ErrorNodeHandler)
Expand Down
20 changes: 20 additions & 0 deletions emf/src/test/kotlin/com/strumenta/kolasu/emf/cli/EMFCLIToolTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,26 @@ class EMFCLIToolTest {
"eClass" : "http://www.eclipse.org/emf/2002/Ecore#//EClass",
"name" : "EntityDeclaration",
"interface" : true
}, {
"eClass" : "http://www.eclipse.org/emf/2002/Ecore#//EClass",
"name" : "EntityGroupDeclaration",
"interface" : true
}, {
"eClass" : "http://www.eclipse.org/emf/2002/Ecore#//EClass",
"name" : "TypeAnnotation",
"interface" : true
}, {
"eClass" : "http://www.eclipse.org/emf/2002/Ecore#//EClass",
"name" : "BehaviorDeclaration",
"interface" : true
}, {
"eClass" : "http://www.eclipse.org/emf/2002/Ecore#//EClass",
"name" : "Parameter",
"interface" : true
}, {
"eClass" : "http://www.eclipse.org/emf/2002/Ecore#//EClass",
"name" : "Documentation",
"interface" : true
}, {
"eClass" : "http://www.eclipse.org/emf/2002/Ecore#//EClass",
"name" : "PlaceholderElement",
Expand Down

0 comments on commit bdd76b3

Please sign in to comment.