Search in sources :

Example 6 with ContainmentPathElement

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

the class EMV2Util method getContainmentErrorType.

/**
 * get error type (last element of containment path, if present
 * Otherwise return null
 * @param containedNamedElement Containment path
 * @return EList<ErrorType>
 */
public static ErrorType getContainmentErrorType(ContainedNamedElement containedNamedElement) {
    EList<ContainmentPathElement> cpes = containedNamedElement.getContainmentPathElements();
    if (!cpes.isEmpty()) {
        ContainmentPathElement cpe = cpes.get(cpes.size() - 1);
        NamedElement appliestome = cpe.getNamedElement();
        if (appliestome instanceof ErrorType) {
            return ((ErrorType) appliestome);
        }
    }
    return null;
}
Also used : ErrorType(org.osate.xtext.aadl2.errormodel.errorModel.ErrorType) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement)

Example 7 with ContainmentPathElement

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

the class EMV2Util method getLastComponentInstance.

/**
 * get the last component instance in the epath relative to the component instance root
 * Returns root if the path does not include subcomponents.
 * Returns null if the component instance is not found, i.e., the path subcomponent references cannot be found in the
 * component instance hierarchy.
 * @param epath EMV2Path that includes EMV2PathElements pointing to subcomponents.
 * @param root ComponentInstance that is the root of the subcomponent section of the path
 * @return ComponentInstance
 */
public static ComponentInstance getLastComponentInstance(EMV2Path epath, ComponentInstance root) {
    ComponentInstance result = root;
    if (epath.getContainmentPath() != null) {
        // handle paths that come from the EMV2PropertyAssociation with the new syntax for the core path
        ContainmentPathElement ce = epath.getContainmentPath();
        while (ce != null && result != null) {
            if (ce.getNamedElement() instanceof Subcomponent) {
                Subcomponent sub = (Subcomponent) ce.getNamedElement();
                result = result.findSubcomponentInstance(sub);
            }
            ce = ce.getPath();
        }
        return result;
    }
    EMV2PathElement epe = epath.getEmv2Target();
    while (epe != null && result != null) {
        if (epe.getNamedElement() instanceof Subcomponent) {
            Subcomponent sub = (Subcomponent) epe.getNamedElement();
            result = result.findSubcomponentInstance(sub);
        }
        epe = epe.getPath();
    }
    return result;
}
Also used : EMV2PathElement(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PathElement) Subcomponent(org.osate.aadl2.Subcomponent) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement)

Example 8 with ContainmentPathElement

use of org.osate.aadl2.ContainmentPathElement 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 9 with ContainmentPathElement

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

the class PropertiesValidator method checkConstantProperty.

protected void checkConstantProperty(PropertyAssociation assoc) {
    Property property = assoc.getProperty();
    if (!property.eIsProxy()) {
        EList<ContainedNamedElement> appliesTos = assoc.getAppliesTos();
        if (appliesTos == null || appliesTos.isEmpty()) {
            NamedElement holder = (NamedElement) assoc.getOwner();
            if (holder.acceptsProperty(property)) {
                checkOverridingConstant(holder, assoc);
            }
        } else {
            for (ContainedNamedElement cne : assoc.getAppliesTos()) {
                if (cne.getContainmentPathElements().size() == 1) {
                    ContainmentPathElement cpe = cne.getContainmentPathElements().get(0);
                    NamedElement ne = cpe.getNamedElement();
                    if (!ne.eIsProxy() && ne.acceptsProperty(property)) {
                        checkOverridingConstant(ne, assoc);
                    }
                }
            }
        }
    }
}
Also used : ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) ArraySizeProperty(org.osate.aadl2.ArraySizeProperty) Property(org.osate.aadl2.Property) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement)

Example 10 with ContainmentPathElement

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

the class PropertiesValidator method getLastSubcomponent.

public Subcomponent getLastSubcomponent(ContainedNamedElement cne) {
    Subcomponent subComponent = null;
    List<ContainmentPathElement> cpes = cne.getContainmentPathElements();
    for (int i = cpes.size() - 1; i > -1; i--) {
        ContainmentPathElement cpe = cpes.get(i);
        if (cpe.getNamedElement() instanceof Subcomponent) {
            subComponent = (Subcomponent) cpe.getNamedElement();
            return subComponent;
        }
    }
    return subComponent;
}
Also used : Subcomponent(org.osate.aadl2.Subcomponent) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement)

Aggregations

ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)52 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)27 NamedElement (org.osate.aadl2.NamedElement)24 PropertyAssociation (org.osate.aadl2.PropertyAssociation)19 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)15 ReferenceValue (org.osate.aadl2.ReferenceValue)14 Property (org.osate.aadl2.Property)12 Subcomponent (org.osate.aadl2.Subcomponent)12 IntegerLiteral (org.osate.aadl2.IntegerLiteral)11 ListValue (org.osate.aadl2.ListValue)11 NamedValue (org.osate.aadl2.NamedValue)11 ArrayRange (org.osate.aadl2.ArrayRange)10 RangeValue (org.osate.aadl2.RangeValue)10 RealLiteral (org.osate.aadl2.RealLiteral)10 RecordValue (org.osate.aadl2.RecordValue)10 BooleanLiteral (org.osate.aadl2.BooleanLiteral)9 ClassifierValue (org.osate.aadl2.ClassifierValue)9 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)9 StringLiteral (org.osate.aadl2.StringLiteral)9 EObject (org.eclipse.emf.ecore.EObject)7