Commit d7da29d4 authored by Rakshit Mittal's avatar Rakshit Mittal
Browse files

added feature for DIMClassifier property to be added to classifier

according to user preference, (TODO: check URI)
parent f976a279
......@@ -61,7 +61,6 @@ class DIMTransformationDeltaInplace extends DIMTransformationRules{
DIMTransformationRulesConnection connectionRules
DIMTransformationRulesMode modeRules
DIMTransformationRulesProperty propertyRules
DIMTransformationRulesExtension transformationUtils
def execute() {
transformation.executionSchema.startUnscheduledExecution
......
......@@ -33,6 +33,8 @@ class DIMTransformationRules {
protected DIMPreferences preferences
protected PublicPackageSection aadlPublicPackage
protected DIMTransformationRulesExtension transformationUtils
def SystemInstance getTopSystemInst() {
return topSystemInst;
}
......@@ -45,6 +47,7 @@ class DIMTransformationRules {
for (ComponentImplementation currentcompimp : extensionList.reverse) {
if (extensionList.indexOf(currentcompimp) < extensionList.size - extensionIndex) {
var compimpcopy = EcoreUtil.copy(currentcompimp)
transformationUtils.classifierCreationPropertyAddition(compimpcopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, compimpcopy)
compimpcopy.set(namedElement_Name,currentcompimp.name+"_dimcopy")
if(extensionList.indexOf(currentcompimp) == 0) {
......@@ -61,6 +64,7 @@ class DIMTransformationRules {
}
} else {
var compimpcopy = EcoreUtil.copy(currentcompimp)
transformationUtils.classifierCreationPropertyAddition(compimpcopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, compimpcopy)
compimpcopy.set(namedElement_Name,currentcompimp.name+"_dimcopy")
compimpcopy.set(componentImplementation_Extended, previousImp)
......@@ -72,9 +76,23 @@ class DIMTransformationRules {
}
}
}
} else if (parentcompinst != topSystemInst && LibraryUtils.isSubcomponentAffectingLibrary(parentcompinst.subcomponent,parentcompinst.eContainer as ComponentInstance,aadlPublicPackage)) {
changeParentSubcomponentDefinition(parentcompinst, parentcompinst.eContainer as ComponentInstance)
}
} else {
var ComponentImplementation previousImp
for (ComponentImplementation currentcompimp : extensionList.reverse) {
var compimpcopy = EcoreUtil.copy(currentcompimp)
transformationUtils.classifierCreationPropertyAddition(compimpcopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, compimpcopy)
compimpcopy.set(namedElement_Name,currentcompimp.name+"_dimcopy")
compimpcopy.set(componentImplementation_Extended, previousImp)
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)) {
changeParentSubcomponentDefinition(parentcompinst, parentcompinst.eContainer as ComponentInstance)
}
}
}
}
setSubcomponentType(compinst, compinst.classifier)
}
......
......@@ -54,6 +54,7 @@ class DIMTransformationRulesComponent extends DIMTransformationRules {
case ComponentCategory.VIRTUAL_PROCESSOR : aadlPublicPackage.createChild(packageSection_OwnedClassifier,virtualProcessorImplementation)
}
} as ComponentImplementation
transformationUtils.classifierCreationPropertyAddition(compimp)
compimp.set(namedElement_Name, compinst.name+".impl")
if (compinst.classifier instanceof ComponentType) {
compimp.set(componentImplementation_Type, compinst.classifier)
......@@ -101,6 +102,9 @@ class DIMTransformationRulesComponent extends DIMTransformationRules {
subcomp.set(namedElement_Name,subcompinst.name)
subcomptype.set(namedElement_Name,subcompinst.name)
}
if (subcompinst.classifier === null) {
transformationUtils.classifierCreationPropertyAddition(subcomptype as ComponentClassifier)
}
subcompinst.set(componentInstance_Classifier, subcomptype)
setSubcomponentType(subcompinst, subcomptype as ComponentClassifier)
}
......
......@@ -78,6 +78,7 @@ class DIMTransformationRulesConnection extends DIMTransformationRules {
case ComponentCategory.VIRTUAL_PROCESSOR : aadlPublicPackage.createChild(packageSection_OwnedClassifier,virtualProcessorImplementation)
}
} as ComponentImplementation
transformationUtils.classifierCreationPropertyAddition(compimp)
compimp.set(namedElement_Name, currentcompinst.name+".impl")
if (currentcompinst.classifier instanceof ComponentType) {
compimp.set(componentImplementation_Type, currentcompinst.classifier)
......@@ -154,7 +155,8 @@ class DIMTransformationRulesConnection extends DIMTransformationRules {
case ComponentCategory.VIRTUAL_BUS : aadlPackage.createChild(packageSection_OwnedClassifier,virtualBusImplementation)
case ComponentCategory.VIRTUAL_PROCESSOR : aadlPackage.createChild(packageSection_OwnedClassifier,virtualProcessorImplementation)
}
}
} as ComponentImplementation
transformationUtils.classifierCreationPropertyAddition(compimp)
compimp.set(namedElement_Name, currentcompinst.classifier.name+".impl")
compimp.set(componentImplementation_Type,currentcompinst.classifier)
currentcompinst.set(componentInstance_Classifier, compimp)
......@@ -226,6 +228,7 @@ class DIMTransformationRulesConnection extends DIMTransformationRules {
for (ComponentImplementation currentcompimp : extensionList.reverse) {
if (extensionList.indexOf(currentcompimp) < extensionList.size - extensionIndex) {
var compimpcopy = EcoreUtil.copy(currentcompimp)
transformationUtils.classifierCreationPropertyAddition(compimpcopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, compimpcopy)
compimpcopy.set(namedElement_Name,currentcompimp.name+"_dimcopy")
if(extensionList.indexOf(currentcompimp) == 0) {
......@@ -242,6 +245,7 @@ class DIMTransformationRulesConnection extends DIMTransformationRules {
}
} else {
var compimpcopy = EcoreUtil.copy(currentcompimp)
transformationUtils.classifierCreationPropertyAddition(compimpcopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, compimpcopy)
compimpcopy.set(namedElement_Name,currentcompimp.name+"_dimcopy")
compimpcopy.set(componentImplementation_Extended, previousImp)
......
......@@ -4,26 +4,47 @@ import org.osate.aadl2.instance.InstanceObject
import org.osate.aadl2.PropertyAssociation
import org.osate.aadl2.instance.ComponentInstance
import org.eclipse.viatra.transformation.runtime.emf.modelmanipulation.IModelManipulations
import org.osate.aadl2.instance.ModeInstance
import org.eclipse.emf.ecore.util.EcoreUtil
import org.osate.aadl2.ComponentClassifier
import org.osate.aadl2.PropertySet
import org.osate.aadl2.Property
import org.osate.aadl2.modelsupport.FileNameConstants
import org.eclipse.emf.common.util.URI
class DIMTransformationRulesExtension extends DIMTransformationRules {
new(IModelManipulations manipulation) {
this.manipulation = manipulation
}
dimResource = topSystemInst.eResource.resourceSet.getResource(URI.createURI("fr.mem4csd.osatedim.viatra/src/fr/mem4csd/osatedim/viatra/preference/DIM_Properties").appendFileExtension( FileNameConstants.SOURCE_FILE_EXT ), true).getContents().get(0) as PropertySet;
}
extension IModelManipulations manipulation
PropertySet dimResource
protected def elementCreationPropertyInheritance (InstanceObject instanceObj, DIMTransformationRulesProperty propertyRules) {
protected def elementCreationPropertyInheritance(InstanceObject instanceObj, DIMTransformationRulesProperty propertyRules) {
for (PropertyAssociation propinst : (instanceObj.eContainer as InstanceObject).ownedPropertyAssociations) {
if (propinst.property.inherit || instanceObj.acceptsProperty(propinst.property)) {
var propadd = instanceObj.createChild(namedElement_OwnedPropertyAssociation, propertyAssociationInstance)
propertyRules.modalPropertyCreatedDIM(propinst, propadd as PropertyAssociation, null)
if (propinst.property.inherit && instanceObj.acceptsProperty(propinst.property)) {
var propadd = EcoreUtil.copy(propinst)
instanceObj.add(namedElement_OwnedPropertyAssociation, propadd)
}
}
}
def elementCreationModeInheritance(ComponentInstance instance) {
throw new UnsupportedOperationException("TODO: auto-generated method stub")
protected def elementCreationModeInheritance(ComponentInstance subcompinst) {
for (ModeInstance modeinst : (subcompinst.eContainer as ComponentInstance).inModes) {
var modeadd = EcoreUtil.copy(modeinst)
subcompinst.add(componentInstance_InMode, modeadd)
}
}
protected def classifierCreationPropertyAddition(ComponentClassifier compclass) {
if (preferences.isAddClassifierProperty) {
var propadd = compclass.createChild(namedElement_OwnedPropertyAssociation, propertyAssociation)
propadd.set(propertyAssociation_Property, dimResource.ownedProperties.get(2))
var modpropadd = propadd.createChild(propertyAssociation_OwnedValue, modalPropertyValue)
var propvaladd = modpropadd.createChild(modalPropertyValue_OwnedValue, booleanLiteral)
propvaladd.set(booleanLiteral_Value,true)
}
}
}
\ No newline at end of file
......@@ -60,6 +60,7 @@ class DIMTransformationRulesFeature extends DIMTransformationRules {
case ComponentCategory.VIRTUAL_PROCESSOR : aadlPublicPackage.createChild(packageSection_OwnedClassifier,virtualProcessorImplementation)
}
} as ComponentImplementation
transformationUtils.classifierCreationPropertyAddition(compimp)
compimp.set(namedElement_Name, compinst.name+".impl")
compimp.set(componentImplementation_Type, comptype)
aadlPublicPackage.add(packageSection_ImportedUnit, compinst.classifier.eContainer.eContainer as ModelUnit)
......@@ -87,6 +88,7 @@ class DIMTransformationRulesFeature extends DIMTransformationRules {
case ComponentCategory.VIRTUAL_PROCESSOR : aadlPublicPackage.createChild(packageSection_OwnedClassifier,virtualProcessorType)
}
} as ComponentType
transformationUtils.classifierCreationPropertyAddition(newcomptype)
newcomptype.set(namedElement_Name, compinst.name)
newcomptype.set(componentType_Extended, comptype)
comptype = newcomptype
......@@ -133,6 +135,7 @@ class DIMTransformationRulesFeature extends DIMTransformationRules {
for (ComponentType currentcomptype : extensionList.reverse) {
if (extensionList.indexOf(currentcomptype) < extensionList.size - extensionIndex) {
var comptypecopy = EcoreUtil.copy(currentcomptype)
transformationUtils.classifierCreationPropertyAddition(comptypecopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, comptypecopy)
comptypecopy.set(namedElement_Name,currentcomptype.name+"_dimcopy")
if(extensionList.indexOf(currentcomptype) == 0) {
......@@ -149,13 +152,15 @@ class DIMTransformationRulesFeature extends DIMTransformationRules {
currentcomptype.set(componentType_Extended, previousType)
} else {
var comptypecopy = EcoreUtil.copy(currentcomptype)
transformationUtils.classifierCreationPropertyAddition(comptypecopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, comptypecopy)
comptypecopy.set(namedElement_Name,currentcomptype.name+"_dimcopy")
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)) {
var compimp = EcoreUtil.copy(compinst.classifier)
transformationUtils.classifierCreationPropertyAddition(compimp)
aadlPublicPackage.add(packageSection_OwnedClassifier, compimp)
compimp.set(namedElement_Name, compinst.name+".impl")
compimp.set(componentImplementation_Type, comptypecopy)
......
......@@ -62,6 +62,7 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
} as ComponentType
}
}
transformationUtils.classifierCreationPropertyAddition(classifier)
classifier.set(namedElement_Name, compinst.name+".impl")
if (classifier instanceof ComponentType) {
classifier.set(componentType_Extended, compinst.classifier)
......@@ -112,6 +113,7 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
for (ComponentClassifier currentcompclass : extensionList.reverse) {
if (extensionList.indexOf(currentcompclass) < extensionList.size - extensionIndex) {
var compclasscopy = EcoreUtil.copy(currentcompclass)
transformationUtils.classifierCreationPropertyAddition(compclasscopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, compclasscopy)
compclasscopy.set(namedElement_Name,currentcompclass.name+"_dimcopy")
if(extensionList.indexOf(currentcompclass) == 0) {
......@@ -136,6 +138,7 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
}
} else {
var compclasscopy = EcoreUtil.copy(currentcompclass)
transformationUtils.classifierCreationPropertyAddition(compclasscopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, compclasscopy)
compclasscopy.set(namedElement_Name,currentcompclass.name+"_dimcopy")
compclasscopy.set(componentImplementation_Extended, previousClass)
......@@ -162,6 +165,7 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
for (ComponentClassifier currentcompclass : extensionList.reverse) {
if (extensionList.indexOf(currentcompclass) < extensionList.size - extensionIndex) {
var compclasscopy = EcoreUtil.copy(currentcompclass)
transformationUtils.classifierCreationPropertyAddition(compclasscopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, compclasscopy)
compclasscopy.set(namedElement_Name,currentcompclass.name+"_dimcopy")
if(extensionList.indexOf(currentcompclass) == 0) {
......@@ -186,6 +190,7 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
}
} else {
var compclasscopy = EcoreUtil.copy(currentcompclass)
transformationUtils.classifierCreationPropertyAddition(compclasscopy)
aadlPublicPackage.add(packageSection_OwnedClassifier, compclasscopy)
compclasscopy.set(namedElement_Name,currentcompclass.name+"_dimcopy")
compclasscopy.set(componentImplementation_Extended, previousClass)
......@@ -244,6 +249,7 @@ class DIMTransformationRulesMode extends DIMTransformationRules {
} as ComponentType
}
}
transformationUtils.classifierCreationPropertyAddition(classifier)
classifier.set(namedElement_Name, compinst.name+".impl")
if (classifier instanceof ComponentType) {
classifier.set(componentType_Extended, compinst.classifier)
......
......@@ -2,6 +2,7 @@ package fr.mem4csd.osatedim.viatra.utils;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
import org.osate.aadl2.ClassifierFeature;
import org.osate.aadl2.ComponentClassifier;
import org.osate.aadl2.ComponentImplementation;
......@@ -15,6 +16,8 @@ import org.osate.aadl2.PackageSection;
import org.osate.aadl2.Subcomponent;
import org.osate.aadl2.instance.ComponentInstance;
import fr.mem4csd.osatedim.viatra.queries.FindComponent;
public class LibraryUtils {
private LibraryUtils() {
......@@ -175,4 +178,47 @@ public class LibraryUtils {
}
return returnList;
}
public static Boolean isReusedClassifier(ComponentClassifier classifier, ViatraQueryEngine engine) {
Integer returnCount = 0;
FindComponent.Matcher matcher = FindComponent.Matcher.on(engine);
for (FindComponent.Match match : matcher.getAllMatches()) {
ComponentInstance compinst = match.getCompinst();
if (compinst.getCategory() == classifier.getCategory()) {
if (hasContributingClassifier(compinst, classifier)) {
returnCount += 1;
}
}
}
if (returnCount > 1) {
return true;
} else {
return false;
}
}
public static Boolean hasContributingClassifier(ComponentInstance compinst, ComponentClassifier classifier) {
ComponentClassifier currentclass;
if (classifier instanceof ComponentType) {
if (compinst.getClassifier() instanceof ComponentType) {
currentclass = compinst.getClassifier();
} else {
currentclass = ((ComponentImplementation) compinst.getClassifier()).getType();
}
} else {
if (compinst.getClassifier() instanceof ComponentType) {
return false;
} else {
currentclass = compinst.getClassifier();
}
}
while (currentclass != null) {
if (currentclass == classifier) {
return true;
} else {
currentclass = (ComponentClassifier) currentclass.getExtended();
}
}
return false;
}
}
\ No newline at end of file
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