Skip to content
Snippets Groups Projects
Commit 1010fa5c authored by Chrissi's avatar Chrissi
Browse files

error removing and shrinking example finish

parent 869ffc00
No related branches found
No related tags found
No related merge requests found
natural join shrinking.Class with shrinking.Class as shrinking.Class {
keep supertype shrinking.Classifier as type shrinking.Classifier {
keep attributes shrinking.Classifier.name
}
keep outgoing shrinking.StructuredClassifier.part as type shrinking.Property {
keep attributes shrinking.ConnectableElement.name
}
keep outgoing shrinking.StructuredClassifier.role as type shrinking.Property {
keep attributes shrinking.ConnectableElement.name
}
keep outgoing shrinking.StructuredClassifier.ownedAttribute as type shrinking.Property {
}
}
<?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="ShrinkingExample" nsURI="http://www.example.org/shrinking" nsPrefix="shr">
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="shrinking" nsURI="http://www.example.org/shrinking" nsPrefix="shr">
<eClassifiers xsi:type="ecore:EClass" name="Classifier" abstract="true">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
......
......@@ -14,6 +14,7 @@ class ModelJoinViewGeneratingVisitor(joinExpression: ModelJoinExpression) extend
var refRelationalClasses: Seq[SClass] = Seq.empty
var newInternalRoles: Seq[SInnerViewNaturalClass] = Seq.empty
var newInternalRelationalRoles: Seq[SInnerViewRelationalClass] = Seq.empty
var allImportClasses: Set[STypedElement] = Set.empty
override def visit(sModel: SModel): Unit = {
println("#################################################################")
......@@ -23,6 +24,7 @@ class ModelJoinViewGeneratingVisitor(joinExpression: ModelJoinExpression) extend
refRelationalClasses = Seq.empty
newInternalRoles = Seq.empty
newInternalRelationalRoles = Seq.empty
allImportClasses = Set.empty
viewCompartment = new SClass(joinExpression.getName() + counter, "view")
counter += 1
viewCompartment.addParent(PredefRsumTypes.IVIEW_COMPARTMENT_STYPE)
......@@ -56,44 +58,6 @@ class ModelJoinViewGeneratingVisitor(joinExpression: ModelJoinExpression) extend
})
})
//Iterate over all Relational compartments and create relational internal role classes
/*sModel.getRelationalCompartments.foreach(r => {
var sourceAtt: SAttribute = null
var targetAtt: SAttribute = null
//set as attributes the other classes
var sourceRole: SInnerViewNaturalClass = null
var targetRole: SInnerViewNaturalClass = null
r.getAttributes.foreach(attr => {
newInternalRoles.foreach(inte => {
if (inte.getName == attr.getTypeElement.getName + "Role") {
if (attr.getName == "sInstance") {
sourceRole = inte
sourceAtt = new SAttribute("source", inte)
sourceAtt.isFinal = true
sourceAtt.setVisibility(MethodVisibility.privateVis)
} else {
targetRole = inte
targetAtt = new SAttribute("target", inte)
targetAtt.isFinal = true
targetAtt.setVisibility(MethodVisibility.privateVis)
}
}
})
})
val internalClass = new SInnerViewRelationalClass(r.getName + "Role", _externalClass = viewCompartment,
sumSource = r.asInstanceOf[SRelationalCompartmentClass], viewSource = sourceRole, viewTarget = targetRole)
internalClass.setAttributes(sourceAtt ++ targetAtt)
internalClass.addMethod(ViewMethods.getIsRelationalMethod(true))
internalClass.addMethod(ViewMethods.getCreationObjectMethod(internalClass))
internalClass.addMethod(ViewMethods.getDeleteElementRelationMethod(internalClass))
internalClass.addMethod(ToStringMethods.onlyStringToStringMethod("VRR: " + internalClass.getName))
ViewMethods.getSourceAndTargetGetter(internalClass).foreach(internalClass.addMethod(_))
internalClass.addParent(PredefRsumTypes.AVIEW_ROLE_STYPE)
createAllReferenceLinks(internalClass)
newInternalRelationalRoles = newInternalRelationalRoles :+ internalClass
viewCompartment.addInternalClass(internalClass)
})*/
//add methods that must be override from the view trait
viewCompartment.addMethod(ViewMethods.getIsViewableMethod((refClasses ++ refRelationalClasses).toSet))
viewCompartment.addMethod(ViewMethods.getViewNameMethod(viewCompartment))
......@@ -103,6 +67,9 @@ class ModelJoinViewGeneratingVisitor(joinExpression: ModelJoinExpression) extend
//Create methods to create elements from the view
ViewMethods.getCreateNaturalRoleMethods(newInternalRoles.toSet).foreach(viewCompartment.addMethod(_))
println("Alllllllllllll: " + allImportClasses)
viewCompartment.augmentConstructor(new SMethodStatement("", allImportClasses))
//add the view to the list for generating views
sModel.addViewCompartment(viewCompartment)
})
......@@ -110,16 +77,30 @@ class ModelJoinViewGeneratingVisitor(joinExpression: ModelJoinExpression) extend
}
def createClasses(keeps: Set[KeepExpression], cls: SClass, sModel: SModel): SInnerViewNaturalClass = {
var internalClass: SInnerViewNaturalClass = null
var newAtts: Seq[SAttribute] = Seq.empty
if (refClasses.contains(cls)) {
newInternalRoles.foreach(nir => {
if (nir.sumSource == cls) {
internalClass = nir
newAtts = nir.getAttributes()
}
})
} else {
refClasses = refClasses :+ cls
val internalClass = new SInnerViewNaturalClass(cls.getName + "Role",
internalClass = new SInnerViewNaturalClass(cls.getName + "Role",
_isAbstract = cls.isAbstract,
_isInterface = cls.isInterface,
_externalClass = viewCompartment,
sumSource = cls)
newInternalRoles = newInternalRoles :+ internalClass
allImportClasses = allImportClasses + cls
viewCompartment.addInternalClass(internalClass)
}
//without keep lists
//KeepAggregateExpression KeepAttributesExpression KeepCalculatedExpression
//sets the attributes from the source class
var newAtts: Set[SAttribute] = Set.empty
var features: Set[SStructuralFeature] = Set.empty
if (cls.isInstanceOf[SJoinClass]) {
val jCls = cls.asInstanceOf[SJoinClass]
......@@ -130,7 +111,7 @@ class ModelJoinViewGeneratingVisitor(joinExpression: ModelJoinExpression) extend
var newAtt = SAttribute(a.getName, a.getTypeElement)
newAtt.setVisibility(MethodVisibility.protectedVis)
newAtt.isFinal = true
newAtts += newAtt
newAtts = newAtts :+ newAtt
})
}
} else {
......@@ -143,17 +124,24 @@ class ModelJoinViewGeneratingVisitor(joinExpression: ModelJoinExpression) extend
println("#### " + keepAtt)
keepAtt.getAttributes.forEach(attExp => {
println("N: " + attExp.getAttributeName + " P: " + attExp.getContainingClass.getPackage + " CN: " + attExp.getContainingClass.getClassName)
features.foreach(a => {
features.filter(_.getName == attExp.getAttributeName).foreach(a => {
var isIn = false
internalClass.getAttributes().foreach(ain => {
if (ain.getName == a.getName && ain.getTypeElement.getName == a.getTypeElement.getName) {
isIn = true
}
})
if (!isIn) {
//Proof if attribute must be in then add it to view class
if (a.getName == attExp.getAttributeName) {
var newAtt = SAttribute(a.getName, a.getTypeElement)
newAtt.setVisibility(MethodVisibility.protectedVis)
newAtt.isFinal = true
newAtts += newAtt
newAtts = newAtts :+ newAtt
}
})
})
})
internalClass.setAttributes(newAtts)
println("+++ KeepAggregateExpression")
keeps.filter(_.isInstanceOf[KeepAggregateExpression]).foreach(ja => {
//TODO: later
......@@ -200,10 +188,26 @@ class ModelJoinViewGeneratingVisitor(joinExpression: ModelJoinExpression) extend
var sourceAtt: SAttribute = null
var targetAtt: SAttribute = null
if (rc.sClass.getName == keepAtt.getAttribute.getContainingClass.getClassName) {
//current is source
sourceRole = internalClass
targetRole = createClasses(asScalaBuffer(keepAtt.getKeeps).toSet, rc.tClass.asInstanceOf[SClass], sModel)
var tClass = rc.tClass.asInstanceOf[SClass]
sModel.getModelClasses.filter(m => m.getName == keepAtt.getTarget.getClassName && m.getPackage == keepAtt.getTarget.getPackage).foreach(cs => {
val parent = cs.getRootClassWithNameAndPackage(rc.tClass.getName, rc.tClass.getPackage)
if (parent != null) {
tClass = cs
}
})
targetRole = createClasses(asScalaBuffer(keepAtt.getKeeps).toSet, tClass, sModel)
} else {
sourceRole = createClasses(asScalaBuffer(keepAtt.getKeeps).toSet, rc.sClass.asInstanceOf[SClass], sModel)
//current is target
var sClass = rc.sClass.asInstanceOf[SClass]
sModel.getModelClasses.filter(m => m.getName == keepAtt.getTarget.getClassName && m.getPackage == keepAtt.getTarget.getPackage).foreach(cs => {
val parent = cs.getRootClassWithNameAndPackage(rc.sClass.getName, rc.sClass.getPackage)
if (parent != null) {
sClass = cs
}
})
sourceRole = createClasses(asScalaBuffer(keepAtt.getKeeps).toSet, sClass, sModel)
targetRole = internalClass
}
sourceAtt = new SAttribute("source", sourceRole)
......@@ -226,6 +230,7 @@ class ModelJoinViewGeneratingVisitor(joinExpression: ModelJoinExpression) extend
internalRelClass.addParent(PredefRsumTypes.AVIEW_ROLE_STYPE)
createAllReferenceLinks(internalRelClass)
newInternalRelationalRoles = newInternalRelationalRoles :+ internalRelClass
allImportClasses = allImportClasses + sourceRole.sumSource + targetRole.sumSource + rc.tClass + rc.sClass
viewCompartment.addInternalClass(internalRelClass)
}
}
......@@ -233,9 +238,6 @@ class ModelJoinViewGeneratingVisitor(joinExpression: ModelJoinExpression) extend
})
})
println("#######################" + internalClass + " Ps: " + internalClass.getAllParents())
internalClass.setAttributes(newAtts.toSeq)
newInternalRoles = newInternalRoles :+ internalClass
viewCompartment.addInternalClass(internalClass)
internalClass
}
......
......@@ -8,8 +8,8 @@ import org.rosi_project.model_sync.generator.Creation
object ApplicationTest extends App {
runCombinedTest(Creation.rsum)
//runTestAML(Creation.rsum)
//runTestLibrary(Creation.rsum)
//runShrinkingModel(Creation.rsum)
//runAllTests(Creation.rsum)
//runAllTests(Creation.rsync)
......@@ -36,6 +36,12 @@ object ApplicationTest extends App {
println("#####################################################################################")
}
def runShrinkingModel(cre: Creation.Value): Unit = {
var config: GeneratorConfig = GeneratorConfig(Seq("assets/models/ShrinkingModel.ecore"), false, new File("assets/models"), modelJoin = "assets/model_join/shrinking.modeljoin");
config.setCreate(cre)
new Generator(config).run()
}
def runCombinedTest(cre: Creation.Value): Unit = {
var config: GeneratorConfig = GeneratorConfig(Seq("assets/models/IMDBDatabase.ecore", "assets/models/ModelJoinLibrary.ecore"), false, new File("assets/models"), modelJoin = "assets/model_join/complex.modeljoin");
config.setCreate(cre)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment