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

Update for ttc live contest

+ todo remove interface and abstract change
+ todo set ttclive2019 value in SClassWriter the other way
parent fc43ea88
No related branches found
No related tags found
No related merge requests found
Showing
with 89 additions and 148 deletions
<?xml version="1.0" encoding="ASCII"?>
<tt:TruthTable xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tt="https://www.transformation-tool-contest.eu/2019/tt" name="TableI4O2Seed42">
<ports xsi:type="tt:InputPort" name="I0" cells="//@rows.0/@cells.0 //@rows.1/@cells.0 //@rows.2/@cells.0 //@rows.3/@cells.0 //@rows.4/@cells.0 //@rows.5/@cells.0 //@rows.6/@cells.0 //@rows.7/@cells.0 //@rows.8/@cells.0 //@rows.9/@cells.0 //@rows.10/@cells.0 //@rows.11/@cells.0 //@rows.12/@cells.0 //@rows.13/@cells.0 //@rows.14/@cells.0 //@rows.15/@cells.0"/>
<ports xsi:type="tt:InputPort" name="I1" cells="//@rows.0/@cells.1 //@rows.1/@cells.1 //@rows.2/@cells.1 //@rows.3/@cells.1 //@rows.4/@cells.1 //@rows.5/@cells.1 //@rows.6/@cells.1 //@rows.7/@cells.1 //@rows.8/@cells.1 //@rows.9/@cells.1 //@rows.10/@cells.1 //@rows.11/@cells.1 //@rows.12/@cells.1 //@rows.13/@cells.1 //@rows.14/@cells.1 //@rows.15/@cells.1"/>
<ports xsi:type="tt:InputPort" name="I2" cells="//@rows.0/@cells.2 //@rows.1/@cells.2 //@rows.2/@cells.2 //@rows.3/@cells.2 //@rows.4/@cells.2 //@rows.5/@cells.2 //@rows.6/@cells.2 //@rows.7/@cells.2 //@rows.8/@cells.2 //@rows.9/@cells.2 //@rows.10/@cells.2 //@rows.11/@cells.2 //@rows.12/@cells.2 //@rows.13/@cells.2 //@rows.14/@cells.2 //@rows.15/@cells.2"/>
<ports xsi:type="tt:InputPort" name="I3" cells="//@rows.0/@cells.3 //@rows.1/@cells.3 //@rows.2/@cells.3 //@rows.3/@cells.3 //@rows.4/@cells.3 //@rows.5/@cells.3 //@rows.6/@cells.3 //@rows.7/@cells.3 //@rows.8/@cells.3 //@rows.9/@cells.3 //@rows.10/@cells.3 //@rows.11/@cells.3 //@rows.12/@cells.3 //@rows.13/@cells.3 //@rows.14/@cells.3 //@rows.15/@cells.3"/>
<ports xsi:type="tt:OutputPort" name="O0" cells="//@rows.0/@cells.4 //@rows.1/@cells.4 //@rows.2/@cells.4 //@rows.3/@cells.4 //@rows.4/@cells.4 //@rows.5/@cells.4 //@rows.6/@cells.4 //@rows.7/@cells.4 //@rows.8/@cells.4 //@rows.9/@cells.4 //@rows.10/@cells.4 //@rows.11/@cells.4 //@rows.12/@cells.4 //@rows.13/@cells.4 //@rows.14/@cells.4 //@rows.15/@cells.4"/>
<ports xsi:type="tt:OutputPort" name="O1" cells="//@rows.0/@cells.5 //@rows.1/@cells.5 //@rows.2/@cells.5 //@rows.3/@cells.5 //@rows.4/@cells.5 //@rows.5/@cells.5 //@rows.6/@cells.5 //@rows.7/@cells.5 //@rows.8/@cells.5 //@rows.9/@cells.5 //@rows.10/@cells.5 //@rows.11/@cells.5 //@rows.12/@cells.5 //@rows.13/@cells.5 //@rows.14/@cells.5 //@rows.15/@cells.5"/>
<rows>
<cells port="//@ports.0"/>
<cells port="//@ports.1"/>
<cells port="//@ports.2"/>
<cells port="//@ports.3"/>
<cells value="true" port="//@ports.4"/>
<cells port="//@ports.5"/>
</rows>
<rows>
<cells value="true" port="//@ports.0"/>
<cells port="//@ports.1"/>
<cells port="//@ports.2"/>
<cells port="//@ports.3"/>
<cells value="true" port="//@ports.4"/>
<cells port="//@ports.5"/>
</rows>
<rows>
<cells port="//@ports.0"/>
<cells value="true" port="//@ports.1"/>
<cells port="//@ports.2"/>
<cells port="//@ports.3"/>
<cells port="//@ports.4"/>
<cells value="true" port="//@ports.5"/>
</rows>
<rows>
<cells value="true" port="//@ports.0"/>
<cells value="true" port="//@ports.1"/>
<cells port="//@ports.2"/>
<cells port="//@ports.3"/>
<cells port="//@ports.4"/>
<cells value="true" port="//@ports.5"/>
</rows>
<rows>
<cells port="//@ports.0"/>
<cells port="//@ports.1"/>
<cells value="true" port="//@ports.2"/>
<cells port="//@ports.3"/>
<cells value="true" port="//@ports.4"/>
<cells port="//@ports.5"/>
</rows>
<rows>
<cells value="true" port="//@ports.0"/>
<cells port="//@ports.1"/>
<cells value="true" port="//@ports.2"/>
<cells port="//@ports.3"/>
<cells value="true" port="//@ports.4"/>
<cells port="//@ports.5"/>
</rows>
<rows>
<cells port="//@ports.0"/>
<cells value="true" port="//@ports.1"/>
<cells value="true" port="//@ports.2"/>
<cells port="//@ports.3"/>
<cells port="//@ports.4"/>
<cells port="//@ports.5"/>
</rows>
<rows>
<cells value="true" port="//@ports.0"/>
<cells value="true" port="//@ports.1"/>
<cells value="true" port="//@ports.2"/>
<cells port="//@ports.3"/>
<cells port="//@ports.4"/>
<cells value="true" port="//@ports.5"/>
</rows>
<rows>
<cells port="//@ports.0"/>
<cells port="//@ports.1"/>
<cells port="//@ports.2"/>
<cells value="true" port="//@ports.3"/>
<cells port="//@ports.4"/>
<cells value="true" port="//@ports.5"/>
</rows>
<rows>
<cells value="true" port="//@ports.0"/>
<cells port="//@ports.1"/>
<cells port="//@ports.2"/>
<cells value="true" port="//@ports.3"/>
<cells value="true" port="//@ports.4"/>
<cells value="true" port="//@ports.5"/>
</rows>
<rows>
<cells port="//@ports.0"/>
<cells value="true" port="//@ports.1"/>
<cells port="//@ports.2"/>
<cells value="true" port="//@ports.3"/>
<cells value="true" port="//@ports.4"/>
<cells port="//@ports.5"/>
</rows>
<rows>
<cells value="true" port="//@ports.0"/>
<cells value="true" port="//@ports.1"/>
<cells port="//@ports.2"/>
<cells value="true" port="//@ports.3"/>
<cells port="//@ports.4"/>
<cells port="//@ports.5"/>
</rows>
<rows>
<cells port="//@ports.0"/>
<cells port="//@ports.1"/>
<cells value="true" port="//@ports.2"/>
<cells value="true" port="//@ports.3"/>
<cells value="true" port="//@ports.4"/>
<cells value="true" port="//@ports.5"/>
</rows>
<rows>
<cells value="true" port="//@ports.0"/>
<cells port="//@ports.1"/>
<cells value="true" port="//@ports.2"/>
<cells value="true" port="//@ports.3"/>
<cells port="//@ports.4"/>
<cells value="true" port="//@ports.5"/>
</rows>
<rows>
<cells port="//@ports.0"/>
<cells value="true" port="//@ports.1"/>
<cells value="true" port="//@ports.2"/>
<cells value="true" port="//@ports.3"/>
<cells port="//@ports.4"/>
<cells port="//@ports.5"/>
</rows>
<rows>
<cells value="true" port="//@ports.0"/>
<cells value="true" port="//@ports.1"/>
<cells value="true" port="//@ports.2"/>
<cells value="true" port="//@ports.3"/>
<cells value="true" port="//@ports.4"/>
<cells port="//@ports.5"/>
</rows>
</tt:TruthTable>
......@@ -212,6 +212,8 @@ class SClass(_name: String,
*/
def isRootClass: Boolean = parentClass == null
def isAbsoluteRootClassOrInterface: Boolean = parentClass == null && parentInterfaces.isEmpty
def getRootClassWithNameAndPackage(n: String, p: String): SClass = {
var parent = this
while (!parent.isRootClass) {
......
......@@ -2,6 +2,7 @@ package org.rosi_project.model_sync.generator.acr_model
import org.rosi_project.model_sync.generator.acr_model.types.PredefTypes
import org.eclipse.emf.ecore.EClass
import org.rosi_project.model_sync.generator.acr_model.types.PredefEcoreTypes
/** Repository to keep track of all types and classes of model. It ensures that all attributes,
* methods, etc. reference the same type instances and thus prevent duplication and conflicting
......@@ -30,6 +31,11 @@ object STypeRegistry {
PredefTypes.Short -> null,
)
/*private val ecoreTypes: Map[STypedElement, EClass] = Map(
PredefEcoreTypes.EcoreObject -> null,
PredefEcoreTypes.EcoreStructuralFeature -> null,
)*/
def getFromClass(cls: EClass): STypedElement = {
registeredTypes.foreach(r => {
if (r._2 == cls) {
......@@ -41,6 +47,7 @@ object STypeRegistry {
registeredTypes ++= defaultTypesNull
registeredTypes ++= defaultTypesNotNull
//registeredTypes ++= ecoreTypes
/**
* Return true if this name comes from a standard null type.
......
package org.rosi_project.model_sync.generator.acr_model.types
import org.rosi_project.model_sync.generator.acr_model.SType
/** Contains a number of types that are part of the Ecore package.
*
* This should prevent creating them over and over again every time a `SType` should be set to any
* of these types.
*
* @author Christopher Werner
*/
object PredefEcoreTypes {
/** `org.eclipse.emf.ecore.EObject` */
val EcoreObject = SType("EObject", "org.eclipse.emf.ecore")
/** `org.eclipse.emf.ecore.EStructuralFeature` */
val EcoreStructuralFeature = SType("EStructuralFeature", "org.eclipse.emf.ecore")
/** `org.eclipse.emf.ecore.EOperation` */
val EcoreOperation = SType("EOperation", "org.eclipse.emf.ecore")
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import java.util.Objects
import org.eclipse.emf.ecore.EDataType
import org.rosi_project.model_sync.generator.acr_model.SType
import org.rosi_project.model_sync.generator.acr_model.types.PredefTypes
import org.rosi_project.model_sync.generator.acr_model.types.PredefEcoreTypes
/** Service to map an instance of [[EDataType]] to its corresponding [[SType]] (which wrap Scala's
* native types).
......@@ -25,6 +26,9 @@ object EmfTypeTranslator {
"ELong" -> PredefTypes.Long,
"EShort" -> PredefTypes.Short,
"EString" -> PredefTypes.String,
"EObject" -> PredefTypes.Object,
"EStructuralFeature" -> PredefEcoreTypes.EcoreStructuralFeature,
"EOperation" -> PredefEcoreTypes.EcoreOperation,
)
/** Maps an EMF data type to its corresponding Scala type.
......
......@@ -19,6 +19,7 @@ class SClassConverter extends Converter[EClass, SClass] {
// fetch the attributes of the SClass
(source.getEAttributes: List[EAttribute]).foreach(eAttr => {
//println("Attribute: " + eAttr.getEAttributeType.getName + " pkg: " + eAttr.getEAttributeType.getEPackage.getNsPrefix + " pre: " + PackageNames.sourcePkgPrefix)
val attrType: STypedElement = STypeRegistry
// check if the attribute type is already known and registered
.query(eAttr.getEAttributeType.getName, PackageNames.sourcePkgPrefix + eAttr.getEAttributeType.getEPackage.getNsPrefix)
......@@ -51,6 +52,8 @@ class SClassConverter extends Converter[EClass, SClass] {
var newTypeCreated: Boolean = false
//println("Referenz: " + refType + " pkg: " + refTypePckg)
var sRefType: STypedElement = STypeRegistry
// check if the attribute type is already known and registered
.query(refType, refTypePckg)
......
......@@ -23,7 +23,8 @@ 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.isAbstract, ec.isInterface), ec)
STypeRegistry.addType(new SClass(ec.getName, PackageNames.sourcePkgPrefix + ec.getEPackage.getNsPrefix, ec.isInterface, ec.isAbstract), ec)
case ee: EEnum =>
//prinltn(ee)
model.addModelEnums(new SEnumConverter convert (ee, sourceName))
......
......@@ -3,6 +3,8 @@ package org.rosi_project.model_sync.generator.io
import org.rosi_project.model_sync.generator.acr_model._
import org.rosi_project.model_sync.generator.support.ExtendedString.stringToExtended
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
/** The `Writer` generates the source code of a [[SClass]] and provides it as a `String`.
*
......@@ -10,6 +12,8 @@ import org.rosi_project.model_sync.generator.sync.PredefRsumTypes
*/
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
......@@ -31,6 +35,8 @@ class SClassWriter(val modelClass: SClass, val isView: Boolean, val isObject: Bo
|
|${clazzFixture} {
|
| ${if (ttcLive2019) s"${generateAttributeFixture}" else ""}
|
| ${modelClass.getAdditionalConstructorStatements.map(_.getContent).mkString("\n")}
|
| ${modelClass.getMethods.map(stringifyMethod).mkString("\n")}
......@@ -109,6 +115,17 @@ class SClassWriter(val modelClass: SClass, val isView: Boolean, val isObject: Bo
visibility
}
/**
* Generate the attribute fixtures to add them in the body.
*/
protected def generateAttributeFixture: String = {
modelClass.getStructuralFeatures.map(attr => {
val finalS: String = if(attr.isFinal) "val" else "var"
val instanziationS: String = if(attr.getTypeElement.isInstanceOf[GenericSequence]) "= Set.empty" else s"= ${HelperFunctions.classEmptyType(attr.getTypeElement.getName)}"
s"${getVisibilityString(attr.getVisibility)}${finalS} ${attr.getName}: ${attr.getTypeElement.getDeepName} ${instanziationS} \n"
}).mkString(" \n")
}
/** Writes the "''class fixture''", i.e. the `class` identifier followed by the constructor and
* optionally a parent class. The parent constructor will be called correctly.
*/
......@@ -144,11 +161,12 @@ class SClassWriter(val modelClass: SClass, val isView: Boolean, val isObject: Bo
} else if (isObject) {
baseFixture = s"object ${modelClass.getName}"
} else {
baseFixture = s"${modelClass.getName}$constructor"
baseFixture = s"class ${modelClass.getName}"
if (!ttcLive2019) {
baseFixture = s"$baseFixture$constructor"
}
if (modelClass.isAbstract) {
baseFixture = s"abstract class $baseFixture"
} else {
baseFixture = s"class $baseFixture"
baseFixture = s"abstract $baseFixture"
}
}
......@@ -160,8 +178,12 @@ class SClassWriter(val modelClass: SClass, val isView: Boolean, val isObject: Bo
baseFixture = s"$baseFixture extends $allInterfaces"
}
}
} else {
if (ttcLive2019) {
baseFixture = s"$baseFixture extends ${parent.getName}"
} else {
baseFixture = s"$baseFixture extends ${parent.getName}$parentConstructor"
}
if (allInterfaces != "") {
baseFixture = s"$baseFixture with $allInterfaces"
}
......
......@@ -22,7 +22,8 @@ class SyncEnhancingVisitor() extends SModelVisitor {
override def visit(sClass: SClass): Unit = {
//TODO: do not have in mind trait extends abstract extends trait hierarchy
if (sClass.isRootClass && !sClass.isInterface && !sClass.isInstanceOf[SRelationalCompartmentClass]) {
if (sClass.isAbsoluteRootClassOrInterface && !sClass.isInstanceOf[SRelationalCompartmentClass]) {
//if (sClass.isRootClass && !sClass.isInterface && !sClass.isInstanceOf[SRelationalCompartmentClass]) {
sClass.addParent(PredefSyncTypes.PLAYER_SYNC_STYPE)
}
}
......
......@@ -11,7 +11,11 @@ object ApplicationTest extends App {
//runShrinkingModel(Creation.rsum)
//runTTC2019(Creation.rolecomb)
runTTC2019(Creation.rolesync)
//runTTC2019(Creation.rolesync)
//runTTCLive2019Part(Creation.rolesync)
runTTCLive2019(Creation.rolesync)
//runTTC2019(Creation.rolesync)
//runAllTests(Creation.rsum)
......@@ -39,6 +43,18 @@ 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)
new Generator(config).run()
}
def runTTC2019(cre: Creation.Value): Unit = {
var config: GeneratorConfig = GeneratorConfig(Seq("assets/models/BDD.ecore", "assets/models/BDDv2.ecore", "assets/models/TT.ecore"), false, new File("assets/models"));
config.setCreate(cre)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment