Search in sources :

Example 1 with EMV2PropertyAssociation

use of org.osate.xtext.aadl2.errormodel.errorModel.EMV2PropertyAssociation in project osate2 by osate.

the class ErrorModelValidator method checkAssociationAppliesTo.

private void checkAssociationAppliesTo(final EMV2PropertyAssociation pa) {
    final Property pn = pa.getProperty();
    final EList<EMV2Path> appliesTo = pa.getEmv2Path();
    if (appliesTo == null || appliesTo.size() == 0) {
        Element element = pa.getOwner();
        if (element instanceof NamedElement) {
            final boolean applies = ((NamedElement) element).acceptsProperty(pn);
            if (!applies) {
                error(pa, "Property " + pa.getProperty().getQualifiedName() + " does not apply to " + ((NamedElement) element).getName());
            // error(pa,
            // "Property " + pa.getQualifiedName() +
            // " does not apply to " + element.eClass().getName());
            }
        }
    } else {
        for (EMV2Path cna : appliesTo) {
            EMV2PathElement path = cna.getEmv2Target();
            if (path != null) {
                // only the last value is interesting to us
                final EMV2PathElement ph = EMV2Util.getLast(path);
                NamedElement ne = ph.getNamedElement();
                if (ne instanceof ErrorTypes) {
                    ErrorTypes et = (ErrorTypes) ne;
                    EObject prev = ph.eContainer();
                    if (prev instanceof EMV2PathElement) {
                        ne = ((EMV2PathElement) prev).getNamedElement();
                        boolean noMatch = false;
                        if (ne instanceof ErrorBehaviorState) {
                            TypeSet ts = ((ErrorBehaviorState) ne).getTypeSet();
                            noMatch = ts != null && !EMV2TypeSetUtil.contains(ts, et);
                        } else if (ne instanceof ErrorPropagation) {
                            String epname = EMV2Util.getPrintName((ErrorPropagation) ne);
                            EList<ErrorPropagation> eplist = EMV2Util.getContainingErrorModelSubclause(ne).getPropagations();
                            Boolean foundType = false;
                            for (ErrorPropagation ep : eplist) {
                                if (epname.equalsIgnoreCase(EMV2Util.getPrintName(ep))) {
                                    TypeSet ts = ep.getTypeSet();
                                    if (EMV2TypeSetUtil.contains(ts, et)) {
                                        foundType = true;
                                        break;
                                    }
                                }
                            }
                            noMatch = !foundType;
                        } else if (ne instanceof ErrorEvent) {
                            TypeSet ts = ((ErrorEvent) ne).getTypeSet();
                            noMatch = ts != null && !EMV2TypeSetUtil.contains(ts, et);
                        }
                        if (noMatch) {
                            error(pa, "Property " + pa.getProperty().getQualifiedName() + " applies to refers to type " + EMV2Util.getPrintName(et) + " not contained in type set of error propagation " + EMV2Util.getPrintName(ne));
                        }
                    }
                }
                if (!Aadl2Util.isNull(ne)) {
                    final boolean applies = ph.getNamedElement().acceptsProperty(pn);
                    if (!applies) {
                        error(pa, "Property " + pa.getProperty().getQualifiedName() + " does not apply to " + EMV2Util.getPrintName(cna));
                    }
                }
            }
        }
    }
}
Also used : EMV2PathElement(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PathElement) ErrorBehaviorState(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) Element(org.osate.aadl2.Element) EMV2PathElement(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PathElement) SConditionElement(org.osate.xtext.aadl2.errormodel.errorModel.SConditionElement) ConditionElement(org.osate.xtext.aadl2.errormodel.errorModel.ConditionElement) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) ErrorTypes(org.osate.xtext.aadl2.errormodel.errorModel.ErrorTypes) EMV2Path(org.osate.xtext.aadl2.errormodel.errorModel.EMV2Path) BasicEList(org.eclipse.emf.common.util.BasicEList) EList(org.eclipse.emf.common.util.EList) EObject(org.eclipse.emf.ecore.EObject) TypeSet(org.osate.xtext.aadl2.errormodel.errorModel.TypeSet) ErrorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorEvent) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation) Property(org.osate.aadl2.Property) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement)

Example 2 with EMV2PropertyAssociation

use of org.osate.xtext.aadl2.errormodel.errorModel.EMV2PropertyAssociation 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 3 with EMV2PropertyAssociation

use of org.osate.xtext.aadl2.errormodel.errorModel.EMV2PropertyAssociation in project osate2 by osate.

the class EMV2Properties method isErrorModelElementProperty.

/**
 * return the containment path if the stack combined with the target and optionally the type set match the containment path of a property association.
 * It is sufficient for one of the paths in the PA to match.
 * ciStack represents the path from the context of the PA to the component instance whose property we want to retrieve
 * The desired type set ts must be contained in the type set named in the containment path
 * @param propertyAssociation PropertyAssociation that is the candidate
 * @param ciStack (can be null or empty) ComponentInstance in instance model hierarchy with the error model element, whose property we are retrieving (or null)
 * @param target Element the target object in the error model whose property we retrieve
 * @param ts type set that must contain the last element if it is a type
 * @return ContainedNamedElement the containment path that matches
 */
public static EMV2PropertyAssociation isErrorModelElementProperty(EMV2PropertyAssociation propertyAssociation, NamedElement target, Stack<NamedElement> ciStack, ErrorTypes ts) {
    boolean matchStack = false;
    EList<EMV2Path> applies = propertyAssociation.getEmv2Path();
    for (EMV2Path emv2Path : applies) {
        ContainmentPathElement cp = emv2Path.getContainmentPath();
        if (cp != null) {
            matchStack = matchCIStack(ciStack, cp);
        } else {
            matchStack = matchCIStack(ciStack, emv2Path.getEmv2Target());
        }
        if (matchStack) {
            // we are past the component portion of the path
            String targetName = EMV2Util.getPrintName(target);
            NamedElement pathTargetEME = EMV2Util.getErrorModelElement(emv2Path);
            String pathName = EMV2Util.getPrintName(pathTargetEME);
            if (targetName.equalsIgnoreCase(pathName)) {
                ErrorTypes typeelement = EMV2Util.getErrorType(emv2Path);
                if (typeelement != null && ts != null) {
                    // check to see if the desired ts is contained in the PA containment path
                    if (EMV2TypeSetUtil.contains(ts, typeelement) || EMV2TypeSetUtil.contains(typeelement, ts)) {
                        return propertyAssociation;
                    }
                } else {
                    return propertyAssociation;
                }
            }
        }
    }
    return null;
}
Also used : EMV2Path(org.osate.xtext.aadl2.errormodel.errorModel.EMV2Path) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) NamedElement(org.osate.aadl2.NamedElement) ErrorTypes(org.osate.xtext.aadl2.errormodel.errorModel.ErrorTypes)

Example 4 with EMV2PropertyAssociation

use of org.osate.xtext.aadl2.errormodel.errorModel.EMV2PropertyAssociation in project osate2 by osate.

the class EMV2Properties method getMatchingPropertiesInList.

/**
 * return containment path of all PA in list that match the target.
 * Should be only one matching.
 * @param props list of property associations from the properties section in the error model of ci
 * @param propertyName name of property we are looking for
 * @param target the error model element
 * @param ciStack stack of nested CI below the ci of the props; those names may show up in the path
 * @return list of paths
 */
public static List<EMV2PropertyAssociation> getMatchingPropertiesInList(List<EMV2PropertyAssociation> props, String propertyName, NamedElement target, Stack<NamedElement> ciStack, ErrorTypes ts) {
    if (props.isEmpty()) {
        return Collections.emptyList();
    }
    List<EMV2PropertyAssociation> result = new ArrayList<EMV2PropertyAssociation>();
    for (EMV2PropertyAssociation propertyAssociation : props) {
        Property prop = propertyAssociation.getProperty();
        String name = prop.getQualifiedName();
        if (propertyName.equalsIgnoreCase(name)) {
            EMV2PropertyAssociation res = isErrorModelElementProperty(propertyAssociation, target, ciStack, ts);
            if (res != null) {
                result.add(res);
            }
        }
    }
    return result;
}
Also used : EMV2PropertyAssociation(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PropertyAssociation) ArrayList(java.util.ArrayList) Property(org.osate.aadl2.Property)

