use of org.osate.aadl2.ModalPropertyValue in project osate2 by osate.
the class PropertyUtils method getContainedSimplePropertyValue.
/**
* get a property association from the properties section of the containing classifier if the context.
* This method has been designed to work with end points of connections, i.e., consisting of a target and a context.
* The context must be a NamedElement in its containing classifier, i.e., a feature, feature group, subcomponent.
* The property holder is assumed to be contained in the context object, e.g., a feature in afeature group or a data subcomponent in a port, or feature in a subcomponent.
* The association must match the property definition.
* if the context is null then the containing classifier of the target is used and the path must be one or no path.
* The applies to clause of the property association must be of size 2 if the context is set and point to the context and then the property holder.
* The property value of the property association is assumed not to be modal.
* @param context NamedElement whose containing classifier's properties section is searched for the desired property
* @param target NamedElement the model element to which the property is applied to via the applies to clause
* @param pd Property the property definition
* @return
*/
public static PropertyExpression getContainedSimplePropertyValue(final NamedElement context, final NamedElement target, final Property pd) {
if (context == null) {
return target.getNonModalPropertyValue(pd);
}
Classifier cl = AadlUtil.getContainingClassifier(context);
EList<PropertyAssociation> props = cl.getAllPropertyAssociations();
for (PropertyAssociation propertyAssociation : props) {
if (propertyAssociation.getProperty().equals(pd)) {
// we found a property with the corect type
// now we need to check whether the applies to points to the holder
EList<ContainedNamedElement> appliestos = propertyAssociation.getAppliesTos();
for (ContainedNamedElement containedNamedElement : appliestos) {
EList<ContainmentPathElement> cpes = containedNamedElement.getContainmentPathElements();
if (cpes.size() == 2) {
NamedElement pathcxt = cpes.get(0).getNamedElement();
NamedElement pathelement = cpes.get(1).getNamedElement();
if (context.equals(pathcxt) && target.equals(pathelement)) {
EList<ModalPropertyValue> vallist = propertyAssociation.getOwnedValues();
if (!vallist.isEmpty()) {
ModalPropertyValue elem = vallist.get(0);
PropertyExpression res = elem.getOwnedValue();
if (res instanceof NamedValue) {
AbstractNamedValue nv = ((NamedValue) res).getNamedValue();
if (nv instanceof Property) {
res = target.getNonModalPropertyValue((Property) nv);
} else if (nv instanceof PropertyConstant) {
res = ((PropertyConstant) nv).getConstantValue();
}
}
return res;
}
}
}
}
}
}
return null;
}
use of org.osate.aadl2.ModalPropertyValue in project osate2 by osate.
the class AadlBaNameResolver method propertyFieldIndexResolver.
private boolean propertyFieldIndexResolver(Element el, IntegerValue field, BasicProperty bProperty, int fieldIndex, DeclarativePropertyName declProName) {
if (integerValueResolver(field)) {
// Link to the default value, if it exists.
if (Aadl2Package.LIST_VALUE == el.eClass().getClassifierID() && propertyFieldListValueResolver(field, (ListValue) el, fieldIndex, declProName)) {
return true;
} else if (Aadl2Package.PROPERTY_ASSOCIATION == el.eClass().getClassifierID()) {
PropertyAssociation pa = (PropertyAssociation) el;
ModalPropertyValue mpv = pa.getOwnedValues().get(pa.getOwnedValues().size() - 1);
PropertyExpression pe = mpv.getOwnedValue();
if (Aadl2Package.LIST_VALUE == pe.eClass().getClassifierID()) {
return propertyFieldListValueResolver(field, (ListValue) pe, fieldIndex, declProName);
}
}
// the else statements: link with the property type.
ListType lt = (ListType) bProperty.getPropertyType();
declProName.setOsateRef(lt.getElementType());
return true;
} else {
return false;
}
}
use of org.osate.aadl2.ModalPropertyValue in project osate2 by osate.
the class AadlBaNameResolver method behaviorVariableResolver.
/**
* Resolves the behavior annex's variables.
*
* @return {@code true} if all names are resolved. {@code false} otherwise.
*/
private boolean behaviorVariableResolver() {
boolean result = true;
QualifiedNamedElement uccr;
// classifier reference exists.
for (BehaviorVariable v : _ba.getVariables()) {
uccr = (QualifiedNamedElement) v.getDataClassifier();
result &= qualifiedNamedElementResolver(uccr, true);
for (ArrayDimension tmp : v.getArrayDimensions()) {
IntegerValueConstant ivc = ((DeclarativeArrayDimension) tmp).getDimension();
result &= integerValueConstantResolver(ivc);
}
List<PropertyAssociation> paList = v.getOwnedPropertyAssociations();
List<PropertyAssociation> paPropertyNotFound = new ArrayList<PropertyAssociation>();
Set<PropertyAssociation> paPropertyValueError = new HashSet<PropertyAssociation>();
for (PropertyAssociation pa : paList) {
QualifiedNamedElement p = (QualifiedNamedElement) pa.getProperty();
boolean valid = qualifiedNamedElementResolver(p, false);
if (valid) {
for (ModalPropertyValue mpv : pa.getOwnedValues()) {
result &= propertyExpressionResolver(v, p, mpv.getOwnedValue());
paPropertyValueError.add(pa);
}
}
if (!valid) {
paPropertyNotFound.add(pa);
}
result &= valid;
}
StringBuilder msg = new StringBuilder();
if (paPropertyNotFound.size() > 1) {
msg.append("Properties ");
} else {
msg.append("Property ");
}
boolean first = true;
for (PropertyAssociation paToRemove : paPropertyNotFound) {
QualifiedNamedElement p = (QualifiedNamedElement) paToRemove.getProperty();
StringBuilder qualifiedName = new StringBuilder();
if (p.getBaNamespace() != null) {
qualifiedName.append(p.getBaNamespace().getId());
qualifiedName.append("::");
}
qualifiedName.append(p.getBaName().getId());
if (first) {
msg.append("\'" + qualifiedName + "\' ");
} else {
msg.append(" and \'" + qualifiedName + "\' ");
}
first = false;
}
paList.removeAll(paPropertyNotFound);
paList.removeAll(paPropertyValueError);
if (paPropertyNotFound.size() > 0) {
msg.append("not found");
_errManager.error(v, msg.toString());
}
}
return result;
}
use of org.osate.aadl2.ModalPropertyValue in project osate2 by osate.
the class PropertyUtils method createIntegerAssignment.
public static PropertyAssociation createIntegerAssignment(String propertyName, long value) {
Property property = Aadl2Factory.eINSTANCE.createProperty();
PropertyAssociation assignment = Aadl2Factory.eINSTANCE.createPropertyAssociation();
ModalPropertyValue modalPropertyValue = Aadl2Factory.eINSTANCE.createModalPropertyValue();
IntegerLiteral propertyValue = Aadl2Factory.eINSTANCE.createIntegerLiteral();
property.setName(propertyName);
propertyValue.setValue(value);
modalPropertyValue.setOwnedValue(propertyValue);
assignment.setProperty(property);
assignment.getOwnedValues().add(modalPropertyValue);
return assignment;
}
use of org.osate.aadl2.ModalPropertyValue in project osate2 by osate.
the class PropertyUtils method getListValue.
public static ListValue getListValue(NamedElement ne, String propertyName) {
PropertyAssociation pa = findPropertyAssociation(propertyName, ne);
if (pa != null) {
Property p = pa.getProperty();
if (p.getName().equalsIgnoreCase(propertyName)) {
List<ModalPropertyValue> values = pa.getOwnedValues();
if (values.size() == 1) {
ModalPropertyValue v = values.get(0);
PropertyExpression expr = v.getOwnedValue();
if (expr instanceof ListValue) {
return (ListValue) expr;
}
}
}
}
return null;
}
Aggregations