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