Example 5 with EMV2PropertyAssociation

use of org.osate.xtext.aadl2.errormodel.errorModel.EMV2PropertyAssociation in project osate2 by osate.

the class EMV2Properties method getFailure.

/**
 * @param element - the EMV2 element that referes to the artifact
 * @param relatedComponent - the component the component (instance, subcomponent or classifier) that have the property association
 * @return - the text related to the failure part of the hazards property. Null if not defined
 */
public static String getFailure(NamedElement element, NamedElement relatedComponent) {
    TypeSet ts = null;
    if (element instanceof ErrorBehaviorState) {
        ts = ((ErrorBehaviorState) element).getTypeSet();
    }
    if (element instanceof ErrorPropagation) {
        ts = ((ErrorPropagation) element).getTypeSet();
    }
    if (element instanceof ErrorEvent) {
        ts = ((ErrorEvent) element).getTypeSet();
    }
    List<EMV2PropertyAssociation> PA = EMV2Properties.getHazardsProperty(relatedComponent, element, ts);
    if (PA.isEmpty()) {
        return null;
    }
    // XXX TODO we may get more than one back, one each for different types
    PropertyExpression val = getPropertyValue(PA.get(0));
    if (val instanceof RecordValue) {
        RecordValue rv = (RecordValue) val;
        EList<BasicPropertyAssociation> fields = rv.getOwnedFieldValues();
        BasicPropertyAssociation xref = GetProperties.getRecordField(fields, "failure");
        if (xref != null) {
            PropertyExpression peVal = getPropertyValue(xref);
            if (peVal instanceof StringLiteral) {
                return ((StringLiteral) peVal).getValue();
            }
        }
    }
    if (val instanceof ListValue) {
        ListValue lv = (ListValue) val;
        for (PropertyExpression pe : lv.getOwnedListElements()) {
            if (pe instanceof RecordValue) {
                RecordValue rv = (RecordValue) pe;
                EList<BasicPropertyAssociation> fields = rv.getOwnedFieldValues();
                BasicPropertyAssociation xref = GetProperties.getRecordField(fields, "failure");
                if (xref != null) {
                    PropertyExpression peVal = getPropertyValue(xref);
                    if (peVal instanceof StringLiteral) {
                        return ((StringLiteral) peVal).getValue();
                    }
                }
            }
        }
    }
    return null;
}
Also used : ErrorBehaviorState(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState) StringLiteral(org.osate.aadl2.StringLiteral) TypeSet(org.osate.xtext.aadl2.errormodel.errorModel.TypeSet) ListValue(org.osate.aadl2.ListValue) ErrorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorEvent) EMV2PropertyAssociation(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PropertyAssociation) RecordValue(org.osate.aadl2.RecordValue) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation) PropertyExpression(org.osate.aadl2.PropertyExpression) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation)

Aggregations

EMV2PropertyAssociation (org.osate.xtext.aadl2.errormodel.errorModel.EMV2PropertyAssociation)13 TypeSet (org.osate.xtext.aadl2.errormodel.errorModel.TypeSet)6 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)5 NamedElement (org.osate.aadl2.NamedElement)5 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)4 ListValue (org.osate.aadl2.ListValue)4 RecordValue (org.osate.aadl2.RecordValue)4 EMV2Path (org.osate.xtext.aadl2.errormodel.errorModel.EMV2Path)4 EMV2PathElement (org.osate.xtext.aadl2.errormodel.errorModel.EMV2PathElement)4 EList (org.eclipse.emf.common.util.EList)3 Element (org.osate.aadl2.Element)3 Property (org.osate.aadl2.Property)3 PropertyExpression (org.osate.aadl2.PropertyExpression)3 StringLiteral (org.osate.aadl2.StringLiteral)3 Subcomponent (org.osate.aadl2.Subcomponent)3 ConditionElement (org.osate.xtext.aadl2.errormodel.errorModel.ConditionElement)3 ErrorBehaviorState (org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState)3 ErrorEvent (org.osate.xtext.aadl2.errormodel.errorModel.ErrorEvent)3 ErrorModelSubclause (org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelSubclause)3 ErrorPropagation (org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation)3