Search in sources :

Example 11 with ConditionElement

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

the class PropagateErrorSources method processTransition.

private void processTransition(ComponentInstance ci, ErrorBehaviorEvent event, TypeToken eventtype, ErrorBehaviorTransition trans, ConditionElement conditionElement, String componentText, HashMultimap<ErrorPropagation, String> handledPropagations) {
    EventOrPropagation eop = EMV2Util.getErrorEventOrPropagation(conditionElement);
    TypeSet constraint = conditionElement.getConstraint();
    if (eop instanceof ErrorPropagation) {
        return;
    }
    if (eop.getName().equalsIgnoreCase(event.getName())) {
        // match the event
        if (eventtype != null && constraint != null && !EMV2TypeSetUtil.contains(constraint, eventtype)) {
            return;
        }
        ErrorBehaviorState targetstate = trans.getTarget();
        TypeSet statetype = null;
        if (targetstate.getTypeSet() != null) {
            statetype = trans.getTargetToken();
        }
        // we have the state and possibly a type
        for (OutgoingPropagationCondition opc : EMV2Util.getAllOutgoingPropagationConditions(ci)) {
            if (EMV2TypeSetUtil.isNoError(opc.getTypeToken()) || opc.getCondition() != null) {
                continue;
            }
            if (opc.isAllStates() || (opc.getState() != null && targetstate.getName().equalsIgnoreCase(opc.getState().getName()))) {
                // either typeless state or type is contained in opc type constraint on state
                TypeSet statetypeconstraint = opc.getTypeTokenConstraint();
                if (statetypeconstraint == null || statetype == null || EMV2TypeSetUtil.contains(statetypeconstraint, statetype)) {
                    ErrorTypes outtype = opc.getTypeToken();
                    if (outtype == null) {
                        outtype = statetype;
                    }
                    if (opc.isAllPropagations()) {
                        Collection<ErrorPropagation> oeps = EMV2Util.getAllOutgoingErrorPropagations(ci.getComponentClassifier());
                        for (ErrorPropagation ep : oeps) {
                            if (outtype == null) {
                                if (eventtype != null) {
                                    traceErrorPaths(ci, ep, eventtype, 2, componentText + ", " + "error event " + event.getName() + EMV2Util.getPrintName(eventtype));
                                    handledPropagations.put(ep, EMV2Util.getPrintName(eventtype));
                                }
                            } else {
                                EList<TypeToken> result = EMV2TypeSetUtil.generateAllLeafTypeTokens((TypeSet) outtype, EMV2Util.getUseTypes(opc));
                                for (TypeToken tt : result) {
                                    traceErrorPaths(ci, ep, tt, 2, componentText + ", " + "error event " + event.getName() + EMV2Util.getPrintName(eventtype));
                                    handledPropagations.put(ep, EMV2Util.getPrintName(tt));
                                }
                            }
                        }
                    } else {
                        ErrorPropagation ep = opc.getOutgoing();
                        if (outtype == null) {
                            if (eventtype != null) {
                                traceErrorPaths(ci, ep, eventtype, 2, componentText + ", " + "error event " + event.getName() + EMV2Util.getPrintName(eventtype));
                                handledPropagations.put(ep, EMV2Util.getPrintName(eventtype));
                            }
                        } else {
                            EList<TypeToken> result = EMV2TypeSetUtil.generateAllLeafTypeTokens((TypeSet) outtype, EMV2Util.getUseTypes(opc));
                            for (TypeToken tt : result) {
                                traceErrorPaths(ci, ep, tt, 2, componentText + ", " + "error event " + event.getName() + EMV2Util.getPrintName(eventtype));
                                handledPropagations.put(ep, EMV2Util.getPrintName(tt));
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : ErrorBehaviorState(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState) TypeToken(org.osate.xtext.aadl2.errormodel.errorModel.TypeToken) TypeSet(org.osate.xtext.aadl2.errormodel.errorModel.TypeSet) EventOrPropagation(org.osate.xtext.aadl2.errormodel.errorModel.EventOrPropagation) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation) OutgoingPropagationCondition(org.osate.xtext.aadl2.errormodel.errorModel.OutgoingPropagationCondition) ErrorTypes(org.osate.xtext.aadl2.errormodel.errorModel.ErrorTypes)

Example 12 with ConditionElement

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

the class EMV2Util method errorConditionContainsIncomingPropagation.

/**
 * Return true if a ConditionExpression object contains a reference to a specific error propagation.
 * In fact, we are looking for an incoming error propagation that may trigger a condition
 * (for example, switching to a state, propagating an error, etc.
 *
 * @param conditionExpression : the conditionExpression that may contain a reference to the error propagation
 * @param errorPropagation    : the incoming propagation we are looking for as a referenced condition
 * @return if the conditionExpression contains a reference (either with a or or and) to the error propagation passed as the second parameter.
 */
public static boolean errorConditionContainsIncomingPropagation(ConditionExpression conditionExpression, ErrorPropagation errorPropagation) {
    boolean result = false;
    if (conditionExpression instanceof ConditionElement) {
        ConditionElement ce = (ConditionElement) conditionExpression;
        NamedElement eop = getErrorModelElement(ce);
        if (eop instanceof ErrorPropagation) {
            if (areEquivalent((ErrorPropagation) eop, errorPropagation)) {
                return true;
            }
        }
    }
    if (conditionExpression instanceof AndExpressionImpl) {
        AndExpressionImpl ae = (AndExpressionImpl) conditionExpression;
        for (ConditionExpression ce : ae.getOperands()) {
            if (errorConditionContainsIncomingPropagation(ce, errorPropagation)) {
                result = true;
            }
        }
    }
    if (conditionExpression instanceof OrExpressionImpl) {
        OrExpressionImpl oe = (OrExpressionImpl) conditionExpression;
        for (ConditionExpression ce : oe.getOperands()) {
            if (errorConditionContainsIncomingPropagation(ce, errorPropagation)) {
                result = true;
            }
        }
    }
    return result;
}
Also used : SConditionElement(org.osate.xtext.aadl2.errormodel.errorModel.SConditionElement) ConditionElement(org.osate.xtext.aadl2.errormodel.errorModel.ConditionElement) AndExpressionImpl(org.osate.xtext.aadl2.errormodel.errorModel.impl.AndExpressionImpl) ConditionExpression(org.osate.xtext.aadl2.errormodel.errorModel.ConditionExpression) OrExpressionImpl(org.osate.xtext.aadl2.errormodel.errorModel.impl.OrExpressionImpl) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement)

Example 13 with ConditionElement

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

the class EMV2Util method getSubcomponents.

public static EList<SubcomponentElement> getSubcomponents(SConditionElement conditionElement) {
    final EList<SubcomponentElement> list = new BasicEList<>();
    for (QualifiedErrorBehaviorState current = conditionElement.getQualifiedState(); current.getSubcomponent() != null; ) {
        list.add(current.getSubcomponent());
        current = current.getNext();
    }
    return list;
}
Also used : SubcomponentElement(org.osate.xtext.aadl2.errormodel.errorModel.SubcomponentElement) BasicEList(org.eclipse.emf.common.util.BasicEList) QualifiedErrorBehaviorState(org.osate.xtext.aadl2.errormodel.errorModel.QualifiedErrorBehaviorState)

Example 14 with ConditionElement

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

the class EMV2Util method getErrorModelElement.

/**
 * Get the error model element pointed to by the EMV2Path.
 * An error model element can be ErrorSource, ErrorSink, ErrorPath, ErrorPropagaiton, ErrorState,
 * ErrorBehaviorEvent (ErrorEvent, RecoverEvent, RepairEvent), ErrorBehaviorTransition
 * This works for condition elements (ConditionElement, SConditionElement)
 * @param epath EMV2Path
 * @return NamedElement
 */
public static NamedElement getErrorModelElement(EMV2Path epath) {
    if (epath == null) {
        return null;
    }
    EMV2PathElement target = getLast(epath.getEmv2Target());
    if (target.getNamedElement() instanceof ErrorTypes) {
        EObject prev = target.eContainer();
        if (prev instanceof EMV2PathElement) {
            target = (EMV2PathElement) prev;
        } else {
            return null;
        }
    }
    NamedElement prop = target.getNamedElement();
    if (prop != null) {
        return prop;
    }
    String kind = target.getEmv2PropagationKind();
    Classifier cxtcl = EMV2Util.getAssociatedClassifier(epath);
    if (target.eContainer() instanceof EMV2PathElement) {
        // should be a subcomponent reference
        NamedElement cxt = ((EMV2PathElement) target.eContainer()).getNamedElement();
        if (cxt instanceof Subcomponent) {
            cxtcl = ((Subcomponent) cxt).getAllClassifier();
        }
    } else {
        if (epath.getContainmentPath() != null) {
            ContainmentPathElement last = getLast(epath.getContainmentPath());
            if (last.getNamedElement() instanceof Subcomponent) {
                cxtcl = ((Subcomponent) last.getNamedElement()).getAllClassifier();
            }
        }
    }
    ErrorPropagation ep = findErrorPropagation(cxtcl, kind, DirectionType.IN);
    if (ep == null) {
        ep = findErrorPropagation(cxtcl, kind, DirectionType.OUT);
    }
    return ep;
}
Also used : EMV2PathElement(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PathElement) EObject(org.eclipse.emf.ecore.EObject) Subcomponent(org.osate.aadl2.Subcomponent) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation) Classifier(org.osate.aadl2.Classifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) ErrorTypes(org.osate.xtext.aadl2.errormodel.errorModel.ErrorTypes)

Example 15 with ConditionElement

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

the class EMV2Util method isEqual.

/**
 * Determine if the two expressions are the same.
 * Compare operators and compare referenced elements by pathname
 * @param ce1
 * @param ce2
 * @return
 */
public static boolean isEqual(ConditionExpression ce1, ConditionExpression ce2) {
    if ((ce1 == null) && (ce2 == null)) {
        return true;
    }
    if (ce1 == null) {
        return false;
    }
    if (ce2 == null) {
        return false;
    }
    if (ce1.getClass() != ce2.getClass()) {
        return false;
    }
    // They are the same class, so we test for only one being a certain class
    if (ce1 instanceof ConditionElement) {
        ConditionElement element1 = (ConditionElement) ce1;
        ConditionElement element2 = (ConditionElement) ce2;
        return (getPathNameWithoutType(element1.getQualifiedErrorPropagationReference().getEmv2Target()).equalsIgnoreCase(getPathNameWithoutType(element2.getQualifiedErrorPropagationReference().getEmv2Target())));
    }
    if (ce1 instanceof AndExpression) {
        AndExpression expr1 = (AndExpression) ce1;
        AndExpression expr2 = (AndExpression) ce2;
        if (expr1.getOperands().size() != expr2.getOperands().size()) {
            return false;
        }
        for (int i = 0; i < expr1.getOperands().size(); i++) {
            if (!isEqual(expr1.getOperands().get(i), expr2.getOperands().get(i))) {
                return false;
            }
        }
        return true;
    }
    if (ce1 instanceof OrExpression) {
        OrExpression expr1 = (OrExpression) ce1;
        OrExpression expr2 = (OrExpression) ce2;
        if (expr1.getOperands().size() != expr2.getOperands().size()) {
            return false;
        }
        for (int i = 0; i < expr1.getOperands().size(); i++) {
            if (!isEqual(expr1.getOperands().get(i), expr2.getOperands().get(i))) {
                return false;
            }
        }
        return true;
    }
    OsateDebug.osateDebug("[EMV2Util] isEqual does not handled this class type " + ce1 + "|" + ce2);
    return false;
}
Also used : SConditionElement(org.osate.xtext.aadl2.errormodel.errorModel.SConditionElement) ConditionElement(org.osate.xtext.aadl2.errormodel.errorModel.ConditionElement) AndExpression(org.osate.xtext.aadl2.errormodel.errorModel.AndExpression) OrExpression(org.osate.xtext.aadl2.errormodel.errorModel.OrExpression) PropagationPoint(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPoint) QualifiedPropagationPoint(org.osate.xtext.aadl2.errormodel.errorModel.QualifiedPropagationPoint)

Aggregations

ErrorPropagation (org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation)10 ConditionElement (org.osate.xtext.aadl2.errormodel.errorModel.ConditionElement)9 TypeSet (org.osate.xtext.aadl2.errormodel.errorModel.TypeSet)9 ErrorBehaviorState (org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState)8 SConditionElement (org.osate.xtext.aadl2.errormodel.errorModel.SConditionElement)6 TypeToken (org.osate.xtext.aadl2.errormodel.errorModel.TypeToken)6 EObject (org.eclipse.emf.ecore.EObject)5 ConditionExpression (org.osate.xtext.aadl2.errormodel.errorModel.ConditionExpression)5 ErrorEvent (org.osate.xtext.aadl2.errormodel.errorModel.ErrorEvent)5 EventOrPropagation (org.osate.xtext.aadl2.errormodel.errorModel.EventOrPropagation)5 NamedElement (org.osate.aadl2.NamedElement)4 AndExpression (org.osate.xtext.aadl2.errormodel.errorModel.AndExpression)4 ErrorBehaviorTransition (org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition)4 OrExpression (org.osate.xtext.aadl2.errormodel.errorModel.OrExpression)4 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)3 AllExpression (org.osate.xtext.aadl2.errormodel.errorModel.AllExpression)3 EMV2PathElement (org.osate.xtext.aadl2.errormodel.errorModel.EMV2PathElement)3 OrmoreExpression (org.osate.xtext.aadl2.errormodel.errorModel.OrmoreExpression)3 QualifiedErrorBehaviorState (org.osate.xtext.aadl2.errormodel.errorModel.QualifiedErrorBehaviorState)3 LinkedList (java.util.LinkedList)2