Commit 84e3926e authored by Rakshit Mittal's avatar Rakshit Mittal
Browse files

added library support for mode transition instance deinstantiation

parent 939607aa
......@@ -11,9 +11,16 @@ import org.osate.aadl2.ComponentCategory
import org.osate.aadl2.ModelUnit
import org.osate.aadl2.ComponentClassifier
import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.viatra.transformation.runtime.emf.modelmanipulation.IModelManipulations
class DIMTransformationRulesMode extends DIMTransformationRules {
new(IModelManipulations manipulation) {
this.manipulation = manipulation
}
extension IModelManipulations manipulation
protected def modeInstanceCreatedDIM (ModeInstance modeinst) {
val compinst = modeinst.eContainer as ComponentInstance
// Parent Component Classifier Selection
......@@ -109,7 +116,6 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
compclasscopy.set(namedElement_Name,currentcompclass.name+"_dimcopy")
if(extensionList.indexOf(currentcompclass) == 0) {
var newMode = LibraryUtils.getCopyMode(modeinst.mode,compclasscopy)
modeinst.set(modeInstance_Mode, newMode)
} else {
if (compclasscopy instanceof ComponentType) {
......@@ -147,6 +153,56 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
setSubcomponentType(compinst, compinst.classifier)
}
def void modeTransChangedParentSubcomponentDefinition(ModeTransitionInstance modetransinst) {
var compinst = modetransinst.eContainer as ComponentInstance
var extensionList = LibraryUtils.getAllInheritingParentImplementations(modetransinst.modeTransition, compinst)
var extensionIndex = LibraryUtils.getClosestLibraryImplementationIndex(extensionList, aadlPublicPackage)
if (extensionIndex !== -1) {
var ComponentClassifier previousClass
for (ComponentClassifier currentcompclass : extensionList.reverse) {
if (extensionList.indexOf(currentcompclass) < extensionList.size - extensionIndex) {
var compclasscopy = EcoreUtil.copy(currentcompclass)
aadlPublicPackage.add(packageSection_OwnedClassifier, compclasscopy)
compclasscopy.set(namedElement_Name,currentcompclass.name+"_dimcopy")
if(extensionList.indexOf(currentcompclass) == 0) {
var newModeTrans = LibraryUtils.getCopyModeTransition(modetransinst.modeTransition,compclasscopy)
modetransinst.set(modeTransitionInstance_ModeTransition, newModeTrans)
} else {
if (compclasscopy instanceof ComponentType) {
compclasscopy.set(componentType_Extended, previousClass)
} else {
compclasscopy.set(componentImplementation_Extended, previousClass)
}
}
previousClass = compclasscopy
} else {
if (compinst == topSystemInst || !LibraryUtils.isSubcomponentAffectingLibrary(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage)) {
if (extensionList.indexOf(currentcompclass) == extensionList.size - extensionIndex) {
if (currentcompclass instanceof ComponentType) {
currentcompclass.set(componentType_Extended, previousClass)
} else {
currentcompclass.set(componentImplementation_Extended, previousClass)
}
}
} else {
var compclasscopy = EcoreUtil.copy(currentcompclass)
aadlPublicPackage.add(packageSection_OwnedClassifier, compclasscopy)
compclasscopy.set(namedElement_Name,currentcompclass.name+"_dimcopy")
compclasscopy.set(componentImplementation_Extended, previousClass)
previousClass = compclasscopy
if (extensionList.indexOf(currentcompclass) === extensionList.size - 1) {
compinst.set(componentInstance_Classifier, compclasscopy)
changeParentSubcomponentDefinition(compinst, compinst.eContainer as ComponentInstance)
}
}
}
}
} else if (compinst != topSystemInst && LibraryUtils.isSubcomponentAffectingLibrary(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage)) {
changeParentSubcomponentDefinition(compinst, compinst.eContainer as ComponentInstance)
}
setSubcomponentType(compinst, compinst.classifier)
}
protected def modeTransitionInstanceCreatedDIM (ModeTransitionInstance modetransinst) {
var compinst = modetransinst.eContainer as ComponentInstance
// Parent Component Classifier Selection
......@@ -206,16 +262,16 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
}
}
// Mode Transition Creation
var modetransadd = {
if (compinst.classifier instanceof ComponentType) {
compinst.classifier.createChild(componentClassifier_OwnedModeTransition, modeTransition)
} else {
(compinst.classifier as ComponentImplementation).type.createChild(componentClassifier_OwnedModeTransition, modeTransition)
}
var modetransadd = compinst.classifier.createChild(componentClassifier_OwnedModeTransition, modeTransition)
if (modetransinst.name !== null) {
modetransadd.set(namedElement_Name, modetransinst.name)
}
if (modetransinst.source !== null) {
modetransadd.set(modeTransition_Source, (modetransinst.source as ModeInstance).mode)
}
if (modetransinst.destination !== null) {
modetransadd.set(modeTransition_Destination, (modetransinst.destination as ModeInstance).mode)
}
modetransadd.set(modeTransition_Source, (modetransinst.source as ModeInstance).mode)
modetransadd.set(modeTransition_Destination, (modetransinst.destination as ModeInstance).mode)
modetransadd.set(namedElement_Name, modetransinst.name)
// Mode Transition Trigger Creation
for (FeatureInstance trigger : modetransinst.triggers) {
var modetrigadd = modetransadd.createChild(modeTransition_OwnedTrigger, modeTransitionTrigger)
......
......@@ -9,6 +9,7 @@ import org.osate.aadl2.ComponentType;
import org.osate.aadl2.Connection;
import org.osate.aadl2.Feature;
import org.osate.aadl2.Mode;
import org.osate.aadl2.ModeTransition;
import org.osate.aadl2.NamedElement;
import org.osate.aadl2.PackageSection;
import org.osate.aadl2.Subcomponent;
......@@ -126,6 +127,15 @@ public class LibraryUtils {
return null;
}
public static ModeTransition getCopyModeTransition(ModeTransition oldModeTrans, ComponentClassifier newClass) {
for (ModeTransition modeTrans : newClass.getAllModeTransitions()) {
if (modeTrans.getName() == oldModeTrans.getName()) {
return modeTrans;
}
}
return null;
}
public static boolean isSubcomponentAffectingLibrary(Subcomponent childSubcomp, ComponentInstance parentInst, PackageSection aadlPackageSection) {
if (getClosestLibraryImplementationIndex(getAllInheritingParentImplementations(childSubcomp,parentInst),aadlPackageSection) == -1) {
if (parentInst.eContainer() != aadlPackageSection) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment