Search in sources :

Example 26 with PropertyExpression

use of org.osate.aadl2.PropertyExpression in project osate2 by osate.

the class NumericRangeImpl method createLowerBound.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public PropertyExpression createLowerBound(EClass eClass) {
    PropertyExpression newLowerBound = (PropertyExpression) create(eClass);
    setLowerBound(newLowerBound);
    return newLowerBound;
}
Also used : PropertyExpression(org.osate.aadl2.PropertyExpression)

Example 27 with PropertyExpression

use of org.osate.aadl2.PropertyExpression in project osate2 by osate.

the class NumericRangeImpl method createUpperBound.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public PropertyExpression createUpperBound(EClass eClass) {
    PropertyExpression newUpperBound = (PropertyExpression) create(eClass);
    setUpperBound(newUpperBound);
    return newUpperBound;
}
Also used : PropertyExpression(org.osate.aadl2.PropertyExpression)

Example 28 with PropertyExpression

use of org.osate.aadl2.PropertyExpression in project osate2 by osate.

the class PropertiesValidator method typeCheckPropertyValues.

/**
 * checks and report mismatch in type of value and type
 *
 * @param pt:
 *            PropertyType or unresolved proxy or null
 * @param pv:
 *            PropertyExpression or null
 * @param prefix:
 *            String prefix to error message used for lists
 * @since 2.0
 */
