From 8a197bbca1a68d07dc84d29251d44433455c2615 Mon Sep 17 00:00:00 2001 From: Chrissi <christopher@hbsc-werner.de> Date: Mon, 29 Jul 2019 16:23:42 +0200 Subject: [PATCH] remove parent set error in view generation and split ttc case in config object --- assets/model_join/complex.modeljoin | 10 ++++----- assets/models/AML.ecore | 2 +- assets/models/IMDBDatabase.ecore | 2 +- assets/models/ModelJoinLibrary.ecore | 2 +- .../model_sync/generator/PackageNames.scala | 4 +++- .../generator/acr_model/SClass.scala | 1 + .../conversion/SModelGenerator.scala | 8 ++++--- .../generator/io/SClassWriter.scala | 14 ++++++------- .../sync/ViewGeneratingVisitor.scala | 16 +++++++------- .../generator/test/ApplicationTest.scala | 21 +++++++------------ 10 files changed, 38 insertions(+), 42 deletions(-) diff --git a/assets/model_join/complex.modeljoin b/assets/model_join/complex.modeljoin index 3adb368..610f077 100644 --- a/assets/model_join/complex.modeljoin +++ b/assets/model_join/complex.modeljoin @@ -1,16 +1,16 @@ -natural join imdbdatabase.Film with eclipselibrary.VideoCassette as joins.JoinMovie { +natural join imdbdatabase.Film with elib.VideoCassette as joins.JoinMovie { keep attributes imdbdatabase.Film.year keep aggregate avg(score) over Film.votes as Movie.averageRating keep calculated attribute imdbdatabase.Film.votes->select(v|v.score==10)->size() as Movie.topratings:EInt - keep supertype eclipselibrary.AudioVisualItem as type jointarget.MediaItem { - keep attributes library.AudioVisualItem.minutesLength + keep supertype elib.AudioVisualItem as type jointarget.MediaItem { + keep attributes elib.AudioVisualItem.minutesLength } keep outgoing imdbdatabase.Film.votes as type jointarget.Vote { keep attributes imdbdatabase.Vote.score } - keep outgoing eclipselibrary.VideoCassette.cast as type jointarget.Person { - keep attributes eclipselibrary.Person.lastName + keep outgoing elib.VideoCassette.cast as type jointarget.Person { + keep attributes elib.Person.lastName } } diff --git a/assets/models/AML.ecore b/assets/models/AML.ecore index db85f69..a073b44 100644 --- a/assets/models/AML.ecore +++ b/assets/models/AML.ecore @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="AMLLanguage" nsURI="http://www.example.org/aml" nsPrefix="org.rosi_project.example.mm.aml"> + xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="AMLLanguage" nsURI="http://www.example.org/aml" nsPrefix="aml"> <eClassifiers xsi:type="ecore:EClass" name="CAEXObject" abstract="true"> <eStructuralFeatures xsi:type="ecore:EAttribute" name="id" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> diff --git a/assets/models/IMDBDatabase.ecore b/assets/models/IMDBDatabase.ecore index 9c09d12..b5f9b26 100644 --- a/assets/models/IMDBDatabase.ecore +++ b/assets/models/IMDBDatabase.ecore @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="IMDBdatabase" nsURI="http://www.example.org/database" nsPrefix="org.rosi_project.example.mm.database"> + xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="IMDBdatabase" nsURI="http://www.example.org/database" nsPrefix="imdbdatabase"> <eClassifiers xsi:type="ecore:EClass" name="IMDB"> <eStructuralFeatures xsi:type="ecore:EReference" name="users" upperBound="-1" eType="#//User" containment="true" eOpposite="#//User/library"/> diff --git a/assets/models/ModelJoinLibrary.ecore b/assets/models/ModelJoinLibrary.ecore index d98f470..68671c4 100644 --- a/assets/models/ModelJoinLibrary.ecore +++ b/assets/models/ModelJoinLibrary.ecore @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="EclipseLibrary" nsURI="http://www.example.org/eclipselibrary" - nsPrefix="org.rosi_project.example.mm.elib"> + nsPrefix="elib"> <eClassifiers xsi:type="ecore:EClass" name="Item"> <eStructuralFeatures xsi:type="ecore:EAttribute" name="publicationDate" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EDate"/> </eClassifiers> diff --git a/src/main/scala/org/rosi_project/model_sync/generator/PackageNames.scala b/src/main/scala/org/rosi_project/model_sync/generator/PackageNames.scala index 52bdcdb..d174073 100644 --- a/src/main/scala/org/rosi_project/model_sync/generator/PackageNames.scala +++ b/src/main/scala/org/rosi_project/model_sync/generator/PackageNames.scala @@ -2,7 +2,9 @@ package org.rosi_project.model_sync.generator object PackageNames { - var sourcePkgPrefix: String = "sync." + val multiInhertitanceWithTraits = false + + val sourcePkgPrefix: String = "" val viewPkgName: String = "view" val viewPostName: String = "View" diff --git a/src/main/scala/org/rosi_project/model_sync/generator/acr_model/SClass.scala b/src/main/scala/org/rosi_project/model_sync/generator/acr_model/SClass.scala index fe08984..f6c872e 100644 --- a/src/main/scala/org/rosi_project/model_sync/generator/acr_model/SClass.scala +++ b/src/main/scala/org/rosi_project/model_sync/generator/acr_model/SClass.scala @@ -168,6 +168,7 @@ class SClass(_name: String, println("!!!Cannot add parent because their is one parent that is no interface!!!") } } + } /** Gets the references of `this` class. */ diff --git a/src/main/scala/org/rosi_project/model_sync/generator/conversion/SModelGenerator.scala b/src/main/scala/org/rosi_project/model_sync/generator/conversion/SModelGenerator.scala index 5b41f9f..48794b5 100644 --- a/src/main/scala/org/rosi_project/model_sync/generator/conversion/SModelGenerator.scala +++ b/src/main/scala/org/rosi_project/model_sync/generator/conversion/SModelGenerator.scala @@ -23,10 +23,12 @@ class SModelGenerator extends Converter[EPackage, SModel] { println("First run creates all classes, important for abstract and interface relations") contents.foreach { case ec: EClass => - //STypeRegistry.addType(new SClass(ec.getName, PackageNames.sourcePkgPrefix + ec.getEPackage.getNsPrefix, ec.isAbstract, ec.isInterface), ec) - STypeRegistry.addType(new SClass(ec.getName, PackageNames.sourcePkgPrefix + ec.getEPackage.getNsPrefix, ec.isInterface, ec.isAbstract), ec) + if (PackageNames.multiInhertitanceWithTraits) { + STypeRegistry.addType(new SClass(ec.getName, PackageNames.sourcePkgPrefix + ec.getEPackage.getNsPrefix, ec.isInterface, ec.isAbstract), ec) + } else { + STypeRegistry.addType(new SClass(ec.getName, PackageNames.sourcePkgPrefix + ec.getEPackage.getNsPrefix, ec.isAbstract, ec.isInterface), ec) + } case ee: EEnum => - //prinltn(ee) model.addModelEnums(new SEnumConverter convert (ee, sourceName)) case _ => // we only care about classes. Types will be registered as soon as they are needed as diff --git a/src/main/scala/org/rosi_project/model_sync/generator/io/SClassWriter.scala b/src/main/scala/org/rosi_project/model_sync/generator/io/SClassWriter.scala index f82e0bb..541facb 100644 --- a/src/main/scala/org/rosi_project/model_sync/generator/io/SClassWriter.scala +++ b/src/main/scala/org/rosi_project/model_sync/generator/io/SClassWriter.scala @@ -5,14 +5,13 @@ import org.rosi_project.model_sync.generator.support.ExtendedString.stringToExte import org.rosi_project.model_sync.generator.sync.PredefRsumTypes import org.rosi_project.model_sync.generator.acr_model.types.GenericSequence import org.rosi_project.model_sync.generator.sync.HelperFunctions +import org.rosi_project.model_sync.generator.PackageNames /** The `Writer` generates the source code of a [[SClass]] and provides it as a `String`. * * @author Rico Bergmann */ class SClassWriter(val modelClass: SClass, val isView: Boolean, val isObject: Boolean) { - - private val ttcLive2019 = true private val pckg: String = if (modelClass.isDefaultPackage) "" else s"package ${modelClass.sPackage}" private val imports: Seq[String] = modelClass.collectImports.toSeq @@ -35,7 +34,7 @@ class SClassWriter(val modelClass: SClass, val isView: Boolean, val isObject: Bo | |${clazzFixture} { | - | ${if (ttcLive2019) s"${generateAttributeFixture}" else ""} + | ${if (PackageNames.multiInhertitanceWithTraits) s"${generateAttributeFixture}" else ""} | | ${modelClass.getAdditionalConstructorStatements.map(_.getContent).mkString("\n")} | @@ -162,7 +161,7 @@ class SClassWriter(val modelClass: SClass, val isView: Boolean, val isObject: Bo baseFixture = s"object ${modelClass.getName}" } else { baseFixture = s"class ${modelClass.getName}" - if (!ttcLive2019) { + if (!PackageNames.multiInhertitanceWithTraits) { baseFixture = s"$baseFixture$constructor" } if (modelClass.isAbstract) { @@ -179,10 +178,9 @@ class SClassWriter(val modelClass: SClass, val isView: Boolean, val isObject: Bo } } } else { - if (ttcLive2019) { - baseFixture = s"$baseFixture extends ${parent.getName}" - } else { - baseFixture = s"$baseFixture extends ${parent.getName}$parentConstructor" + baseFixture = s"$baseFixture extends ${parent.getName}" + if (!PackageNames.multiInhertitanceWithTraits) { + baseFixture = s"${baseFixture}${parentConstructor}" } if (allInterfaces != "") { baseFixture = s"$baseFixture with $allInterfaces" diff --git a/src/main/scala/org/rosi_project/model_sync/generator/sync/ViewGeneratingVisitor.scala b/src/main/scala/org/rosi_project/model_sync/generator/sync/ViewGeneratingVisitor.scala index 2611fa7..1e8bc55 100644 --- a/src/main/scala/org/rosi_project/model_sync/generator/sync/ViewGeneratingVisitor.scala +++ b/src/main/scala/org/rosi_project/model_sync/generator/sync/ViewGeneratingVisitor.scala @@ -40,21 +40,21 @@ class ViewGeneratingVisitor extends SModelVisitor { if (cls.isRootClass) { inner.addParent(PredefRsumTypes.AVIEW_ROLE_STYPE) } + //add parents + cls.getAllParents().foreach(p => { + val existing: Option[STypedElement] = newInternalRoles.find(existing => existing.getName == p.getName + PackageNames.viewRolePostName) + if (!existing.isEmpty) { + inner.addParent(existing.get) + } + }) //add initialize method if necessary if (!inner.isAbstract && !inner.isInterface) { inner.addMethod(ViewMethods.getIsRelationalMethod(false)) inner.addMethod(ViewMethods.getCreationObjectMethod(inner)) - } + } //add delete method inner.addMethod(ToStringMethods.onlyStringToStringMethod("VNR: " + inner.getName)) inner.addMethod(ViewMethods.getDeleteElementNaturalMethod(inner)) - //add parents - cls.getAllParents().foreach(p => { - val existing: Option[STypedElement] = newInternalRoles.find(existing => existing.getName == p.getName + PackageNames.viewRolePostName) - if (!existing.isEmpty) { - inner.addParent(existing.get) - } - }) //add getter and setter for attributes in the inner class inner.getAttributes.foreach(attr => { inner.addMethod(ViewMethods.getViewAttributeGetter(attr)) diff --git a/src/main/scala/org/rosi_project/model_sync/generator/test/ApplicationTest.scala b/src/main/scala/org/rosi_project/model_sync/generator/test/ApplicationTest.scala index a28abfb..9bf0ba1 100644 --- a/src/main/scala/org/rosi_project/model_sync/generator/test/ApplicationTest.scala +++ b/src/main/scala/org/rosi_project/model_sync/generator/test/ApplicationTest.scala @@ -7,17 +7,16 @@ import org.rosi_project.model_sync.generator.Creation object ApplicationTest extends App { - //runCombinedTest(Creation.rsum) - //runShrinkingModel(Creation.rsum) + runCombinedTest(Creation.rolesum) + //runShrinkingModel(Creation.rolesum) + //runTestAML(Creation.rolesum) + //TTC Case examples //runTTC2019(Creation.rolecomb) - //runTTC2019(Creation.rolesync) - - //runTTCLive2019Part(Creation.rolesync) - runTTCLive2019(Creation.rolesync) - //runTTC2019(Creation.rolesync) + //runTTC2019(Creation.rolesync) + //runTTCLive2019(Creation.rolesync) - + //Run all tests //runAllTests(Creation.rsum) //runAllTests(Creation.rsync) @@ -43,12 +42,6 @@ object ApplicationTest extends App { println("#####################################################################################") } - def runTTCLive2019Part(cre: Creation.Value): Unit = { - var config: GeneratorConfig = GeneratorConfig(Seq("assets/models/BibTeX.ecore"), false, new File("assets/models")); - config.setCreate(cre) - new Generator(config).run() - } - def runTTCLive2019(cre: Creation.Value): Unit = { var config: GeneratorConfig = GeneratorConfig(Seq("assets/models/BibTeX.ecore", "assets/models/DocBook.ecore", "assets/models/NMetaChanges.ecore"), false, new File("assets/models")); config.setCreate(cre) -- GitLab