Commit 87f0cd65 authored by Rakshit Mittal's avatar Rakshit Mittal
Browse files

added support for reused classifier deinstantiation

parent 588044dc
......@@ -15,6 +15,7 @@ import org.osate.aadl2.PublicPackageSection
import org.osate.aadl2.instance.ComponentInstance
import org.osate.aadl2.instance.InstancePackage
import org.osate.aadl2.instance.SystemInstance
import org.eclipse.emf.common.util.EList
class DIMTransformationRules {
/* VIATRA Query Pattern group */
......@@ -40,14 +41,28 @@ class DIMTransformationRules {
}
protected def void changeParentSubcomponentDefinition(ComponentInstance compinst, ComponentInstance parentcompinst) {
var extensionList = LibraryUtils.getAllInheritingParentImplementations(compinst.subcomponent, parentcompinst)
var extensionIndex = LibraryUtils.getClosestLibraryImplementationIndex(extensionList, aadlPublicPackage)
var EList<? extends ComponentClassifier> extensionList = LibraryUtils.getAllInheritingParentImplementations(compinst.subcomponent, parentcompinst)
var libraryIndex = LibraryUtils.getClosestLibraryImplementationIndex(extensionList, aadlPublicPackage)
var reusedIndex = LibraryUtils.getClosestReusedClassifierIndex(extensionList, engine)
var extensionIndex = {
if (preferences.modifyReused) {
libraryIndex
} else {
if (libraryIndex == -1) {
reusedIndex
} else if (reusedIndex == -1) {
libraryIndex
} else {
Math.min(reusedIndex, libraryIndex)
}
}
}
if (extensionIndex !== -1) {
var ComponentImplementation previousImp
for (ComponentImplementation currentcompimp : extensionList.reverse) {
for (ComponentClassifier currentcompimp : extensionList.reverse) {
if (extensionList.indexOf(currentcompimp) < extensionList.size - extensionIndex) {
var compimpcopy = EcoreUtil.copy(currentcompimp)
transformationUtils.classifierCreationPropertyAddition(compimpcopy)
var compimpcopy = EcoreUtil.copy(currentcompimp) as ComponentImplementation
transformationUtils.classifierCreationDIMPropertyAddition(compimpcopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, compimpcopy)
compimpcopy.set(namedElement_Name,currentcompimp.name+"_dimcopy")
if(extensionList.indexOf(currentcompimp) == 0) {
......@@ -58,13 +73,13 @@ class DIMTransformationRules {
}
previousImp = compimpcopy
} else {
if (parentcompinst == topSystemInst || !LibraryUtils.isSubcomponentAffectingLibrary(parentcompinst.subcomponent,parentcompinst.eContainer as ComponentInstance,aadlPublicPackage)) {
if (parentcompinst == topSystemInst || !LibraryUtils.isAffectingSubcomponent(parentcompinst.subcomponent,parentcompinst.eContainer as ComponentInstance,aadlPublicPackage, engine,preferences.modifyReused)) {
if (extensionList.indexOf(currentcompimp) == extensionList.size - extensionIndex) {
currentcompimp.set(componentImplementation_Extended, previousImp)
}
} else {
var compimpcopy = EcoreUtil.copy(currentcompimp)
transformationUtils.classifierCreationPropertyAddition(compimpcopy)
var compimpcopy = EcoreUtil.copy(currentcompimp) as ComponentImplementation
transformationUtils.classifierCreationDIMPropertyAddition(compimpcopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, compimpcopy)
compimpcopy.set(namedElement_Name,currentcompimp.name+"_dimcopy")
compimpcopy.set(componentImplementation_Extended, previousImp)
......@@ -78,16 +93,16 @@ class DIMTransformationRules {
}
} else {
var ComponentImplementation previousImp
for (ComponentImplementation currentcompimp : extensionList.reverse) {
var compimpcopy = EcoreUtil.copy(currentcompimp)
transformationUtils.classifierCreationPropertyAddition(compimpcopy)
for (ComponentClassifier currentcompimp : extensionList.reverse) {
var compimpcopy = EcoreUtil.copy(currentcompimp) as ComponentImplementation
transformationUtils.classifierCreationDIMPropertyAddition(compimpcopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, compimpcopy)
compimpcopy.set(namedElement_Name,currentcompimp.name+"_dimcopy")
compimpcopy.set(componentImplementation_Extended, previousImp)
previousImp = compimpcopy
previousImp = compimpcopy
if (extensionList.indexOf(currentcompimp) === extensionList.size - 1) {
parentcompinst.set(componentInstance_Classifier, compimpcopy)
if (parentcompinst != topSystemInst && LibraryUtils.isSubcomponentAffectingLibrary(parentcompinst.subcomponent,parentcompinst.eContainer as ComponentInstance,aadlPublicPackage)) {
if (parentcompinst != topSystemInst && LibraryUtils.isAffectingSubcomponent(parentcompinst.subcomponent,parentcompinst.eContainer as ComponentInstance, aadlPublicPackage, engine, preferences.modifyReused)) {
changeParentSubcomponentDefinition(parentcompinst, parentcompinst.eContainer as ComponentInstance)
}
}
......
......@@ -34,8 +34,9 @@ class DIMTransformationRulesComponent extends DIMTransformationRules {
def void componentInstanceCreatedDIM(ComponentInstance subcompinst) {
val compinst = subcompinst.eContainer as ComponentInstance
val classifier = compinst.classifier
// Parent Component Implementation Creation
if (compinst.classifier instanceof ComponentType || LibraryUtils.isLibraryClassifier(compinst.classifier, aadlPublicPackage)) {
if (classifier instanceof ComponentType || LibraryUtils.isLibraryClassifier(classifier, aadlPublicPackage) || (LibraryUtils.isReusedClassifier(classifier,engine) && !preferences.modifyReused)) {
var compimp = {
switch (compinst.category) {
case ComponentCategory.ABSTRACT : aadlPublicPackage.createChild(packageSection_OwnedClassifier,abstractImplementation)
......@@ -54,21 +55,21 @@ class DIMTransformationRulesComponent extends DIMTransformationRules {
case ComponentCategory.VIRTUAL_PROCESSOR : aadlPublicPackage.createChild(packageSection_OwnedClassifier,virtualProcessorImplementation)
}
} as ComponentImplementation
transformationUtils.classifierCreationPropertyAddition(compimp)
transformationUtils.classifierCreationDIMPropertyAddition(compimp)
compimp.set(namedElement_Name, compinst.name+".impl")
if (compinst.classifier instanceof ComponentType) {
compimp.set(componentImplementation_Type, compinst.classifier)
if (classifier instanceof ComponentType) {
compimp.set(componentImplementation_Type, classifier)
} else {
compimp.set(componentImplementation_Extended, compinst.classifier)
compimp.set(componentImplementation_Extended, classifier)
}
if (LibraryUtils.isLibraryClassifier(compinst.classifier, aadlPublicPackage)) {
aadlPublicPackage.add(packageSection_ImportedUnit, compinst.classifier.eContainer.eContainer as ModelUnit)
if (LibraryUtils.isLibraryClassifier(classifier, aadlPublicPackage)) {
aadlPublicPackage.add(packageSection_ImportedUnit, classifier.eContainer.eContainer as ModelUnit)
}
compinst.set(componentInstance_Classifier, compimp)
}
// Parent Component Instance Subcomponent Definition
if (compinst !== topSystemInst) {
if (LibraryUtils.isSubcomponentAffectingLibrary(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage)) {
if (LibraryUtils.isSubcomponentAffectingLibrary(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage) || (LibraryUtils.isSubcomponentAffectingReusedClassifier(compinst.subcomponent,compinst.eContainer as ComponentInstance,engine) && !preferences.isModifyReused)) {
changeParentSubcomponentDefinition(compinst, compinst.eContainer as ComponentInstance)
}
}
......@@ -103,7 +104,7 @@ class DIMTransformationRulesComponent extends DIMTransformationRules {
subcomptype.set(namedElement_Name,subcompinst.name)
}
if (subcompinst.classifier === null) {
transformationUtils.classifierCreationPropertyAddition(subcomptype as ComponentClassifier)
transformationUtils.classifierCreationDIMPropertyAddition(subcomptype as ComponentClassifier)
}
subcompinst.set(componentInstance_Classifier, subcomptype)
setSubcomponentType(subcompinst, subcomptype as ComponentClassifier)
......
......@@ -15,6 +15,8 @@ import fr.mem4csd.osatedim.viatra.utils.LibraryUtils
import org.osate.aadl2.ModelUnit
import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.viatra.transformation.runtime.emf.modelmanipulation.IModelManipulations
import org.eclipse.emf.common.util.EList
import org.osate.aadl2.ComponentClassifier
class DIMTransformationRulesConnection extends DIMTransformationRules {
......@@ -59,7 +61,7 @@ class DIMTransformationRulesConnection extends DIMTransformationRules {
}
// Parent Component Implementation Creation
if (currentcompinst !== topSystemInst) {
if (currentcompinst.classifier instanceof ComponentType || LibraryUtils.isLibraryClassifier(currentcompinst.classifier, aadlPublicPackage)) {
if (currentcompinst.classifier instanceof ComponentType || (LibraryUtils.isLibraryClassifier(currentcompinst.classifier, aadlPublicPackage) || (LibraryUtils.isReusedClassifier(currentcompinst.classifier,engine) && !preferences.modifyReused))) {
var compimp = {
switch (currentcompinst.category) {
case ComponentCategory.ABSTRACT : aadlPublicPackage.createChild(packageSection_OwnedClassifier,abstractImplementation)
......@@ -78,7 +80,7 @@ class DIMTransformationRulesConnection extends DIMTransformationRules {
case ComponentCategory.VIRTUAL_PROCESSOR : aadlPublicPackage.createChild(packageSection_OwnedClassifier,virtualProcessorImplementation)
}
} as ComponentImplementation
transformationUtils.classifierCreationPropertyAddition(compimp)
transformationUtils.classifierCreationDIMPropertyAddition(compimp)
compimp.set(namedElement_Name, currentcompinst.name+".impl")
if (currentcompinst.classifier instanceof ComponentType) {
compimp.set(componentImplementation_Type, currentcompinst.classifier)
......@@ -156,7 +158,7 @@ class DIMTransformationRulesConnection extends DIMTransformationRules {
case ComponentCategory.VIRTUAL_PROCESSOR : aadlPackage.createChild(packageSection_OwnedClassifier,virtualProcessorImplementation)
}
} as ComponentImplementation
transformationUtils.classifierCreationPropertyAddition(compimp)
transformationUtils.classifierCreationDIMPropertyAddition(compimp)
compimp.set(namedElement_Name, currentcompinst.classifier.name+".impl")
compimp.set(componentImplementation_Type,currentcompinst.classifier)
currentcompinst.set(componentInstance_Classifier, compimp)
......@@ -221,14 +223,28 @@ class DIMTransformationRulesConnection extends DIMTransformationRules {
protected def connectionDeletedParentSubcomponentDefinition(ConnectionReference connref) {
var compinst = connref.context as ComponentInstance
var extensionList = LibraryUtils.getAllInheritingParentImplementations(connref.connection, compinst)
var extensionIndex = LibraryUtils.getClosestLibraryImplementationIndex(extensionList, aadlPublicPackage)
var EList<? extends ComponentClassifier> extensionList = LibraryUtils.getAllInheritingParentImplementations(connref.connection, compinst)
var libraryIndex = LibraryUtils.getClosestLibraryImplementationIndex(extensionList, aadlPublicPackage)
var reusedIndex = LibraryUtils.getClosestReusedClassifierIndex(extensionList, engine)
var extensionIndex = {
if (preferences.modifyReused) {
libraryIndex
} else {
if (libraryIndex == -1) {
reusedIndex
} else if (reusedIndex == -1) {
libraryIndex
} else {
Math.min(reusedIndex, libraryIndex)
}
}
}
if (extensionIndex != -1) {
var ComponentImplementation previousImp
for (ComponentImplementation currentcompimp : extensionList.reverse) {
for (ComponentClassifier currentcompimp : extensionList.reverse) {
if (extensionList.indexOf(currentcompimp) < extensionList.size - extensionIndex) {
var compimpcopy = EcoreUtil.copy(currentcompimp)
transformationUtils.classifierCreationPropertyAddition(compimpcopy)
var compimpcopy = EcoreUtil.copy(currentcompimp) as ComponentImplementation
transformationUtils.classifierCreationDIMPropertyAddition(compimpcopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, compimpcopy)
compimpcopy.set(namedElement_Name,currentcompimp.name+"_dimcopy")
if(extensionList.indexOf(currentcompimp) == 0) {
......@@ -239,13 +255,13 @@ class DIMTransformationRulesConnection extends DIMTransformationRules {
}
previousImp = compimpcopy
} else {
if (compinst == topSystemInst || !LibraryUtils.isSubcomponentAffectingLibrary(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage)) {
if (compinst == topSystemInst || !LibraryUtils.isAffectingSubcomponent(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage, engine, preferences.modifyReused)) {
if (extensionList.indexOf(currentcompimp) == extensionList.size - extensionIndex) {
currentcompimp.set(componentImplementation_Extended, previousImp)
}
} else {
var compimpcopy = EcoreUtil.copy(currentcompimp)
transformationUtils.classifierCreationPropertyAddition(compimpcopy)
var compimpcopy = EcoreUtil.copy(currentcompimp) as ComponentImplementation
transformationUtils.classifierCreationDIMPropertyAddition(compimpcopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, compimpcopy)
compimpcopy.set(namedElement_Name,currentcompimp.name+"_dimcopy")
compimpcopy.set(componentImplementation_Extended, previousImp)
......@@ -257,7 +273,7 @@ class DIMTransformationRulesConnection extends DIMTransformationRules {
}
}
}
} else if (compinst != topSystemInst && LibraryUtils.isSubcomponentAffectingLibrary(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage)) {
} else if (compinst != topSystemInst && LibraryUtils.isAffectingSubcomponent(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage, engine, preferences.modifyReused)) {
changeParentSubcomponentDefinition(compinst, compinst.eContainer as ComponentInstance)
}
setSubcomponentType(compinst,compinst.classifier)
......
......@@ -37,7 +37,7 @@ class DIMTransformationRulesExtension extends DIMTransformationRules {
}
}
protected def classifierCreationPropertyAddition(ComponentClassifier compclass) {
protected def classifierCreationDIMPropertyAddition(ComponentClassifier compclass) {
if (preferences.isAddClassifierProperty) {
var propadd = compclass.createChild(namedElement_OwnedPropertyAssociation, propertyAssociation)
propadd.set(propertyAssociation_Property, dimResource.ownedProperties.get(2))
......
......@@ -26,6 +26,8 @@ import org.osate.aadl2.instance.FeatureCategory
import org.osate.aadl2.instance.FeatureInstance
import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.viatra.transformation.runtime.emf.modelmanipulation.IModelManipulations
import org.osate.aadl2.ComponentClassifier
import org.eclipse.emf.common.util.EList
class DIMTransformationRulesFeature extends DIMTransformationRules {
......@@ -41,7 +43,7 @@ class DIMTransformationRulesFeature extends DIMTransformationRules {
// Parent Component Classifier Creation
if (compinst.classifier instanceof ComponentImplementation) {
comptype = (compinst.classifier as ComponentImplementation).type
if (LibraryUtils.isLibraryClassifier(compinst.classifier, aadlPublicPackage)) {
if (LibraryUtils.isLibraryClassifier(compinst.classifier, aadlPublicPackage) || (LibraryUtils.isReusedClassifier(compinst.classifier,engine) && !preferences.modifyReused)) {
var compimp = {
switch (compinst.category) {
case ComponentCategory.ABSTRACT : aadlPublicPackage.createChild(packageSection_OwnedClassifier,abstractImplementation)
......@@ -60,7 +62,7 @@ class DIMTransformationRulesFeature extends DIMTransformationRules {
case ComponentCategory.VIRTUAL_PROCESSOR : aadlPublicPackage.createChild(packageSection_OwnedClassifier,virtualProcessorImplementation)
}
} as ComponentImplementation
transformationUtils.classifierCreationPropertyAddition(compimp)
transformationUtils.classifierCreationDIMPropertyAddition(compimp)
compimp.set(namedElement_Name, compinst.name+".impl")
compimp.set(componentImplementation_Type, comptype)
aadlPublicPackage.add(packageSection_ImportedUnit, compinst.classifier.eContainer.eContainer as ModelUnit)
......@@ -69,7 +71,7 @@ class DIMTransformationRulesFeature extends DIMTransformationRules {
} else {
comptype = compinst.classifier as ComponentType
}
if (LibraryUtils.isLibraryClassifier(comptype,aadlPublicPackage)) {
if (LibraryUtils.isLibraryClassifier(comptype,aadlPublicPackage) || (LibraryUtils.isReusedClassifier(comptype,engine) && !preferences.modifyReused)) {
var newcomptype = {
switch (compinst.category) {
case ComponentCategory.ABSTRACT : aadlPublicPackage.createChild(packageSection_OwnedClassifier,abstractType)
......@@ -88,7 +90,7 @@ class DIMTransformationRulesFeature extends DIMTransformationRules {
case ComponentCategory.VIRTUAL_PROCESSOR : aadlPublicPackage.createChild(packageSection_OwnedClassifier,virtualProcessorType)
}
} as ComponentType
transformationUtils.classifierCreationPropertyAddition(newcomptype)
transformationUtils.classifierCreationDIMPropertyAddition(newcomptype)
newcomptype.set(namedElement_Name, compinst.name)
newcomptype.set(componentType_Extended, comptype)
comptype = newcomptype
......@@ -100,7 +102,7 @@ class DIMTransformationRulesFeature extends DIMTransformationRules {
}
// Parent Component Instance Subcomponent Definition
if (compinst !== topSystemInst) {
if (LibraryUtils.isSubcomponentAffectingLibrary(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage)) {
if (LibraryUtils.isAffectingSubcomponent(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage,engine,preferences.modifyReused)) {
changeParentSubcomponentDefinition(compinst, compinst.eContainer as ComponentInstance)
}
}
......@@ -128,39 +130,55 @@ class DIMTransformationRulesFeature extends DIMTransformationRules {
protected def featureChangedParentSubcomponentDefinition(FeatureInstance featinst) {
var compinst = featinst.eContainer as ComponentInstance
var extensionList = LibraryUtils.getAllInheritingParentTypes(featinst.feature, compinst)
var extensionIndex = LibraryUtils.getClosestLibraryTypeIndex(extensionList, aadlPublicPackage)
var EList<? extends ComponentClassifier> extensionList = LibraryUtils.getAllInheritingParentTypes(featinst.feature, compinst)
var libraryIndex = LibraryUtils.getClosestLibraryTypeIndex(extensionList, aadlPublicPackage)
var reusedIndex = LibraryUtils.getClosestReusedClassifierIndex(extensionList, engine)
var extensionIndex = {
if (preferences.modifyReused) {
libraryIndex
} else {
if (libraryIndex == -1) {
reusedIndex
} else if (reusedIndex == -1) {
libraryIndex
} else {
Math.min(reusedIndex, libraryIndex)
}
}
}
if (extensionIndex != -1) {
var ComponentType previousType
for (ComponentType currentcomptype : extensionList.reverse) {
for (ComponentClassifier currentcomptype : extensionList.reverse) {
if (extensionList.indexOf(currentcomptype) < extensionList.size - extensionIndex) {
var comptypecopy = EcoreUtil.copy(currentcomptype)
transformationUtils.classifierCreationPropertyAddition(comptypecopy)
var comptypecopy = EcoreUtil.copy(currentcomptype) as ComponentType
transformationUtils.classifierCreationDIMPropertyAddition(comptypecopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, comptypecopy)
comptypecopy.set(namedElement_Name,currentcomptype.name+"_dimcopy")
if(extensionList.indexOf(currentcomptype) == 0) {
var newFeat = LibraryUtils.getCopyFeature(featinst.feature, comptypecopy)
var newFeat = LibraryUtils.getCopyFeature(featinst.feature, comptypecopy as ComponentType)
featinst.set(featureInstance_Feature, newFeat)
} else {
comptypecopy.set(componentType_Extended, previousType)
}
previousType = comptypecopy
} else {
if (!LibraryUtils.isSubcomponentAffectingLibrary(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage)) {
if (compinst.classifier instanceof ComponentType && extensionList.indexOf(currentcomptype) == extensionList.size - extensionIndex ||
(compinst.classifier instanceof ComponentImplementation && LibraryUtils.getClosestLibraryImplementationIndex(LibraryUtils.getAllTypeInheritingImplementations(currentcomptype, compinst.classifier as ComponentImplementation),aadlPublicPackage) == -1)) {
if (!LibraryUtils.isAffectingSubcomponent(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage, engine, preferences.modifyReused)) {
if ((compinst.classifier instanceof ComponentType && extensionList.indexOf(currentcomptype) == extensionList.size - extensionIndex) ||
(compinst.classifier instanceof ComponentImplementation &&
((LibraryUtils.getClosestLibraryImplementationIndex(LibraryUtils.getAllTypeInheritingImplementations(currentcomptype as ComponentType, compinst.classifier as ComponentImplementation), aadlPublicPackage) == -1) &&
(LibraryUtils.getClosestReusedClassifierIndex(LibraryUtils.getAllTypeInheritingImplementations(currentcomptype as ComponentType, compinst.classifier as ComponentImplementation), engine) == -1)))) {
currentcomptype.set(componentType_Extended, previousType)
} else {
var comptypecopy = EcoreUtil.copy(currentcomptype)
transformationUtils.classifierCreationPropertyAddition(comptypecopy)
var comptypecopy = EcoreUtil.copy(currentcomptype) as ComponentType
transformationUtils.classifierCreationDIMPropertyAddition(comptypecopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, comptypecopy)
comptypecopy.set(namedElement_Name,currentcomptype.name+"_dimcopy")
comptypecopy.set(componentImplementation_Extended, previousType)
previousType = comptypecopy
if (extensionList.indexOf(currentcomptype) === extensionList.size - 1) {
if (compinst.classifier instanceof ComponentImplementation && LibraryUtils.isLibraryClassifier(compinst.classifier,aadlPublicPackage)) {
if (compinst.classifier instanceof ComponentImplementation && (LibraryUtils.isLibraryClassifier(compinst.classifier,aadlPublicPackage) || (LibraryUtils.isReusedClassifier(compinst.classifier,engine) && !preferences.modifyReused))) {
var compimp = EcoreUtil.copy(compinst.classifier)
transformationUtils.classifierCreationPropertyAddition(compimp)
transformationUtils.classifierCreationDIMPropertyAddition(compimp)
aadlPublicPackage.add(packageSection_OwnedClassifier, compimp)
compimp.set(namedElement_Name, compinst.name+".impl")
compimp.set(componentImplementation_Type, comptypecopy)
......@@ -173,7 +191,7 @@ class DIMTransformationRulesFeature extends DIMTransformationRules {
}
}
}
} else if (compinst !== topSystemInst && LibraryUtils.isSubcomponentAffectingLibrary(compinst.subcomponent, compinst.eContainer as ComponentInstance,aadlPublicPackage)) {
} else if (compinst !== topSystemInst && LibraryUtils.isAffectingSubcomponent(compinst.subcomponent, compinst.eContainer as ComponentInstance, aadlPublicPackage, engine, preferences.modifyReused)) {
changeParentSubcomponentDefinition(compinst, compinst.eContainer as ComponentInstance)
}
setSubcomponentType(compinst, compinst.classifier)
......
......@@ -12,6 +12,7 @@ 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
import org.eclipse.emf.common.util.EList
class DIMTransformationRulesMode extends DIMTransformationRules {
......@@ -24,7 +25,7 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
protected def modeInstanceCreatedDIM (ModeInstance modeinst) {
val compinst = modeinst.eContainer as ComponentInstance
// Parent Component Classifier Selection
if (LibraryUtils.isLibraryClassifier(compinst.classifier, aadlPublicPackage)) {
if (LibraryUtils.isLibraryClassifier(compinst.classifier, aadlPublicPackage) || (LibraryUtils.isReusedClassifier(compinst.classifier, engine) && !preferences.modifyReused)) {
val classifier = {
if (compinst.classifier instanceof ComponentImplementation) {
switch (compinst.category) {
......@@ -62,7 +63,7 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
} as ComponentType
}
}
transformationUtils.classifierCreationPropertyAddition(classifier)
transformationUtils.classifierCreationDIMPropertyAddition(classifier)
classifier.set(namedElement_Name, compinst.name+".impl")
if (classifier instanceof ComponentType) {
classifier.set(componentType_Extended, compinst.classifier)
......@@ -76,7 +77,7 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
}
// Parent Component Instance Subcomponent Definition
if (compinst !== topSystemInst) {
if (LibraryUtils.isSubcomponentAffectingLibrary(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage)) {
if (LibraryUtils.isAffectingSubcomponent(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage, engine, preferences.modifyReused)) {
changeParentSubcomponentDefinition(compinst, compinst.eContainer as ComponentInstance)
}
}
......@@ -106,14 +107,28 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
def void modeChangedParentSubcomponentDefinition(ModeInstance modeinst) {
var compinst = modeinst.eContainer as ComponentInstance
var extensionList = LibraryUtils.getAllInheritingParentImplementations(modeinst.mode, compinst)
var extensionIndex = LibraryUtils.getClosestLibraryImplementationIndex(extensionList, aadlPublicPackage)
var EList<? extends ComponentClassifier> extensionList = LibraryUtils.getAllInheritingParentImplementations(modeinst.mode, compinst)
var libraryIndex = LibraryUtils.getClosestLibraryImplementationIndex(extensionList, aadlPublicPackage)
var reusedIndex = LibraryUtils.getClosestReusedClassifierIndex(extensionList, engine)
var extensionIndex = {
if (preferences.modifyReused) {
libraryIndex
} else {
if (libraryIndex == -1) {
reusedIndex
} else if (reusedIndex == -1) {
libraryIndex
} else {
Math.min(reusedIndex, libraryIndex)
}
}
}
if (extensionIndex !== -1) {
var ComponentClassifier previousClass
for (ComponentClassifier currentcompclass : extensionList.reverse) {
if (extensionList.indexOf(currentcompclass) < extensionList.size - extensionIndex) {
var compclasscopy = EcoreUtil.copy(currentcompclass)
transformationUtils.classifierCreationPropertyAddition(compclasscopy)
transformationUtils.classifierCreationDIMPropertyAddition(compclasscopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, compclasscopy)
compclasscopy.set(namedElement_Name,currentcompclass.name+"_dimcopy")
if(extensionList.indexOf(currentcompclass) == 0) {
......@@ -128,7 +143,7 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
}
previousClass = compclasscopy
} else {
if (compinst == topSystemInst || !LibraryUtils.isSubcomponentAffectingLibrary(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage)) {
if (compinst == topSystemInst || !LibraryUtils.isAffectingSubcomponent(compinst.subcomponent, compinst.eContainer as ComponentInstance, aadlPublicPackage, engine, preferences.modifyReused)) {
if (extensionList.indexOf(currentcompclass) == extensionList.size - extensionIndex) {
if (currentcompclass instanceof ComponentType) {
currentcompclass.set(componentType_Extended, previousClass)
......@@ -138,7 +153,7 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
}
} else {
var compclasscopy = EcoreUtil.copy(currentcompclass)
transformationUtils.classifierCreationPropertyAddition(compclasscopy)
transformationUtils.classifierCreationDIMPropertyAddition(compclasscopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, compclasscopy)
compclasscopy.set(namedElement_Name,currentcompclass.name+"_dimcopy")
compclasscopy.set(componentImplementation_Extended, previousClass)
......@@ -150,7 +165,7 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
}
}
}
} else if (compinst != topSystemInst && LibraryUtils.isSubcomponentAffectingLibrary(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage)) {
} else if (compinst != topSystemInst && LibraryUtils.isAffectingSubcomponent(compinst.subcomponent,compinst.eContainer as ComponentInstance, aadlPublicPackage, engine, preferences.modifyReused)) {
changeParentSubcomponentDefinition(compinst, compinst.eContainer as ComponentInstance)
}
setSubcomponentType(compinst, compinst.classifier)
......@@ -158,14 +173,28 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
def void modeTransChangedParentSubcomponentDefinition(ModeTransitionInstance modetransinst) {
var compinst = modetransinst.eContainer as ComponentInstance
var extensionList = LibraryUtils.getAllInheritingParentImplementations(modetransinst.modeTransition, compinst)
var extensionIndex = LibraryUtils.getClosestLibraryImplementationIndex(extensionList, aadlPublicPackage)
var EList<? extends ComponentClassifier> extensionList = LibraryUtils.getAllInheritingParentImplementations(modetransinst.modeTransition, compinst)
var libraryIndex = LibraryUtils.getClosestLibraryImplementationIndex(extensionList, aadlPublicPackage)
var reusedIndex = LibraryUtils.getClosestReusedClassifierIndex(extensionList, engine)
var extensionIndex = {
if (preferences.modifyReused) {
libraryIndex
} else {
if (libraryIndex == -1) {
reusedIndex
} else if (reusedIndex == -1) {
libraryIndex
} else {
Math.min(reusedIndex, libraryIndex)
}
}
}
if (extensionIndex !== -1) {
var ComponentClassifier previousClass
for (ComponentClassifier currentcompclass : extensionList.reverse) {
if (extensionList.indexOf(currentcompclass) < extensionList.size - extensionIndex) {
var compclasscopy = EcoreUtil.copy(currentcompclass)
transformationUtils.classifierCreationPropertyAddition(compclasscopy)
transformationUtils.classifierCreationDIMPropertyAddition(compclasscopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, compclasscopy)
compclasscopy.set(namedElement_Name,currentcompclass.name+"_dimcopy")
if(extensionList.indexOf(currentcompclass) == 0) {
......@@ -180,7 +209,7 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
}
previousClass = compclasscopy
} else {
if (compinst == topSystemInst || !LibraryUtils.isSubcomponentAffectingLibrary(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage)) {
if (compinst == topSystemInst || !LibraryUtils.isAffectingSubcomponent(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage,engine,preferences.modifyReused)) {
if (extensionList.indexOf(currentcompclass) == extensionList.size - extensionIndex) {
if (currentcompclass instanceof ComponentType) {
currentcompclass.set(componentType_Extended, previousClass)
......@@ -190,7 +219,7 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
}
} else {
var compclasscopy = EcoreUtil.copy(currentcompclass)
transformationUtils.classifierCreationPropertyAddition(compclasscopy)
transformationUtils.classifierCreationDIMPropertyAddition(compclasscopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, compclasscopy)
compclasscopy.set(namedElement_Name,currentcompclass.name+"_dimcopy")
compclasscopy.set(componentImplementation_Extended, previousClass)
......@@ -202,7 +231,7 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
}
}
}
} else if (compinst != topSystemInst && LibraryUtils.isSubcomponentAffectingLibrary(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage)) {
} else if (compinst != topSystemInst && LibraryUtils.isAffectingSubcomponent(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage,engine,preferences.modifyReused)) {
changeParentSubcomponentDefinition(compinst, compinst.eContainer as ComponentInstance)
}
setSubcomponentType(compinst, compinst.classifier)
......@@ -211,7 +240,7 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
protected def modeTransitionInstanceCreatedDIM (ModeTransitionInstance modetransinst) {
var compinst = modetransinst.eContainer as ComponentInstance
// Parent Component Classifier Selection
if (LibraryUtils.isLibraryClassifier(compinst.classifier, aadlPublicPackage)) {
if (LibraryUtils.isLibraryClassifier(compinst.classifier, aadlPublicPackage) || (LibraryUtils.isReusedClassifier(compinst.classifier,engine) && !preferences.modifyReused)) {
val classifier = {
if (compinst.classifier instanceof ComponentImplementation) {
switch (compinst.category) {
......@@ -249,7 +278,7 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
} as ComponentType
}
}
transformationUtils.classifierCreationPropertyAddition(classifier)
transformationUtils.classifierCreationDIMPropertyAddition(classifier)
classifier.set(namedElement_Name, compinst.name+".impl")
if (classifier instanceof ComponentType) {
classifier.set(componentType_Extended, compinst.classifier)
......@@ -263,7 +292,7 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
}
// Parent Component Instance Subcomponent Definition
if (compinst !== topSystemInst) {
if (LibraryUtils.isSubcomponentAffectingLibrary(compinst.subcomponent,compinst.eContainer as ComponentInstance,aadlPublicPackage)) {
if (LibraryUtils.isAffectingSubcomponent