use of org.osate.aadl2.properties.PropertyEvaluationResult in project osate2 by osate.
the class PropertyImpl method evaluate.
public PropertyEvaluationResult evaluate(EvaluationContext ctx, int depth) {
List<PropertyAssociation> pas = getPropertyValue(ctx).getAssociations();
List<EvaluatedProperty> vals = new LinkedList<EvaluatedProperty>();
for (PropertyAssociation pa : pas) {
vals.add(pa.evaluate(ctx, depth));
if (!pa.isAppend()) {
break;
}
}
/*
* NB. Do not fix Issue 2387 here! Doing so caused a different problem. Namely,
* if a property with a default value is explicit associated with a value in one place
* in the model, it's going to force model instantiation to create explicit property
* associations in the instance model that bind the default value to the property AT
* ALL OTHER PLACES THE PROPERTY IS APPLICABLE. This is undesirable.
*/
return new PropertyEvaluationResult(pas.isEmpty() ? null : pas.get(0), vals);
}
use of org.osate.aadl2.properties.PropertyEvaluationResult in project osate2 by osate.
the class CachePropertyAssociationsSwitch method cachePropertyAssociations.
protected void cachePropertyAssociations(InstanceObject io) {
try {
for (Property property : propertyFilter) {
if (io.acceptsProperty(property)) {
/*
* Just look up the property. The property doesn't yet have a
* local association, so lookup will get the value from the
* declarative model. Property lookup process now corrects
* reference values to instance reference values.
*/
PropertyEvaluationResult result = property.evaluate(new EvaluationContext(io, classifierCache), 0);
List<EvaluatedProperty> evaluated = result.getEvaluated();
if (!evaluated.isEmpty()) {
// OsateDebug.osateDebug ("[CachePropertyAssociation] io=" + io + ";property=" + property + ";value=" + value);
PropertyAssociationInstance newPA = InstanceFactory.eINSTANCE.createPropertyAssociationInstance();
io.removePropertyAssociations(property);
newPA.setProperty(property);
newPA.setPropertyAssociation(getDeclarativePA(result.getPa()));
fillPropertyValue(io, newPA, evaluated);
if (!newPA.getOwnedValues().isEmpty()) {
io.getOwnedPropertyAssociations().add(newPA);
}
}
}
checkIfCancelled();
if (cancelled()) {
break;
}
}
} catch (IllegalStateException e) {
// circular dependency
// xxx: this is a misleading place to put the marker
OsateDebug.osateDebug("IllegalStateException raised in cachePropertyAssociations");
error(io, e.getMessage());
return;
} catch (InvalidModelException e) {
OsateDebug.osateDebug("InvalidModelException raised in cachePropertyAssociations");
error(e.getElement(), e.getMessage());
return;
}
}
use of org.osate.aadl2.properties.PropertyEvaluationResult in project osate2 by osate.
the class NamedValueImpl method evaluate.
/*
* (non-Javadoc)
*
* @see org.osate.aadl2.impl.PropertyExpressionImpl#evaluate(org.osate.aadl2.properties.EvaluationContext)
*/
public EvaluatedProperty evaluate(EvaluationContext ctx, int depth) {
AbstractNamedValue nv = getNamedValue();
if (depth > 50) {
throw new InvalidModelException(ctx.getInstanceObject(), "Property " + ((Property) nv).getQualifiedName() + " has cyclic value");
}
PropertyEvaluationResult pev = nv.evaluate(ctx, depth + 1);
List<EvaluatedProperty> evaluated = pev.getEvaluated();
if (evaluated.isEmpty()) {
/*
* Issue 2387: If this NamedValue is a reference to a property value, and the
* property value doesn't exist, we need to check for the property's default
* value. (This cannot be done in PropertyImpl.evaluate(), because it is used to
* broadly. See the comment in PropertyImpl.evaluate().)
*/
if (nv instanceof Property) {
final PropertyExpression defaultValueExpression = ((Property) nv).getDefaultValue();
if (defaultValueExpression != null) {
evaluated = Collections.singletonList(defaultValueExpression.evaluate(ctx, depth));
}
}
// Test it again...
if (evaluated.isEmpty()) {
throw new InvalidModelException(ctx.getInstanceObject(), "Property " + ((Property) nv).getQualifiedName() + " is undefined");
}
}
return evaluated.get(0);
}
use of org.osate.aadl2.properties.PropertyEvaluationResult in project osate2 by osate.
the class CachePropertyAssociationsSwitch method cacheConnectionPropertyAssociations.
protected void cacheConnectionPropertyAssociations(final ConnectionInstance conni) {
PropertyAssociation setPA;
PropertyExpression defaultvalue;
try {
/*
* propertyFilter contains all properties used by the system, so, we try to
* use the one associated to the connection instance and their reference and
* see if the user declares a specific value.
*/
for (Property prop : propertyFilter) {
setPA = null;
defaultvalue = prop.getDefaultValue();
for (final ConnectionReference connRef : conni.getConnectionReferences()) {
/*
* In the following piece of code, we check that a property
* is consistent all along the connection reference.
* For example, we check that the timing property (immediate, delayed)
* is consistent for each connection.
*/
if (connRef.acceptsProperty(prop)) {
/*
* Just look up the property. The property doesn't yet have
* a local association, so lookup will get the value from
* the declarative model. Property lookup process now
* corrects reference values to instance reference values.
*/
final PropertyAssociation propAssociation = scProps.retrieveSCProperty(conni, prop, connRef.getConnection());
final EvaluationContext ctx = new EvaluationContext(connRef, classifierCache, propAssociation);
PropertyEvaluationResult result = prop.evaluate(ctx, 0);
List<EvaluatedProperty> evaluated = result.getEvaluated();
if (!evaluated.isEmpty()) {
PropertyAssociationInstance newPA = InstanceFactory.eINSTANCE.createPropertyAssociationInstance();
newPA.setProperty(prop);
newPA.setPropertyAssociation(getDeclarativePA(result.getPa()));
fillPropertyValue(connRef, newPA, evaluated);
if (!newPA.getOwnedValues().isEmpty()) {
/*
* FIXME JD
*
* Try to look if the property references a component or not.
* This was done to fix the issue related to the Bound Bus analysis plugin
*/
for (Iterator<Element> content = EcoreUtil.getAllProperContents(newPA, false); content.hasNext(); ) {
Element elem = content.next();
if (elem instanceof ModalPropertyValue) {
ModalPropertyValue mpv = (ModalPropertyValue) elem;
if (mpv.getOwnedValue() instanceof ListValue) {
ListValue lv = (ListValue) mpv.getOwnedValue();
for (Element e : lv.getOwnedListElements()) {
if (e instanceof ReferenceValue) {
PropertyExpression irv = ((ReferenceValue) e).instantiate(conni.getContainingComponentInstance());
if (irv != null) {
EcoreUtil.replace(e, irv);
}
}
}
}
}
if (elem instanceof ReferenceValue) {
PropertyExpression irv = ((ReferenceValue) elem).instantiate(conni.getContainingComponentInstance());
if (irv != null) {
EcoreUtil.replace(elem, irv);
}
}
}
scProps.recordSCProperty(conni, prop, connRef.getConnection(), newPA);
if (setPA == null) {
setPA = newPA;
conni.getOwnedPropertyAssociations().add(newPA);
} else {
// check consistency
for (Mode m : conni.getSystemInstance().getSystemOperationModes()) {
PropertyExpression newVal = newPA.valueInMode(m);
PropertyExpression setVal = setPA.valueInMode(m);
if (!newVal.sameAs(setVal)) {
error(conni, "Value for property " + setPA.getProperty().getQualifiedName() + " not consistent along connection");
break;
}
}
}
}
}
}
}
checkIfCancelled();
if (cancelled()) {
break;
}
}
} catch (IllegalStateException e) {
// circular dependency
// xxx: this is a misleading place to put the marker
error(conni, e.getMessage());
System.out.println("IllegalStateException raised in cacheConnectionPropertyAssociations");
} catch (InvalidModelException e) {
error(conni, e.getMessage());
System.out.println("InvalidModelException raised in cacheConnectionPropertyAssociations");
}
}
Aggregations