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));
}
}
}
}
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();
}
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;
}
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;
}
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();
});
}
Aggregations