Search in sources :

Example 1 with EMV2Path

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

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

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

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

the class EMV2Util method getPrintName.

public static String getPrintName(EMV2Path ep) {
    if (ep == null) {
        return "";
    }
    EMV2PathElement epe = ep.getEmv2Target();
    if (epe == null) {
        return "";
    }
    ContainmentPathElement cpe = ep.getContainmentPath();
    String prefix;
    if (cpe == null) {
        prefix = "";
    } else {
        prefix = "^" + cpe.getNamedElement().getName();
        cpe = cpe.getPath();
    }
    while (cpe != null) {
        prefix = prefix + "." + cpe.getNamedElement().getName();
        cpe = cpe.getPath();
    }
    if (!prefix.isEmpty()) {
        prefix = prefix + '@';
    }
    if (epe.getEmv2PropagationKind() != null) {
        return prefix + epe.getEmv2PropagationKind() + (epe.getErrorType() != null ? "." + epe.getErrorType().getName() : "");
    } else {
        return getPathName(epe);
    }
}
Also used : EMV2PathElement(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PathElement) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement)

Example 5 with EMV2Path

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

the class EMV2Util method getPrintNameWithoutType.

/**
 * @deprecated Unused. Will be removed in 2.8.1
 */
@Deprecated
public static String getPrintNameWithoutType(EMV2Path ep) {
    if (ep == null) {
        return "";
    }
    EMV2PathElement epe = ep.getEmv2Target();
    if (epe == null) {
        return "";
    }
    ContainmentPathElement cpe = ep.getContainmentPath();
    if (cpe == null) {
        return getPathNameWithoutType(epe);
    }
    String prefix = "^" + cpe.getNamedElement().getName();
    while (cpe.getPath() != null) {
        cpe = cpe.getPath();
        prefix = prefix + "." + cpe.getNamedElement().getName();
    }
    if (!prefix.isEmpty()) {
        prefix = prefix + '@';
    }
    if (epe.getEmv2PropagationKind() != null) {
        return prefix + epe.getEmv2PropagationKind();
    } else {
        return getPathNameWithoutType(epe);
    }
}
Also used : EMV2PathElement(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PathElement) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement)

Aggregations

ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)8 EMV2PathElement (org.osate.xtext.aadl2.errormodel.errorModel.EMV2PathElement)7 EMV2Path (org.osate.xtext.aadl2.errormodel.errorModel.EMV2Path)6 NamedElement (org.osate.aadl2.NamedElement)4 ErrorTypes (org.osate.xtext.aadl2.errormodel.errorModel.ErrorTypes)4 TypeSet (org.osate.xtext.aadl2.errormodel.errorModel.TypeSet)4 EObject (org.eclipse.emf.ecore.EObject)3 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)3 Subcomponent (org.osate.aadl2.Subcomponent)3 ErrorBehaviorState (org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState)3 ErrorEvent (org.osate.xtext.aadl2.errormodel.errorModel.ErrorEvent)3 ErrorPropagation (org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation)3 TypeToken (org.osate.xtext.aadl2.errormodel.errorModel.TypeToken)3 EList (org.eclipse.emf.common.util.EList)2 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)2 ListValue (org.osate.aadl2.ListValue)2 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)2 RecordValue (org.osate.aadl2.RecordValue)2 AllExpression (org.osate.xtext.aadl2.errormodel.errorModel.AllExpression)2 AndExpression (org.osate.xtext.aadl2.errormodel.errorModel.AndExpression)2