protected void typeCheckPropertyValues(PropertyType pt, PropertyExpression pv, String prefix, Element holder, String defName, int depth) {
    if (Aadl2Util.isNull(pt) || pv == null || holder == null) {
        return;
    }
    if (depth > 50) {
        error(holder, "Cyclic value discovered for '" + defName + "'");
        return;
    }
    depth++;
    String msg = " to property '" + defName + "' of type '" + pt.eClass().getName() + "'";
    if (!prefix.isEmpty() && !prefix.startsWith(" ")) {
        prefix = prefix + " ";
    }
    if (pv instanceof ListValue) {
        if (pt instanceof ListType) {
            typeMatchListElements(((ListType) pt).getElementType(), ((ListValue) pv).getOwnedListElements(), holder, defName, depth);
        } else {
            error(holder, prefix + "Assigning a list of values" + msg);
        }
    } else if (pv instanceof Operation || pv instanceof BooleanLiteral) {
        if (!(pt instanceof AadlBoolean)) {
            error(holder, prefix + "Assigning a Boolean value" + msg);
        }
    } else if (pv instanceof StringLiteral) {
        if (!(pt instanceof AadlString)) {
            error(prefix + "Assigning String value" + msg, holder, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, Diagnostic.LINKING_DIAGNOSTIC);
        }
    } else if (pv instanceof EnumerationLiteral || (pv instanceof NamedValue && ((NamedValue) pv).getNamedValue() instanceof EnumerationLiteral)) {
        if (!(pt instanceof EnumerationType)) {
            error(holder, prefix + "Assigning Enumeration literal" + msg);
        }
    } else if (pv instanceof UnitLiteral || (pv instanceof NamedValue && ((NamedValue) pv).getNamedValue() instanceof UnitLiteral)) {
        if (!(pt instanceof UnitsType)) {
            error(holder, prefix + "Assigning Unit literal" + msg);
        }
    } else if (pv instanceof IntegerLiteral) {
        if (!(pt instanceof AadlInteger)) {
            error(holder, prefix + "Assigning Integer value" + msg);
        } else if (checkUnits((AadlInteger) pt, (IntegerLiteral) pv, holder)) {
            checkInRange((AadlInteger) pt, (IntegerLiteral) pv);
        }
    } else if (pv instanceof RealLiteral) {
        if (!(pt instanceof AadlReal)) {
            error(holder, prefix + "Assigning Real value" + msg);
        } else if (checkUnits((AadlReal) pt, (RealLiteral) pv, holder)) {
            checkInRange((AadlReal) pt, (RealLiteral) pv);
        }
    } else if (pv instanceof RangeValue) {
        if (!(pt instanceof RangeType)) {
            error(holder, prefix + "Assigning Range value" + msg);
        } else {
            typeCheckPropertyValues(((RangeType) pt).getNumberType(), ((RangeValue) pv).getMinimumValue(), holder, defName, depth);
            typeCheckPropertyValues(((RangeType) pt).getNumberType(), ((RangeValue) pv).getMaximumValue(), holder, defName, depth);
            typeCheckPropertyValues(((RangeType) pt).getNumberType(), ((RangeValue) pv).getDeltaValue(), holder, defName, depth);
        }
    } else if (pv instanceof ClassifierValue) {
        if (!(pt instanceof ClassifierType)) {
            error(holder, prefix + "Assigning incorrect Classifier value" + msg);
            return;
        }
        ClassifierValue cv = (ClassifierValue) pv;
        ClassifierType ct = (ClassifierType) pt;
        if (ct.getClassifierReferences().isEmpty()) {
            return;
        }
        for (MetaclassReference mcri : ct.getClassifierReferences()) {
            if (mcri.getMetaclass() != null && mcri.getMetaclass().isSuperTypeOf(cv.getClassifier().eClass())) {
                return;
            }
        }
        error(holder, prefix + "Assigning classifier value with incorrect Classifier" + msg);
    } else if (pv instanceof RecordValue) {
        if (!(pt instanceof RecordType)) {
            error(holder, prefix + "Assigning Record value" + msg);
        } else {
            typeMatchRecordFields(((RecordValue) pv).getOwnedFieldValues(), holder, defName, depth);
        }
    } else if (pv instanceof ReferenceValue) {
        if (!(pt instanceof ReferenceType)) {
            error(holder, prefix + "Assigning incorrect reference value" + msg);
        } else {
            ReferenceType ptrt = (ReferenceType) pt;
            if (ptrt.getNamedElementReferences().isEmpty()) {
                return;
            }
            ReferenceValue pvrv = (ReferenceValue) pv;
            EList<ContainmentPathElement> cpes = pvrv.getContainmentPathElements();
            if (!cpes.isEmpty()) {
                NamedElement ne = cpes.get(cpes.size() - 1).getNamedElement();
                for (MetaclassReference mcri : ptrt.getNamedElementReferences()) {
                    if (mcri.getMetaclass().isSuperTypeOf(ne.eClass())) {
                        return;
                    }
                }
                error(holder, prefix + "Assigning reference value with incorrect Named Element class" + msg);
            }
        }
    } else if (pv instanceof NamedValue) {
        AbstractNamedValue nv = ((NamedValue) pv).getNamedValue();
        if (nv instanceof PropertyConstant) {
            final PropertyConstant propertyConstant = (PropertyConstant) nv;
            final PropertyType pct = propertyConstant.getPropertyType();
            if (!Aadl2Util.isNull(pct) && !Aadl2Util.arePropertyTypesEqual(pt, pct)) {
                final String expected = getTypeName(pt);
                final String actual = getTypeName(pct);
                if (actual != null) {
                    if (expected != null) {
                        error(holder, "Property value of type " + actual + "; expected type " + expected);
                    } else {
                        error(holder, "Propery value of type " + actual + " does not match expected type");
                    }
                } else {
                    if (expected != null) {
                        error(holder, "Property value is not of expected type " + expected);
                    } else {
                        error(holder, "Propery value is not of expected type");
                    }
                }
            } else {
                // Issue 2222: is this still really necessary?
                typeCheckPropertyValues(pt, propertyConstant.getConstantValue(), holder, defName, depth);
            }
        } else if (nv instanceof Property) {
            PropertyType pvt = ((Property) nv).getPropertyType();
            if (!Aadl2Util.isNull(pvt)) {
                if (pvt.eClass() != pt.eClass() || !Aadl2Util.arePropertyTypesEqual(pt, pvt)) {
                    final String expected = getTypeName(pt);
                    final String actual = getTypeName(pvt);
                    if (actual != null) {
                        if (expected != null) {
                            error(holder, "Property value of type " + actual + "; expected type " + expected);
                        } else {
                            error(holder, "Propery value of type " + actual + " does not match expected type");
                        }
                    } else {
                        if (expected != null) {
                            error(holder, "Property value is not of expected type " + expected);
                        } else {
                            error(holder, "Propery value is not of expected type");
                        }
                    }
                }
            }
        } else {
            error(holder, "Enum/Unit literal validation should have happened before");
        }
    }
}
Also used : ClassifierType(org.osate.aadl2.ClassifierType) ClassifierValue(org.osate.aadl2.ClassifierValue) BooleanLiteral(org.osate.aadl2.BooleanLiteral) ReferenceValue(org.osate.aadl2.ReferenceValue) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) NamedValue(org.osate.aadl2.NamedValue) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) AadlString(org.osate.aadl2.AadlString) Operation(org.osate.aadl2.Operation) PropertyType(org.osate.aadl2.PropertyType) RangeValue(org.osate.aadl2.RangeValue) ReferenceType(org.osate.aadl2.ReferenceType) RealLiteral(org.osate.aadl2.RealLiteral) RangeType(org.osate.aadl2.RangeType) RecordType(org.osate.aadl2.RecordType) ListType(org.osate.aadl2.ListType) UnitLiteral(org.osate.aadl2.UnitLiteral) AadlInteger(org.osate.aadl2.AadlInteger) MetaclassReference(org.osate.aadl2.MetaclassReference) AadlString(org.osate.aadl2.AadlString) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral) ArraySizeProperty(org.osate.aadl2.ArraySizeProperty) Property(org.osate.aadl2.Property) IntegerLiteral(org.osate.aadl2.IntegerLiteral) AadlReal(org.osate.aadl2.AadlReal) ListValue(org.osate.aadl2.ListValue) EnumerationType(org.osate.aadl2.EnumerationType) RecordValue(org.osate.aadl2.RecordValue) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) PropertyConstant(org.osate.aadl2.PropertyConstant) AadlBoolean(org.osate.aadl2.AadlBoolean) StringLiteral(org.osate.aadl2.StringLiteral) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) UnitsType(org.osate.aadl2.UnitsType)

