Search in sources :

Example 1 with ErrorBehaviorStateMachine

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

the class ErrorModelValidator method checkTransitionTargetTriggerTypes.

private void checkTransitionTargetTriggerTypes(ErrorBehaviorTransition ebt) {
    if (ebt.isSteadyState()) {
        return;
    }
    ErrorBehaviorState targetstate = ebt.getTarget();
    if (targetstate != null) {
        TypeSet targetTS = targetstate.getTypeSet();
        if (targetTS == null) {
            return;
        }
        TypeSet tt = ebt.getTargetToken();
        if (tt != null) {
            return;
        }
        // state requires a type
        if (ebt.getCondition() instanceof ConditionElement) {
            // either the event must be typed or the source state must be typed
            EventOrPropagation ep = EMV2Util.getErrorEventOrPropagation((ConditionElement) ebt.getCondition());
            if (ep instanceof ErrorEvent) {
                ErrorEvent ev = (ErrorEvent) ep;
                TypeSet evTS = ev.getTypeSet();
                if (evTS == null) {
                    TypeSet srcTS = ebt.getSource().getTypeSet();
                    if (srcTS == null) {
                        error(ebt, "Target state " + targetstate.getName() + " requires type but the triggering error event " + EMV2Util.getPrintName(ev) + " or source state " + EMV2Util.getPrintName(ebt.getSource()) + " does not have a type");
                    } else {
                        // source typeset must be contained in target type set
                        if (!EMV2TypeSetUtil.contains(targetTS, srcTS)) {
                            error(ebt, "Target state " + targetstate.getName() + " does not contain types of source state " + EMV2Util.getPrintName(ebt.getSource()));
                        }
                    }
                } else {
                    // error event has type. It must be consistent with the expected state type
                    if (!EMV2TypeSetUtil.contains(targetTS, evTS)) {
                        error(ebt, "Target state " + targetstate.getName() + " does not contain types of error event " + EMV2Util.getPrintName(ev));
                    }
                }
            } else if (ep instanceof ErrorPropagation) {
                ErrorPropagation eprop = (ErrorPropagation) ep;
                // we can check type compatibility
                if (!EMV2TypeSetUtil.contains(targetTS, eprop.getTypeSet())) {
                    error(ebt, "Target state " + targetstate.getName() + " does not contain types of error propagation " + EMV2Util.getPrintName(eprop));
                }
            }
        } else {
            // full condition expression
            // type transformation & events must be typed
            ErrorBehaviorStateMachine ebsm = (ErrorBehaviorStateMachine) targetstate.eContainer();
            if (ebsm.getUseTransformation().isEmpty()) {
                error(ebt, "Target state " + targetstate.getName() + " does not include a target type but requires types. For conditions on multiple elements a target type must be assigned explicitly or a type transformation must be specified in the error behavior state machine" + EMV2Util.getPrintName(ebsm));
            }
        }
    }
}
Also used : ErrorBehaviorState(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState) SConditionElement(org.osate.xtext.aadl2.errormodel.errorModel.SConditionElement) ConditionElement(org.osate.xtext.aadl2.errormodel.errorModel.ConditionElement) TypeSet(org.osate.xtext.aadl2.errormodel.errorModel.TypeSet) ErrorBehaviorStateMachine(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorStateMachine) ErrorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorEvent) EventOrPropagation(org.osate.xtext.aadl2.errormodel.errorModel.EventOrPropagation) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation)

Example 2 with ErrorBehaviorStateMachine

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

the class EMV2Util method getAllErrorBehaviorStates.

/**
 * return list of ErrorBehaviorStates including those inherited from classifiers being extended
 * @param cl Classifier
 * @return Collection<ErrorBehaviorState> list of ErrorBehaviorStates as HashMap for quick lookup of names
 */
public static Collection<ErrorBehaviorState> getAllErrorBehaviorStates(Classifier cl) {
    HashMap<String, ErrorBehaviorState> result = new LinkedHashMap<>();
    EList<ErrorModelSubclause> emslist = getAllContainingClassifierEMV2Subclauses(cl);
    for (ErrorModelSubclause errorModelSubclause : emslist) {
        ErrorBehaviorStateMachine ebsm = errorModelSubclause.getUseBehavior();
        if (ebsm != null) {
            EList<ErrorBehaviorState> eflist = ebsm.getStates();
            for (ErrorBehaviorState ebs : eflist) {
                if (!result.containsKey(ebs.getName())) {
                    result.put(ebs.getName(), ebs);
                }
            }
            return result.values();
        }
    }
    return Collections.emptyList();
}
Also used : ErrorBehaviorState(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState) QualifiedErrorBehaviorState(org.osate.xtext.aadl2.errormodel.errorModel.QualifiedErrorBehaviorState) ErrorModelSubclause(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelSubclause) ErrorBehaviorStateMachine(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorStateMachine) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with ErrorBehaviorStateMachine

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

the class EMV2Util method getAllErrorBehaviorTransitions.

/**
 * return list of ErrorBehaviorTransition including those inherited from classifiers being extended
 * @param cl Classifier
 * @param unnamed Collection of unnamed ErrorBehaviorTransition
 * @return Collection<ErrorBehaviorTransition> list of ErrorBehaviorTransition as HashMap for quick lookup of names
 */
