use of org.osate.aadl2.properties.EvaluatedProperty 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.EvaluatedProperty 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.EvaluatedProperty 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.EvaluatedProperty in project osate2 by osate.
the class RangeValueImpl method evaluate.
public final EvaluatedProperty evaluate(EvaluationContext ctx, int depth) throws InvalidModelException {
/*
* The min, max, and delta attributes can refer to PropertyReferences to
* signed property constants that we need to resolve. So we first
* evaluate the min, max, and delta values, and then create a new
* RangeValue out of the evaluated contents.
*/
try {
NumberValue maxNumberValue;
NumberValue minNumberValue;
EvaluatedProperty maxVal = maximum.evaluate(ctx, depth);
EvaluatedProperty minVal = minimum.evaluate(ctx, depth);
EvaluatedProperty deltaVal = null;
maxNumberValue = null;
minNumberValue = null;
/*
* First, retrieve the maximum value.
*/
if (maxVal.size() != 1 || maxVal.first().isModal()) {
throw new InvalidModelException(ctx.getInstanceObject(), "Range maximum is modal");
}
if (maxVal.first().getValue() instanceof NumberValue) {
maxNumberValue = (NumberValue) maxVal.first().getValue();
} else {
throw new InvalidModelException(ctx.getInstanceObject(), "Range maximum is not numeric");
}
/*
* So now, retrieve the minimum value.
*/
if (minVal.size() != 1 || minVal.first().isModal()) {
throw new InvalidModelException(ctx.getInstanceObject(), "Range minimum is modal");
}
if (minVal.first().getValue() instanceof NumberValue) {
minNumberValue = (NumberValue) minVal.first().getValue();
} else {
throw new InvalidModelException(ctx.getInstanceObject(), "Range minimum is not numeric");
}
if (delta != null) {
deltaVal = delta.evaluate(ctx, depth);
if (deltaVal.size() != 1 || deltaVal.first().isModal()) {
throw new InvalidModelException(ctx.getInstanceObject(), "Range delta is modal");
}
if (!(deltaVal.first().getValue() instanceof NumberValue)) {
throw new InvalidModelException(ctx.getInstanceObject(), "Range delta is not numeric");
}
}
RangeValue newVal = Aadl2Factory.eINSTANCE.createRangeValue();
newVal.setMaximum(maxNumberValue);
newVal.setMinimum(minNumberValue);
if (deltaVal != null) {
newVal.setDelta(deltaVal.first().getValue());
}
return new EvaluatedProperty(newVal);
} catch (NullPointerException e) {
throw new InvalidModelException(ctx.getInstanceObject(), "Incomplete range value");
} catch (ClassCastException e) {
throw new InvalidModelException(ctx.getInstanceObject(), "Incomplete range value");
}
}
use of org.osate.aadl2.properties.EvaluatedProperty in project osate2 by osate.
the class RecordValueImpl method evaluate.
/*
* (non-Javadoc)
*
* @see org.osate.aadl2.impl.PropertyExpressionImpl#evaluate(org.osate.aadl2.properties.EvaluationContext, int)
*/
public EvaluatedProperty evaluate(EvaluationContext ctx, int depth) {
// evaluate each record field
RecordValue newVal = Aadl2Factory.eINSTANCE.createRecordValue();
for (BasicPropertyAssociation field : getOwnedFieldValues()) {
EvaluatedProperty fieldVal = field.getOwnedValue().evaluate(ctx, depth + 1);
String name = field.getProperty().getName();
if (fieldVal.isEmpty()) {
throw new InvalidModelException(this, "Field " + name + " has no value");
}
if (fieldVal.size() > 1) {
throw new InvalidModelException(this, "Field " + name + " has multiple values");
}
if (fieldVal.first().isModal()) {
throw new InvalidModelException(this, "Field " + name + ": value is modal");
}
BasicPropertyAssociation newField = newVal.createOwnedFieldValue();
newField.setProperty(field.getProperty());
PropertyExpression exp = fieldVal.first().getValue();
newField.setOwnedValue(exp);
}
return new EvaluatedProperty(newVal);
}
Aggregations