Example 29 with PropertyExpression

use of org.osate.aadl2.PropertyExpression in project osate2 by osate.

the class PropertiesValidator method checkInRange.

private void checkInRange(NumberType type, NumberValue value) {
    NumericRange range = type.getRange();
    if (range != null) {
        PropertyExpression lowerExpression;
        try {
            MpvProxy modalProxy = range.getLowerBound().evaluate(null, 0).first();
            lowerExpression = modalProxy == null ? null : modalProxy.getValue();
        } catch (InvalidModelException e) {
            lowerExpression = null;
        }
        PropertyExpression upperExpression;
        try {
            MpvProxy modalProxy = range.getUpperBound().evaluate(null, 0).first();
            upperExpression = modalProxy == null ? null : modalProxy.getValue();
        } catch (InvalidModelException e) {
            upperExpression = null;
        }
        if (lowerExpression instanceof NumberValue && upperExpression instanceof NumberValue) {
            NumberValue lower = (NumberValue) lowerExpression;
            NumberValue upper = (NumberValue) upperExpression;
            double valueScaled = value.getScaledValue();
            if (valueScaled < lower.getScaledValue() || valueScaled > upper.getScaledValue()) {
                error(value, "Value must be between " + lower + " and " + upper);
            }
        }
    }
}
Also used : NumericRange(org.osate.aadl2.NumericRange) InvalidModelException(org.osate.aadl2.properties.InvalidModelException) NumberValue(org.osate.aadl2.NumberValue) MpvProxy(org.osate.aadl2.properties.EvaluatedProperty.MpvProxy) PropertyExpression(org.osate.aadl2.PropertyExpression)

Example 30 with PropertyExpression

use of org.osate.aadl2.PropertyExpression in project osate2 by osate.

the class PropertiesValidator method checkArrayReference.