private static HashMap<String, ErrorBehaviorTransition> getAllErrorBehaviorTransitions(Classifier cl, Collection<ErrorBehaviorTransition> unnamed) {
    HashMap<String, ErrorBehaviorTransition> result = new LinkedHashMap<>();
    EList<ErrorModelSubclause> emslist = getAllContainingClassifierEMV2Subclauses(cl);
    boolean foundEBSM = false;
    for (ErrorModelSubclause errorModelSubclause : emslist) {
        ErrorBehaviorStateMachine ebsm = errorModelSubclause.getUseBehavior();
        EList<ErrorBehaviorTransition> eflist = errorModelSubclause.getTransitions();
        for (ErrorBehaviorTransition ebt : eflist) {
            if (ebt.getName() == null) {
                unnamed.add(ebt);
            } else {
                if (!result.containsKey(ebt.getName())) {
                    result.put(ebt.getName(), ebt);
                }
            }
        }
        if (!foundEBSM && ebsm != null) {
            foundEBSM = true;
            eflist = ebsm.getTransitions();
            for (ErrorBehaviorTransition ebt : eflist) {
                if (ebt.getName() == null) {
                    unnamed.add(ebt);
                } else {
                    if (!result.containsKey(ebt.getName())) {
                        result.put(ebt.getName(), ebt);
                    }
                }
            }
        }
    }
    return result;
}
Also used : ErrorBehaviorTransition(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition) ErrorModelSubclause(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelSubclause) ErrorBehaviorStateMachine(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorStateMachine) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with ErrorBehaviorStateMachine

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

the class ErrorModelQualifiedNameProvider method getFullyQualifiedName.

// Enable to limit indexing to global items
// Duplicates checking only applies to global items
@Override
public QualifiedName getFullyQualifiedName(final EObject obj) {
    if (obj instanceof ErrorBehaviorStateMachine || obj instanceof TypeMappingSet || obj instanceof ErrorModelLibrary || obj instanceof ErrorModelSubclause || obj instanceof ErrorType || obj instanceof TypeSet || obj instanceof TypeTransformationSet) {
        /*
			 * It is important that we return null if obj is not in an
			 * AadlPackage or in a EMV2Root. This happens when serializing an
			 * aadl file with an error model annex. See EMV2AnnexUnparser. If
			 * this check is not here, then a ClassCastException occurs during
			 * serialization.
			 */
        NamedElement namedElement = (NamedElement) obj;
        NamedElement root = namedElement.getElementRoot();
        if (namedElement.getName() == null || !(root instanceof AadlPackage || root instanceof EMV2Root) || (obj instanceof ErrorModelSubclause && !(root instanceof EMV2Root))) {
            return null;
        }
        return getConverter().toQualifiedName(getTheName(namedElement));
    }
    if (obj instanceof AadlPackage) {
        return getConverter().toQualifiedName(((AadlPackage) obj).getName());
    }
    return null;
}
Also used : TypeTransformationSet(org.osate.xtext.aadl2.errormodel.errorModel.TypeTransformationSet) AadlPackage(org.osate.aadl2.AadlPackage) ErrorModelLibrary(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelLibrary) ErrorType(org.osate.xtext.aadl2.errormodel.errorModel.ErrorType) ErrorModelSubclause(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelSubclause) ErrorBehaviorStateMachine(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorStateMachine) TypeSet(org.osate.xtext.aadl2.errormodel.errorModel.TypeSet) TypeMappingSet(org.osate.xtext.aadl2.errormodel.errorModel.TypeMappingSet) NamedElement(org.osate.aadl2.NamedElement) EMV2Root(org.osate.xtext.aadl2.errormodel.errorModel.EMV2Root)

Example 5 with ErrorBehaviorStateMachine

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

the class CreateStateMachinePaletteCommand method getOperation.

@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
    return ErrorModelGeUtil.createErrorModelLibraryModifyOperation(ctx.getTarget(), lib -> {
        // Create the ErrorBehaviorStateMachine
        final ErrorBehaviorStateMachine newBehavior = ErrorModelFactory.eINSTANCE.createErrorBehaviorStateMachine();
        final String newName = ErrorModelNamingUtil.buildUniqueIdentifier(lib, "new_state_machine");
        newBehavior.setName(newName);
        // Add the new type to the error model library
        lib.getBehaviors().add(newBehavior);
        return StepResultBuilder.create().showNewBusinessObject(ctx.getTarget(), newBehavior).build();
    });
}
Also used : ErrorBehaviorStateMachine(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorStateMachine)

Aggregations

ErrorBehaviorStateMachine (org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorStateMachine)13 ErrorModelSubclause (org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelSubclause)9 Classifier (org.osate.aadl2.Classifier)4 LinkedHashMap (java.util.LinkedHashMap)3 AadlPackage (org.osate.aadl2.AadlPackage)2 ComponentClassifier (org.osate.aadl2.ComponentClassifier)2 Subcomponent (org.osate.aadl2.Subcomponent)2 ErrorBehaviorEvent (org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorEvent)2 ErrorBehaviorState (org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState)2 TypeSet (org.osate.xtext.aadl2.errormodel.errorModel.TypeSet)2 Arrays (java.util.Arrays)1 Set (java.util.Set)1 WeakHashMap (java.util.WeakHashMap)1 Function (java.util.function.Function)1 Stream (java.util.stream.Stream)1 URI (org.eclipse.emf.common.util.URI)1 EObject (org.eclipse.emf.ecore.EObject)1 EPackage (org.eclipse.emf.ecore.EPackage)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 Action (org.eclipse.xtext.Action)1