Skip to content
Snippets Groups Projects
Commit 869ffc00 authored by Chrissi's avatar Chrissi
Browse files

functionality for super and sub type expressions

parent 252063b0
Branches
No related tags found
No related merge requests found
natural join imdbdatabase.Film with eclipselibrary.VideoCassette as joins.JoinMovie {
keep attributes imdbdatabase.Film.year
keep attributes eclipselibrary.AudioVisualItem.minutesLength
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 {
......
......@@ -6,7 +6,8 @@ import org.rosi_project.model_sync.generator.acr_model.types.GenericSequence
import org.rosi_project.model_sync.generator.acr_model.types.PredefTypes
import org.rosi_project.model_sync.generator.sync.ToStringMethods
/** Representation of Scala classes. Attributes, methods, etc. have their own wrappers which should
/**
* Representation of Scala classes. Attributes, methods, etc. have their own wrappers which should
* be used to modify these individual parts of the class.
*
* @see [[SType]]
......@@ -77,7 +78,8 @@ class SClass(_name: String,
}
}
/** Augments `this` class with another method.
/**
* Augments `this` class with another method.
*
* @param m the additional method. May not be `null`
*/
......@@ -89,8 +91,10 @@ class SClass(_name: String,
methods = methods :+ m
}
/** Gets the methods of `this` class.
* And adds a to String if not exists. */
/**
* Gets the methods of `this` class.
* And adds a to String if not exists.
*/
def getMethods: Seq[SMethod] = {
if (methods.exists(_.getName == "toString")) {
methods
......@@ -113,7 +117,8 @@ class SClass(_name: String,
parentInterfaces :+ parentClass
}
/** Adds a internal class to `this` class.
/**
* Adds a internal class to `this` class.
*
* If `parent == this or null` nothing will happen.
*/
......@@ -127,7 +132,8 @@ class SClass(_name: String,
internalClasses = internalClasses :+ internal
}
/** Makes `this` class a subclass of `parent`.
/**
* Makes `this` class a subclass of `parent`.
*
* If `parent == this` nothing will happen.
*
......@@ -153,7 +159,8 @@ class SClass(_name: String,
/** Gets the references of `this` class. */
def getReferences(): Seq[SReference] = references
/** Sets the references of `this` class.
/**
* Sets the references of `this` class.
*
* @param refs the references. May be `null` to remove all current references.
*/
......@@ -168,7 +175,8 @@ class SClass(_name: String,
/** Gets the attributes of `this` class. */
def getAttributes(): Seq[SAttribute] = attributes
/** Sets the attributes of `this` class.
/**
* Sets the attributes of `this` class.
*
* @param attrs the attributes. May be `null` to remove all current attributes.
*/
......@@ -183,18 +191,34 @@ class SClass(_name: String,
/** Provides code that should be executed when invoking the constructor. */
def getAdditionalConstructorStatements: Seq[SMethodStatement] = constructorStatements
/** Checks, whether `this` extends any other classes. If this is the case, it is '''not'''
/**
* Checks, whether `this` extends any other classes. If this is the case, it is '''not'''
* considered a ''root class'', otherwise it is.
* Interfaces are not checked.
*/
def isRootClass: Boolean = parentClass == null
/** Provides the set of all symbols that have to be imported in order to use `this` complete
def getRootClassWithNameAndPackage(n: String, p: String): SClass = {
var parent = this
while (!parent.isRootClass) {
if (parent.getClassParent.isInstanceOf[SClass]) {
parent = parent.getClassParent.asInstanceOf[SClass]
if (parent.getName == n && parent.getPackage == p) {
return parent
}
}
}
return null
}
/**
* Provides the set of all symbols that have to be imported in order to use `this` complete
* class.
*/
def collectImports: Set[String] = getNecessaryImports.map(imp => s"${imp.pckg}.${imp.name}")
/** Augments the constructor by another statement. The statement will be executed lastly (though
/**
* Augments the constructor by another statement. The statement will be executed lastly (though
* this may change due to further modifications of the constructor).
*
* @param statement the new statement. May not be `null`
......@@ -326,7 +350,8 @@ class SClass(_name: String,
protected def canEqual(other: Any): Boolean = other.isInstanceOf[SClass]
/** Checks if some class has to be imported in order to be usable from `this` class. If this
/**
* Checks if some class has to be imported in order to be usable from `this` class. If this
* is the case it will wrap the necessary import in a `List` for further usage.
*
* @param sPackage the package of the class
......
......@@ -12,4 +12,13 @@ class SJoinClass(_name: String,
val joinAttributes: Set[SStructuralFeature],
val innerAttributes: Set[SStructuralFeature]) extends SClass(_name, _sPackage, _isAbstract, _isInterface) {
override def getRootClassWithNameAndPackage(n: String, p: String): SClass = {
val bparent = base.getRootClassWithNameAndPackage(n, p)
val oparent = other.getRootClassWithNameAndPackage(n, p)
if (bparent != null) {
return bparent
}
oparent
}
}
\ No newline at end of file
......@@ -36,9 +36,8 @@ class ModelJoinViewGeneratingVisitor(joinExpression: ModelJoinExpression) extend
//Now fill all natural internal roles with functionality
newInternalRoles.foreach(inner => {
val cls = inner.sumSource
//set inheritance to abstract view role
if (cls.isRootClass) {
if (inner.isRootClass) {
inner.addParent(PredefRsumTypes.AVIEW_ROLE_STYPE)
}
//add initialize method if necessary
......@@ -50,13 +49,6 @@ class ModelJoinViewGeneratingVisitor(joinExpression: ModelJoinExpression) extend
inner.addMethod(ToStringMethods.onlyStringToStringMethod("VNR: " + inner.getName))
//add delete method
inner.addMethod(ViewMethods.getDeleteElementNaturalMethod(inner))
//add parents TODO: make this in the create function because of subtypes and suptypes
cls.getAllParents().foreach(p => {
val existing: Option[STypedElement] = newInternalRoles.find(existing => existing.getName == p.getName + "Role")
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))
......@@ -174,11 +166,24 @@ class ModelJoinViewGeneratingVisitor(joinExpression: ModelJoinExpression) extend
//with keep lists
//KeepSubTypeExpression KeepSuperTypeExpression KeepReferenceExpression (List of Keeps)
keeps.filter(_.isInstanceOf[KeepSubTypeExpression]).foreach(ja => {
//TODO: later
val keepAtt = ja.asInstanceOf[KeepSubTypeExpression]
sModel.getModelClasses.filter(m => m.getName == keepAtt.getType.getClassName && m.getPackage == keepAtt.getType.getPackage).foreach(mc => {
val parent = mc.getRootClassWithNameAndPackage(cls.getName, cls.getPackage)
if (parent != null) {
val innerParent = createClasses(asScalaBuffer(keepAtt.getKeeps).toSet, mc, sModel)
innerParent.addParent(internalClass)
}
})
})
println("+++ KeepSuperTypeExpression")
keeps.filter(_.isInstanceOf[KeepSuperTypeExpression]).foreach(ja => {
//TODO: later
val keepAtt = ja.asInstanceOf[KeepSuperTypeExpression]
println("TC: " + keepAtt.getTarget + " TC: " + keepAtt.getType)
val parent = cls.getRootClassWithNameAndPackage(keepAtt.getType.getClassName, keepAtt.getType.getPackage)
if (parent != null) {
val innerParent = createClasses(asScalaBuffer(keepAtt.getKeeps).toSet, parent, sModel)
internalClass.addParent(innerParent)
}
})
println("+++ KeepReferenceExpression")
keeps.filter(_.isInstanceOf[KeepReferenceExpression]).foreach(ja => {
......@@ -227,6 +232,7 @@ class ModelJoinViewGeneratingVisitor(joinExpression: ModelJoinExpression) extend
}
})
})
println("#######################" + internalClass + " Ps: " + internalClass.getAllParents())
internalClass.setAttributes(newAtts.toSeq)
newInternalRoles = newInternalRoles :+ internalClass
viewCompartment.addInternalClass(internalClass)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment