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