Search in sources :

Example 1 with EvaluatedProperty

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);
}
Also used : PropertyEvaluationResult(org.osate.aadl2.properties.PropertyEvaluationResult) PropertyAssociation(org.osate.aadl2.PropertyAssociation) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) LinkedList(java.util.LinkedList)

Example 2 with EvaluatedProperty

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;
    }
}
Also used : InvalidModelException(org.osate.aadl2.properties.InvalidModelException) PropertyEvaluationResult(org.osate.aadl2.properties.PropertyEvaluationResult) PropertyAssociationInstance(org.osate.aadl2.instance.PropertyAssociationInstance) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) EvaluationContext(org.osate.aadl2.properties.EvaluationContext) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) Property(org.osate.aadl2.Property)

Example 3 with EvaluatedProperty

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);
}
Also used : InvalidModelException(org.osate.aadl2.properties.InvalidModelException) PropertyEvaluationResult(org.osate.aadl2.properties.PropertyEvaluationResult) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) PropertyExpression(org.osate.aadl2.PropertyExpression) Property(org.osate.aadl2.Property) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty)

Example 4 with EvaluatedProperty

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");
    }
}
Also used : InvalidModelException(org.osate.aadl2.properties.InvalidModelException) NumberValue(org.osate.aadl2.NumberValue) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) RangeValue(org.osate.aadl2.RangeValue)

Example 5 with EvaluatedProperty

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);
}
Also used : InvalidModelException(org.osate.aadl2.properties.InvalidModelException) RecordValue(org.osate.aadl2.RecordValue) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) PropertyExpression(org.osate.aadl2.PropertyExpression) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation)

Aggregations

EvaluatedProperty (org.osate.aadl2.properties.EvaluatedProperty)9 InvalidModelException (org.osate.aadl2.properties.InvalidModelException)8 PropertyExpression (org.osate.aadl2.PropertyExpression)6 PropertyEvaluationResult (org.osate.aadl2.properties.PropertyEvaluationResult)4 Property (org.osate.aadl2.Property)3 Element (org.osate.aadl2.Element)2 ListValue (org.osate.aadl2.ListValue)2 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)2 Mode (org.osate.aadl2.Mode)2 NumberValue (org.osate.aadl2.NumberValue)2 PropertyAssociation (org.osate.aadl2.PropertyAssociation)2 ReferenceValue (org.osate.aadl2.ReferenceValue)2 ConnectionReference (org.osate.aadl2.instance.ConnectionReference)2 PropertyAssociationInstance (org.osate.aadl2.instance.PropertyAssociationInstance)2 SystemOperationMode (org.osate.aadl2.instance.SystemOperationMode)2 EvaluationContext (org.osate.aadl2.properties.EvaluationContext)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 AbstractNamedValue (org.osate.aadl2.AbstractNamedValue)1 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)1