use of org.osate.aadl2.PropertyAssociation in project AMASE by loonwerks.
the class SafetyScopeProvider method scope_GetPropertyExpr_prop.
protected IScope scope_GetPropertyExpr_prop(GetPropertyExpr ctx, EReference ref) {
IScope prevScope = prevScope(ctx, ref);
ComponentRef cr = ctx.getComponentRef();
if (cr instanceof ThisRef) {
List<Property> ps = new ArrayList<>();
EObject container = ctx.getContainingClassifier();
while (container != null) {
if (container instanceof Classifier) {
List<PropertyAssociation> pas = ((Classifier) container).getAllPropertyAssociations();
for (PropertyAssociation pa : pas) {
ps.add(pa.getProperty());
}
container = ((Classifier) container).eContainer();
} else if (container instanceof AadlPackage) {
for (PropertySet propSet : EcoreUtil2.getAllContentsOfType(container, PropertySet.class)) {
for (Property p : propSet.getOwnedProperties()) {
ps.add(p);
}
// =======
// EList<EObject> refs = null;
//
// if (container instanceof NestedDotID) {
// NestedDotID parent = (NestedDotID) container;
// refs = parent.eCrossReferences();
//
// if (refs.size() != 1) {
// return new HashSet<>(); // this will throw a parsing error
// }
// container = refs.get(0); // figure out what this type this portion
//
// // of the nest id is so we can figure out
// // what we could possibly link to
//
// if (container instanceof ThreadSubcomponent) {
// container = ((ThreadSubcomponent) container).getComponentType();
// result.addAll(getAadlElements(container));
// } else if (container instanceof Subcomponent) {
// container = ((Subcomponent) container).getComponentImplementation();
// if (container == null) { // no implementation is provided
// container = refs.get(0);
// container = ((Subcomponent) container).getClassifier();
// }
// result.addAll(getAadlElements(container));
// } else if (container instanceof DataPort) {
// container = ((DataPort) container).getDataFeatureClassifier();
// result.addAll(getAadlElements(container));
// } else if (container instanceof EventDataPort) {
// container = ((EventDataPort) container).getDataFeatureClassifier();
// result.addAll(getAadlElements(container));
// } else if (container instanceof AadlPackage) {
// result.addAll(getAadlElements(container));
// } else if (container instanceof FeatureGroupImpl) {
// container = ((FeatureGroupImpl) container).getAllFeatureGroupType();
// result.addAll(getAadlElements(container));
// } else if (container instanceof Arg || container instanceof ConstStatement) {
// Type type;
//
// if (container instanceof Arg) {
// type = ((Arg) container).getType();
// } else {
// type = ((ConstStatement) container).getType();
// }
//
// if (type instanceof RecordType) {
// DoubleDotRef elID = ((RecordType) type).getRecord();
// NamedElement namedEl = elID.getElm();
//
// if (namedEl instanceof ComponentImplementation) {
// ComponentImplementation componentImplementation = (ComponentImplementation) namedEl;
// EList<Subcomponent> subs = componentImplementation.getAllSubcomponents();
// result.addAll(subs);
// } else if (namedEl instanceof RecordDefExpr) {
// result.addAll(((RecordDefExpr) namedEl).getArgs());
// >>>>>>> origin/develop
}
container = null;
} else {
container = container.eContainer();
}
}
return Scopes.scopeFor(ps, prevScope);
} else if (cr instanceof DoubleDotRef) {
NamedElement ne = ((DoubleDotRef) cr).getElm();
if (ne instanceof Subcomponent) {
List<PropertyAssociation> pas = ((Subcomponent) ne).getOwnedPropertyAssociations();
List<Property> ps = new ArrayList<>();
for (PropertyAssociation pa : pas) {
ps.add(pa.getProperty());
}
return Scopes.scopeFor(ps, prevScope);
}
}
return IScope.NULLSCOPE;
}
use of org.osate.aadl2.PropertyAssociation in project VERDICT by ge-high-assurance.
the class SynthesisAadlWriter method applyChangesToElem.
private static void applyChangesToElem(NamedElement elem, Map<String, Property> props, Map<String, List<ResultsInstance.Item>> elemChanges) {
if (elemChanges.containsKey(elem.getFullName())) {
for (ResultsInstance.Item item : elemChanges.get(elem.getFullName())) {
Property prop = props.get(item.defenseProperty);
// TODO perhaps figure out how to remove a defense if the DAL goes to 0?
boolean existing = false;
// try modifying existing prop if it exists
for (PropertyAssociation assoc : elem.getOwnedPropertyAssociations()) {
if (prop.equals(assoc.getProperty())) {
if (assoc.getOwnedValues().size() != 1) {
throw new RuntimeException("defense property has a list value, component: " + item.component + ", defense property: " + item.defenseProperty);
}
ModalPropertyValue propVal = assoc.getOwnedValues().get(0);
IntegerLiteral val = (IntegerLiteral) propVal.createOwnedValue(Aadl2Package.eINSTANCE.getIntegerLiteral());
val.setValue(item.outputDal);
existing = true;
break;
}
}
// add the prop if it doesn't exist
if (!existing && item.outputDal > 0) {
PropertyAssociation assoc = elem.createOwnedPropertyAssociation();
assoc.setProperty(prop);
ModalPropertyValue propVal = assoc.createOwnedValue();
IntegerLiteral val = (IntegerLiteral) propVal.createOwnedValue(Aadl2Package.eINSTANCE.getIntegerLiteral());
val.setValue(item.outputDal);
}
}
}
}
use of org.osate.aadl2.PropertyAssociation in project VERDICT by ge-high-assurance.
the class Aadl2Vdm method getStrRepofPropVal.
/**
* @author Paul Meng
* @param propAcc
* @return
*/
public String getStrRepofPropVal(PropertyAcc propAcc) {
String value = "";
if (propAcc != null) {
List<PropertyAssociation> propAssocs = propAcc.getAssociations();
if (!propAssocs.isEmpty() && propAssocs.size() == 1) {
PropertyAssociation propAssoc = propAssocs.get(0);
// We assume that each property only has only 1 non-list value for now
if (propAssoc.getOwnedValues().size() == 1) {
ModalPropertyValue propVal = propAssoc.getOwnedValues().get(0);
PropertyExpression exp = propVal.getOwnedValue();
value = getStrRepofExpr(exp)[0];
} else {
throw new RuntimeException("Unexpected: property is a list of values with size = : " + propAssoc.getOwnedValues().size());
}
} else {
// throw new RuntimeException("Unexpected property association size: " + propAssocs.size());
}
}
return value;
}
use of org.osate.aadl2.PropertyAssociation in project VERDICT by ge-high-assurance.
the class Aadl2Vdm method createVdmPort.
/**
* @author Vidhya Tekken Valapil
* Creates a new Vdm Port object and returns
* Populates "name", "mode" and "type"
* @param dataport
* @return vdm port
*/
private Port createVdmPort(DataPort dataPort, Model model, HashSet<String> dataTypeDecl) {
String modeString = "in";
if (dataPort.isIn()) {
modeString = "in";
} else if (dataPort.isOut()) {
modeString = "out";
}
// fetching data type information
DataSubcomponentType dSubCompType = dataPort.getDataFeatureClassifier();
verdict.vdm.vdm_data.DataType dtype = new verdict.vdm.vdm_data.DataType();
if (dSubCompType instanceof DataTypeImpl) {
org.osate.aadl2.DataType aadlDType = (org.osate.aadl2.DataType) dSubCompType;
dtype = resolveAADLDataType(aadlDType, model, dataTypeDecl);
} else if (dSubCompType instanceof DataImplementationImpl) {
org.osate.aadl2.DataImplementation aadlDImpl = (org.osate.aadl2.DataImplementation) dSubCompType;
dtype = resolveAADLDataImplementationType(aadlDImpl, model, dataTypeDecl);
} else {
System.out.println("Unresolved/unexpected Named Element.");
}
verdict.vdm.vdm_model.Port newPort = new verdict.vdm.vdm_model.Port();
newPort.setProbe(false);
if (dataPort.getOwnedPropertyAssociations().size() != 0) {
EList<PropertyAssociation> propertyAssocs = dataPort.getOwnedPropertyAssociations();
for (PropertyAssociation propertyAssoc : propertyAssocs) {
if (propertyAssoc.getProperty().getName().equalsIgnoreCase("probe")) {
EList<ModalPropertyValue> propVals = propertyAssoc.getOwnedValues();
if (propVals.size() == 0 || propVals.size() > 1) {
throw new RuntimeException("Unexpected number for values for probe property of port.");
}
if (propVals.get(0).getOwnedValue() instanceof BooleanLiteral) {
BooleanLiteral probeVal = (BooleanLiteral) propVals.get(0).getOwnedValue();
newPort.setProbe(probeVal.getValue());
} else {
throw new RuntimeException("Unexpected type of value for probe property of port.");
}
}
}
}
newPort.setId(dataPort.getQualifiedName());
newPort.setName(dataPort.getName());
newPort.setMode(convertToVdmPortMode(modeString));
newPort.setType(dtype);
return newPort;
}
use of org.osate.aadl2.PropertyAssociation in project VERDICT by ge-high-assurance.
the class Aadl2CsvTranslator method getStrRepofPropVal.
public String getStrRepofPropVal(PropertyAcc propAcc) {
String value = "";
if (propAcc != null) {
List<PropertyAssociation> propAssocs = propAcc.getAssociations();
if (!propAssocs.isEmpty() && propAssocs.size() == 1) {
PropertyAssociation propAssoc = propAssocs.get(0);
// We assume that each property only has only 1 non-list value for now
if (propAssoc.getOwnedValues().size() == 1) {
ModalPropertyValue propVal = propAssoc.getOwnedValues().get(0);
PropertyExpression exp = propVal.getOwnedValue();
value = getStrRepofExpr(exp)[0];
} else {
throw new RuntimeException("Unexpected: property is a list of values with size = : " + propAssoc.getOwnedValues().size());
}
} else {
// throw new RuntimeException("Unexpected property association size: " + propAssocs.size());
}
}
return value;
}
Aggregations