@Check(CheckType.FAST)
public void checkArrayReference(ContainmentPathElement pathElement) {
    NamedElement element = pathElement.getNamedElement();
    List<ArrayRange> providedRanges = pathElement.getArrayRanges();
    if (element.eIsProxy() || providedRanges.isEmpty()) {
        // Only validate if the name is resolvable and there really are array indicies.
        return;
    }
    String name = element.getName();
    if (element instanceof ArrayableElement) {
        List<ArrayDimension> requiredDimensions = ((ArrayableElement) element).getArrayDimensions();
        if (requiredDimensions.isEmpty()) {
            error(providedRanges.get(0), "'" + name + "' is not an array");
        } else if (providedRanges.size() < requiredDimensions.size()) {
            error(providedRanges.get(providedRanges.size() - 1), "Too few array dimensions: '" + name + "' has " + requiredDimensions.size());
        } else if (providedRanges.size() > requiredDimensions.size()) {
            error(providedRanges.get(requiredDimensions.size()), "Too many array dimensions: '" + name + "' has " + requiredDimensions.size());
        } else {
            for (int i = 0; i < providedRanges.size(); i++) {
                ArrayRange providedRange = providedRanges.get(i);
                if (providedRange.getLowerBound() == 0) {
                    error("Array indices start at 1", providedRange, Aadl2Package.eINSTANCE.getArrayRange_LowerBound(), ARRAY_LOWER_BOUND_IS_ZERO);
                }
                // If the upper is zero, then we have an index. Otherwise, we have a range.
                if (providedRange.getUpperBound() != 0) {
                    if (providedRange.getLowerBound() > providedRange.getUpperBound()) {
                        error("Range lower bound is greater than upper bound", providedRange, null, ARRAY_RANGE_UPPER_LESS_THAN_LOWER);
                    }
                    if (EcoreUtil2.getContainerOfType(pathElement, ReferenceValue.class) != null) {
                        warning(providedRange, "Array ranges in reference values are not property instantiated");
                    }
                }
                ArrayDimension requiredDimension = requiredDimensions.get(i);
                if (requiredDimension.getSize() == null) {
                    error(providedRange, "'" + name + "' does not have an array size");
                } else {
                    ArraySizeProperty sizeProperty = requiredDimension.getSize().getSizeProperty();
                    OptionalLong size = OptionalLong.empty();
                    /*
						 * If the size property is null, then an integer literal was specified for the size.
						 * If the size property is not null, but is a proxy, then the property could not be resolved.
						 */
                    if (sizeProperty == null) {
                        size = OptionalLong.of(requiredDimension.getSize().getSize());
                    } else if (!sizeProperty.eIsProxy()) {
                        PropertyExpression constantValue = ((PropertyConstant) sizeProperty).getConstantValue();
                        if (constantValue instanceof IntegerLiteral) {
                            size = OptionalLong.of(((IntegerLiteral) constantValue).getValue());
                        }
                    }
                    size.ifPresent(requiredSize -> {
                        // If the upper is zero, then we have an index. Otherwise, we have a range.
                        if (providedRange.getUpperBound() == 0) {
                            long index = providedRange.getLowerBound();
                            if (index > requiredSize) {
                                error("Index is greater than array size " + requiredSize, providedRange, Aadl2Package.eINSTANCE.getArrayRange_LowerBound(), ARRAY_INDEX_GREATER_THAN_MAXIMUM, Long.toString(requiredSize));
                            }
                        } else if (providedRange.getUpperBound() > requiredSize) {
                            error("Upper bound is greater than array size " + requiredSize, providedRange, Aadl2Package.eINSTANCE.getArrayRange_UpperBound(), ARRAY_RANGE_UPPER_GREATER_THAN_MAXIMUM, Long.toString(requiredSize));
                        }
                    });
                }
            }
        }
    } else {
        error(providedRanges.get(0), "'" + name + "' is not an array");
    }
}
Also used : ReferenceValue(org.osate.aadl2.ReferenceValue) ArrayRange(org.osate.aadl2.ArrayRange) AadlString(org.osate.aadl2.AadlString) OptionalLong(java.util.OptionalLong) PropertyExpression(org.osate.aadl2.PropertyExpression) ArrayableElement(org.osate.aadl2.ArrayableElement) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) ArrayDimension(org.osate.aadl2.ArrayDimension) IntegerLiteral(org.osate.aadl2.IntegerLiteral) ArraySizeProperty(org.osate.aadl2.ArraySizeProperty) Check(org.eclipse.xtext.validation.Check)

Aggregations

PropertyExpression (org.osate.aadl2.PropertyExpression)400 Property (org.osate.aadl2.Property)295 PropertyNotPresentException (org.osate.aadl2.properties.PropertyNotPresentException)246 ListValue (org.osate.aadl2.ListValue)88 BasicProperty (org.osate.aadl2.BasicProperty)51 PropertyAssociation (org.osate.aadl2.PropertyAssociation)41 TimeUnits (org.osate.aadl2.contrib.aadlproject.TimeUnits)40 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)34 PropertyLookupException (org.osate.aadl2.properties.PropertyLookupException)34 IntegerLiteral (org.osate.aadl2.IntegerLiteral)33 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)31 InstanceReferenceValue (org.osate.aadl2.instance.InstanceReferenceValue)31 NamedValue (org.osate.aadl2.NamedValue)26 PropertyConstant (org.osate.aadl2.PropertyConstant)26 ArrayList (java.util.ArrayList)25 ClassifierValue (org.osate.aadl2.ClassifierValue)25 EnumerationLiteral (org.osate.aadl2.EnumerationLiteral)25 NamedElement (org.osate.aadl2.NamedElement)25 StringLiteral (org.osate.aadl2.StringLiteral)25 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)23