Skip to content
Snippets Groups Projects
Commit 21e4a7d2 authored by Chrissi's avatar Chrissi
Browse files

hinzufügen des erzeugen und hinzufügen von EMF modellen

parent a3c4ffd3
Branches
No related tags found
No related merge requests found
......@@ -75,6 +75,9 @@ class Generator(config: GeneratorConfig) {
new SModelSUMCorePreparationService prepareModel (sm._1)
//add sync stuff
new SModelOnlySyncService prepareModel (sm._1)
//create the EMF Ecore reading models
new SModelSUMReadEMFService prepareModel (sm._1)
//instance generation for combi means rsum
if (sm._2.obj != null) {
new SModelCombiInstanceService prepareModel(sm._1, sm._2)
......
......@@ -4,7 +4,7 @@ object PackageNames {
val multiInhertitanceWithTraits = false
val sourcePkgPrefix: String = ""
val sourcePkgPrefix: String = "sum."
val viewPkgName: String = "view"
val viewPostName: String = "View"
......@@ -19,4 +19,6 @@ object PackageNames {
val examplePkgName: String = "example"
val creationPkgName: String = "creation"
}
\ No newline at end of file
package org.rosi_project.model_sync.generator
import org.rosi_project.model_sync.generator.sync.SumModelReadingVisitor
import org.rosi_project.model_sync.generator.acr_model.SModel
/** Simple service to create the new emf ecore model instances.
*
* @author Christopher Werner
*/
class SModelSUMReadEMFService {
/** Add classes to read emf and ecore models.
*
* @param sModel the model to augment
*/
def prepareModel(sModel: SModel): Unit = {
val sumModelReadingVisitor = new SumModelReadingVisitor
sModel.accept(sumModelReadingVisitor)
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import org.rosi_project.model_sync.generator.acr_model._
import org.rosi_project.model_sync.model_join.representation.grammar.ModelJoinExpression
import org.rosi_project.model_management.sum.join.RsumJoinType
import org.rosi_project.model_sync.model_join.representation.grammar.JoinExpression.JoinType
import org.rosi_project.model_sync.model_join.representation.grammar.ThetaJoinExpression
class JoinGeneratingVisitor(joinExpression: ModelJoinExpression) extends SModelVisitor {
......@@ -30,12 +31,16 @@ class JoinGeneratingVisitor(joinExpression: ModelJoinExpression) extends SModelV
val baseClass = baseType.get.asInstanceOf[SClass]
val otherClass = otherType.get.asInstanceOf[SClass]
var rsumJoinType = RsumJoinType.natural
var compareString: String = null
j.getType match {
case JoinType.NATURAL => rsumJoinType = RsumJoinType.natural
case JoinType.OUTER => rsumJoinType = RsumJoinType.outer
case JoinType.THETA => rsumJoinType = RsumJoinType.theta
case JoinType.THETA =>
rsumJoinType = RsumJoinType.theta
compareString = j.asInstanceOf[ThetaJoinExpression].getCondition.get
}
var otherAttsBase: Set[SStructuralFeature] = Set.empty
......@@ -86,7 +91,7 @@ class JoinGeneratingVisitor(joinExpression: ModelJoinExpression) extends SModelV
joinObject.addMethod(JoinMethods.getInstanceOtherModelMethod(otherClass))
joinObject.addMethod(JoinMethods.getNewInstanceMethod(joinClass))
joinObject.addMethod(JoinMethods.getInstanceOfMethod(joinClass))
joinObject.addMethod(JoinMethods.getMatchMethod(baseClass, otherClass, joinAtts)) //TODO: for theta join
joinObject.addMethod(JoinMethods.getMatchMethod(baseClass, otherClass, joinAtts, compareString))
joinObject.addMethod(ToStringMethods.onlyStringToStringMethod(joinObject.getName))
//add functions to the join class
......
......@@ -60,19 +60,22 @@ object JoinMethods {
SMethodStatement(content = "j", usedTypes = Set())))
}
def getMatchMethod(base: SClass, other: SClass, joinAtts: Set[SStructuralFeature]): SMethod = {
def getMatchMethod(base: SClass, other: SClass, joinAtts: Set[SStructuralFeature], joinString: String): SMethod = {
val met = new SMethod(
name = "matchTwoObjects",
result = PredefTypes.Boolean,
params = Seq(SMethodParameter("b", PredefTypes.Object), SMethodParameter("o", PredefTypes.Object)),
implementation = Seq())
met.implementation = Seq(SMethodStatement(content = s"val base = b.asInstanceOf[${base.getName}]", usedTypes = Set(base)),
SMethodStatement(content = s"val other = o.asInstanceOf[${other.getName}]", usedTypes = Set(other)),
SMethodStatement(content = s"${joinAtts.map(HelperFunctions.attributeEqualCreation(_)).mkString(" && ")}", usedTypes = Set()))
SMethodStatement(content = s"val other = o.asInstanceOf[${other.getName}]", usedTypes = Set(other)))
if (joinString == null) {
met.implementation = met.implementation :+ SMethodStatement(content = s"${joinAtts.map(HelperFunctions.attributeEqualCreation(_)).mkString(" && ")}")
} else {
met.implementation = met.implementation :+ SMethodStatement(content = joinString)
}
met
}
//JOIN CLASS METHODS
def getJoinInfoMethod(obj: SClass): SMethod = {
new SMethod(
......
......@@ -18,7 +18,7 @@ object QueryMethods {
name = s"create${nr.sumSource.getName}",
result = nr,
params = Seq.empty,
implementation = Seq(SMethodStatement(content = s"return new ${nr.getName}()", usedTypes = Set.empty)))
implementation = Seq(SMethodStatement(content = s"return new ${nr.getName}()")))
methods = methods :+ method
}
})
......
package org.rosi_project.model_sync.generator.sync
import org.rosi_project.model_sync.generator.acr_model._
import org.rosi_project.model_sync.generator.PackageNames
import org.rosi_project.model_sync.generator.acr_model.types.PredefEcoreTypes
import org.rosi_project.model_sync.generator.acr_model.types.PredefTypes
/**
* Read EMF and Ecore models.
*
* @author Christopher Werner
*/
class SumModelReadingVisitor() extends SModelVisitor {
override def visit(sModel: SModel): Unit = {
//println("++++++++++++++++++++++++++++++++++++++++++++++")
val example = new SClass("Creation" + sModel.getName, PackageNames.creationPkgName)
example.augmentConstructor(SMethodStatement(content = s"var mapping: Map[EObject, Object] = Map.empty", usedTypes = Set(PredefEcoreTypes.EcoreObject)))
sModel.getAllClasses.filter(c => !c.isAbstract && !c.isInterface).foreach(c => {
val metod = new SMethod(
name = s"create${c.getName}",
result = PredefTypes.Unit,
params = c.getAllConstructorParameters :+ SMethodParameter("id", PredefEcoreTypes.EcoreObject),
implementation = Seq(
SMethodStatement(content = s"mapping += (id -> new ${c.getName}(name, Set.empty, Set.empty, null))", usedTypes = Set.empty)))
})
sModel.getRelationalCompartments.foreach(r => {
var rc = r.asInstanceOf[SRelationalCompartmentClass]
val metod = new SMethod(
name = s"create${r.getName}",
result = PredefTypes.Unit,
params = Seq(SMethodParameter("s", PredefEcoreTypes.EcoreObject), SMethodParameter("t", PredefEcoreTypes.EcoreObject)),
implementation = Seq(
SMethodStatement(content = s"val s1 = mapping.get(s).get.asInstanceOf[${rc.sClass.getName}]"),
SMethodStatement(content = s"val t1 = mapping.get(t).get.asInstanceOf[${rc.tClass.getName}]"),
SMethodStatement(content = s"(new ${rc.getName}(s1, t1)).initialize()")))
})
//add values for instances
/*lines.foreach(l => {
l.usedType.getAllConstructorParameters.foreach(cp => {
if (!STypeRegistry.isDefaultType(cp.getType.getName)) {
val structs: Seq[EStructuralFeature] = l.obj.eClass().getEAllStructuralFeatures.asScala
structs.foreach(att => {
if (att.getName == cp.getName) {
val obj = l.obj.eGet(att)
if (obj.isInstanceOf[EObject]) {
lines.foreach(lnow => {
if (lnow.obj == obj.asInstanceOf[EObject]) {
//println("Found: " + lnow.counter) .filter(_.isInstanceOf[SRelationalCompartmentClass])
sModel.getRelationalCompartments.foreach(rc => {
val realRc = rc.asInstanceOf[SRelationalCompartmentClass]
//println(" AN: " + att.getName + " l1: " + l.usedType.getName + " l2: " + lnow.usedType.getName + " RC: " + realRc.connectedRef.getName + " SN: " + realRc.sClass.getName + " TN: " + realRc.tClass.getName)
if (realRc.connectedRef.getName == att.getName && l.usedType.proofHierarchicalEquality(realRc.sClass) && lnow.usedType.proofHierarchicalEquality(realRc.tClass)) {
val s = s"(new ${realRc.getName}(${l.getName()}, ${lnow.getName()})).initialize()"
generationLines = generationLines :+ new InstanceLine(0, null, realRc, s)
}
})
}
})
} else {
val listi: List[EObject] = EMFUtilForGenerator.getList(obj)
val liste = listi.asScala
liste.foreach(eo => {
lines.foreach(lnow => {
if (lnow.obj == eo) {
sModel.getRelationalCompartments.foreach(rc => {
val realRc = rc.asInstanceOf[SRelationalCompartmentClass]
//println(" AN: " + att.getName + " l1: " + l.usedType.getName + " l2: " + lnow.usedType.getName + " RC: " + realRc.connectedRef.getName + " SN: " + realRc.sClass.getName + " TN: " + realRc.tClass.getName)
if (realRc.connectedRef.getName == att.getName && l.usedType.proofHierarchicalEquality(realRc.sClass) && lnow.usedType.proofHierarchicalEquality(realRc.tClass)) {
val s = s"(new ${realRc.getName}(${l.getName()}, ${lnow.getName()})).initialize()"
generationLines = generationLines :+ new InstanceLine(0, null, realRc, s)
}
})
}
})
})
}
}
})
}
})
})*/
sModel.addModelClass(example)
// pass
}
override def visit(sClass: SClass): Unit = {
// pass
}
override def visit(sAttr: SAttribute): Unit = {
// pass
}
override def visit(sRef: SReference): Unit = {
// pass
}
override def visit(sMethod: SMethod): Unit = {
// pass
}
override def visit(sType: SType): Unit = {
// pass
}
}
\ No newline at end of file
......@@ -8,13 +8,13 @@ import org.rosi_project.model_sync.generator.Creation
object ApplicationTest extends App {
//runTestLibrary(Creation.rolesum)
runCombinedTest(Creation.rolecomb)
//runCombinedTest(Creation.rolecomb)
//runShrinkingModel(Creation.rolesum)
//runTestAML(Creation.rolesum)
//TTC Case examples
//runTTC2019(Creation.rolecomb)
//runTTC2019(Creation.rolesync)
runTTC2019(Creation.rolesync)
//runTTCLive2019(Creation.rolesync)
//Run all tests
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment