use of org.osate.aadl2.ContainmentPathElement in project osate2 by osate.
the class AadlBaNameResolver method propertyExpressionResolver.
/**
* Resolves the property expressions used in behavior annex.
* @param p
*
* @return {@code true} if all names are resolved. {@code false} otherwise.
*/
private boolean propertyExpressionResolver(BehaviorVariable bv, Property p, PropertyExpression pe) {
QualifiedNamedElement qne = (QualifiedNamedElement) p;
String propertyName = "";
boolean hasNamespace = qne.getBaNamespace() != null;
if (hasNamespace) {
propertyName = qne.getBaNamespace().getId() + "::";
}
propertyName += qne.getBaName().getId();
boolean result = true;
if (pe instanceof DeclarativeListValue) {
ListValue dlv = (DeclarativeListValue) pe;
for (PropertyExpression peInList : dlv.getOwnedListElements()) {
result &= propertyExpressionResolver(bv, p, peInList);
}
} else if (pe instanceof IntegerLiteral) {
IntegerLiteral il = (IntegerLiteral) pe;
if (il.getUnit() != null && il.getUnit() instanceof QualifiedNamedElement) {
result &= unitResolver(il, bv, p);
}
} else if (pe instanceof RealLiteral) {
RealLiteral rl = (RealLiteral) pe;
if (rl.getUnit() != null && rl.getUnit() instanceof QualifiedNamedElement) {
result &= unitResolver(rl, bv, p);
}
} else if (pe instanceof RecordValue) {
RecordValue rv = (RecordValue) pe;
for (BasicPropertyAssociation bpa : rv.getOwnedFieldValues()) {
if (bpa instanceof DeclarativeBasicPropertyAssociation) {
DeclarativeBasicPropertyAssociation dbpa = (DeclarativeBasicPropertyAssociation) bpa;
String basicPropertyName = dbpa.getBasicPropertyName();
BasicProperty basicProp = getBasicPropertyResolver(bv, p, basicPropertyName);
if (basicProp == null) {
_errManager.error(bv, "Property field \'" + basicPropertyName + "\' of property " + propertyName + " is not found");
result = false;
}
dbpa.setProperty(basicProp);
}
}
} else if (pe instanceof RangeValue) {
RangeValue rv = (RangeValue) pe;
result &= propertyExpressionResolver(bv, p, rv.getMaximum());
result &= propertyExpressionResolver(bv, p, rv.getMinimum());
} else if (pe instanceof ReferenceValue) {
ReferenceValue rv = (ReferenceValue) pe;
Reference r = (Reference) (rv.getPath());
ContainmentPathElement firstCne = Aadl2Factory.eINSTANCE.createContainmentPathElement();
ContainmentPathElement prevCne = null;
boolean first = true;
Classifier context = _baParentContainer;
for (Identifier subPath : r.getIds()) {
ContainmentPathElement currentCne;
if (!first) {
currentCne = Aadl2Factory.eINSTANCE.createContainmentPathElement();
} else {
currentCne = firstCne;
}
first = false;
NamedElement ne = Aadl2Visitors.findSubcomponentInComponent(context, subPath.getId());
if (ne == null) {
ne = Aadl2Visitors.findFeatureInComponent(context, subPath.getId());
}
if (ne == null) {
_errManager.error(bv, "Element \'" + subPath.getId() + "\' is not found in " + context.getName() + "(property " + propertyName + ")");
result = false;
} else {
currentCne.setNamedElement(ne);
if (prevCne != null) {
prevCne.setPath(currentCne);
}
if (ne instanceof Subcomponent) {
Subcomponent sub = (Subcomponent) ne;
context = sub.getClassifier();
} else if (ne instanceof Feature) {
Feature f = (Feature) ne;
context = f.getClassifier();
}
}
prevCne = currentCne;
}
rv.setPath(firstCne);
} else if (pe instanceof ClassifierValue) {
ClassifierValue cv = (ClassifierValue) pe;
QualifiedNamedElement classifierQne = (QualifiedNamedElement) cv.getClassifier();
String qneClassPackageName = "";
boolean qneClassHasNamespace = classifierQne.getBaNamespace() != null;
if (qneClassHasNamespace) {
qneClassPackageName = classifierQne.getBaNamespace().getId();
}
boolean resolved = false;
for (PackageSection context : _contextsTab) {
NamedElement ne = Aadl2Visitors.findElementInPackage(classifierQne.getBaName().getId(), qneClassPackageName, context);
if (ne != null && ne instanceof Classifier) {
cv.setClassifier((Classifier) ne);
resolved = true;
break;
}
}
if (!resolved) {
String cvQualifiedName = "";
if (!qneClassPackageName.isEmpty()) {
cvQualifiedName += qneClassPackageName + "::";
}
cvQualifiedName += classifierQne.getBaName().getId();
_errManager.error(bv, "Classifier \'" + cvQualifiedName + "\' associated to property " + propertyName + " is not found");
result = false;
}
}
return result;
}
use of org.osate.aadl2.ContainmentPathElement in project osate2 by osate.
the class PropertyUtils method getSubcomponentList.
/**
* May return an empty list.
*
* @param object
* @param propertyName
* @return
*/
public static List<Subcomponent> getSubcomponentList(ProcessorSubcomponent object, String propertyName) {
List<Subcomponent> res = new ArrayList<Subcomponent>();
PropertyAssociation pa = findPropertyAssociation(propertyName, object);
if (pa != null) {
Property p = pa.getProperty();
if (p.getName().equalsIgnoreCase(propertyName)) {
List<ModalPropertyValue> values = pa.getOwnedValues();
if (values.size() == 1) {
ModalPropertyValue v = values.get(0);
PropertyExpression expr = v.getOwnedValue();
if (expr instanceof ListValue) {
ListValue lv = (ListValue) expr;
for (PropertyExpression pe : lv.getOwnedListElements()) {
if (pe instanceof ReferenceValue) {
ReferenceValue c = ((ReferenceValue) pe);
ContainmentPathElement cpe = c.getContainmentPathElements().get(c.getContainmentPathElements().size() - 1);
res.add((Subcomponent) cpe.getNamedElement());
}
}
}
}
}
}
// try on a refined NamedElement
if (object instanceof RefinableElement) {
RefinableElement re = object;
if (re.getRefinedElement() != null) {
List<Subcomponent> l = getSubcomponentList((ProcessorSubcomponent) re.getRefinedElement(), propertyName);
if (!l.isEmpty()) {
res.addAll(l);
}
}
}
return res;
}
use of org.osate.aadl2.ContainmentPathElement in project osate2 by osate.
the class ContainedNamedElementImpl method getContainmentPathElements.
/**
* <!-- begin-user-doc -->
* Get the path elements as a list. For backward-compatibility after metamodel change.
* <!-- end-user-doc -->
* @generated NOT
*/
public EList<ContainmentPathElement> getContainmentPathElements() {
EList<ContainmentPathElement> result = newBasicEList();
ContainmentPathElement next = path;
if (next != null) {
do {
result.add(next);
next = next.getPath();
} while (next != null);
}
return unmodifiableEList(result);
}
use of org.osate.aadl2.ContainmentPathElement in project osate2 by osate.
the class Aadl2Util method getPrintablePathName.
public static String getPrintablePathName(ContainedNamedElement path) {
String pathname = "";
EList<ContainmentPathElement> pathelements = path.getContainmentPathElements();
for (ContainmentPathElement containmentPathElement : pathelements) {
pathname = pathname + (pathname.isEmpty() ? "" : ".") + containmentPathElement.getNamedElement().getName();
}
return pathname;
}
use of org.osate.aadl2.ContainmentPathElement in project osate2 by osate.
the class PropertiesLinkingService method getLinkedObjects.
/**
* returns the first linked object
*/
@Override
public List<EObject> getLinkedObjects(EObject context, EReference reference, INode node) throws IllegalNodeException {
final EClass requiredType = reference.getEReferenceType();
if (requiredType == null) {
return Collections.<EObject>emptyList();
}
EObject searchResult = null;
final EClass cl = Aadl2Package.eINSTANCE.getClassifier();
final EClass sct = Aadl2Package.eINSTANCE.getSubcomponentType();
final EClass pt = Aadl2Package.eINSTANCE.getPropertyType();
final String name = getCrossRefNodeAsString(node);
if (sct.isSuperTypeOf(requiredType) || cl.isSuperTypeOf(requiredType)) {
// XXX: this code can be replicated in Aadl2LinkingService as it is called often in the core
// resolve classifier reference
EObject e = findClassifier(context, reference, name);
if (e != null) {
// the result satisfied the expected class
return Collections.singletonList(e);
}
if (!(context instanceof Generalization) && sct.isSuperTypeOf(requiredType)) {
// need to resolve prototype
EObject res = AadlUtil.getContainingClassifier(context).findNamedElement(name);
if (Aadl2Package.eINSTANCE.getDataPrototype() == reference) {
if (res instanceof DataPrototype) {
searchResult = res;
}
} else if (res instanceof ComponentPrototype) {
searchResult = res;
}
}
} else if (Aadl2Package.eINSTANCE.getModelUnit() == requiredType) {
AadlPackage pack = findAadlPackage(context, name, reference);
if (pack != null) {
searchResult = pack;
} else {
PropertySet ps = findPropertySet(context, name, reference);
if (ps != null) {
searchResult = ps;
}
}
} else if (Aadl2Package.eINSTANCE.getAadlPackage() == requiredType) {
AadlPackage pack = findAadlPackage(context, name, reference);
if (pack != null) {
searchResult = pack;
}
} else if (Aadl2Package.eINSTANCE.getPropertySet() == requiredType) {
PropertySet ps = findPropertySet(context, name, reference);
if (ps != null) {
searchResult = ps;
}
} else if (Aadl2Package.eINSTANCE.getFeature().isSuperTypeOf(requiredType)) {
if (context instanceof Feature) {
// Feature referenced in feature refinement
Classifier ns = AadlUtil.getContainingClassifier(context);
// we need to resolve a refinement
if (ns.getExtended() != null) {
EObject res = ns.getExtended().findNamedElement(name);
if (res != null && res instanceof Feature) {
searchResult = res;
}
} else {
return Collections.emptyList();
}
} else if (context instanceof FlowEnd) {
FlowEnd flowEnd = (FlowEnd) context;
searchResult = findElementInContext(flowEnd, flowEnd.getContext(), name, Feature.class);
}
} else if (Aadl2Package.eINSTANCE.getSubcomponent().isSuperTypeOf(requiredType)) {
// if context Subcomponent then find in extension source (refined
// to)
// prototype binding as context
Classifier ns = AadlUtil.getContainingClassifier(context);
if (context instanceof Subcomponent) {
// we need to resolve a refinement
if (ns.getExtended() != null) {
ns = ns.getExtended();
} else {
return Collections.emptyList();
}
}
EObject res = ns.findNamedElement(name);
if (res instanceof Subcomponent) {
searchResult = res;
}
} else if (Aadl2Package.eINSTANCE.getProperty() == requiredType) {
// look for property definition in property set
return findPropertyDefinitionAsList(context, reference, name);
} else if (Aadl2Package.eINSTANCE.getAbstractNamedValue() == requiredType) {
// AbstractNamedValue: constant reference, property definition reference, unit literal, enumeration literal
if (context instanceof NamedValue) {
List<EObject> res = Collections.EMPTY_LIST;
if (name.indexOf("::") == -1) {
// names without qualifier. Must be enum/unit literal
res = findEnumLiteralAsList(context, reference, name);
if (res.isEmpty()) {
res = findUnitLiteralAsList(context, reference, name);
}
}
if (res.isEmpty()) {
res = findPropertyConstant(context, reference, name);
}
if (res.isEmpty()) {
res = findPropertyDefinitionAsList(context, reference, name);
}
return res;
}
} else if (Aadl2Package.eINSTANCE.getBasicProperty() == requiredType) {
// look for record field definition
if (context instanceof BasicPropertyAssociation) {
BasicPropertyAssociation bpa = (BasicPropertyAssociation) context;
// TODO: Need to check that the type of the record field is
// correct for the value.
Element parent = bpa.getOwner();
while (parent != null && !(parent instanceof BasicPropertyAssociation || parent instanceof PropertyAssociation || parent instanceof Property || parent instanceof PropertyConstant)) {
parent = parent.getOwner();
}
PropertyType propertyType = null;
if (parent instanceof BasicPropertyAssociation) {
BasicProperty bp = ((BasicPropertyAssociation) parent).getProperty();
if (bp != null) {
propertyType = bp.getPropertyType();
}
} else if (parent instanceof PropertyAssociation) {
Property pd = ((PropertyAssociation) parent).getProperty();
if (pd != null) {
propertyType = pd.getPropertyType();
}
} else if (parent instanceof Property) {
propertyType = ((Property) parent).getPropertyType();
} else if (parent instanceof PropertyConstant) {
propertyType = ((PropertyConstant) parent).getPropertyType();
}
propertyType = AadlUtil.getBasePropertyType(propertyType);
if (propertyType != null && propertyType instanceof RecordType) {
BasicProperty rf = (BasicProperty) ((RecordType) propertyType).findNamedElement(name);
if (rf != null) {
searchResult = rf;
}
}
}
} else if (pt.isSuperTypeOf(requiredType)) {
// look for property type in property set
return findPropertyType(context, reference, name);
} else if (Aadl2Package.eINSTANCE.getPropertyConstant() == requiredType) {
// look for property constant in property set
return findPropertyConstant(context, reference, name);
} else if (Aadl2Package.eINSTANCE.getUnitLiteral() == requiredType) {
// look for unit literal pointed to by baseUnit
return findUnitLiteralAsList(context, reference, name);
} else if (Aadl2Package.eINSTANCE.getEnumerationLiteral() == requiredType) {
// look for enumeration literal
return findEnumLiteralAsList(context, reference, name);
} else if (Aadl2Package.eINSTANCE.getMode() == requiredType) {
// referenced by mode transition, inmodes, ModeBinding
EObject res = null;
if (context instanceof ModeBinding) {
if (reference == Aadl2Package.eINSTANCE.getModeBinding_ParentMode()) {
res = AadlUtil.getContainingClassifier(context).findNamedElement(name);
} else if (reference == Aadl2Package.eINSTANCE.getModeBinding_DerivedMode()) {
Subcomponent subcomponent = AadlUtil.getContainingSubcomponent(context);
while (subcomponent.getSubcomponentType() == null && subcomponent.getRefined() != null) {
subcomponent = subcomponent.getRefined();
}
ComponentClassifier subcomponentClassifier = null;
if (subcomponent.getSubcomponentType() instanceof ComponentClassifier) {
subcomponentClassifier = ((ComponentClassifier) subcomponent.getSubcomponentType());
} else if (subcomponent.getSubcomponentType() instanceof ComponentPrototype) {
subcomponentClassifier = findClassifierForComponentPrototype(AadlUtil.getContainingClassifier(context), ((ComponentPrototype) subcomponent.getSubcomponentType()));
}
if (subcomponentClassifier != null) {
res = subcomponentClassifier.findNamedElement(name);
}
}
} else {
// check about in modes in a contained property association
PropertyAssociation pa = AadlUtil.getContainingPropertyAssociation(context);
if (pa != null && !pa.getAppliesTos().isEmpty()) {
ContainedNamedElement path = pa.getAppliesTos().get(0);
EList<ContainmentPathElement> cpelist = path.getContainmentPathElements();
Subcomponent cpesub = null;
for (ContainmentPathElement containmentPathElement : cpelist) {
if (containmentPathElement.getNamedElement() instanceof Subcomponent) {
cpesub = (Subcomponent) containmentPathElement.getNamedElement();
} else {
break;
}
}
if (cpesub != null) {
if (cpesub.getAllClassifier() != null) {
res = cpesub.getAllClassifier().findNamedElement(name);
}
} else {
res = AadlUtil.getContainingClassifier(context).findNamedElement(name);
}
} else {
if ((pa != null) && (pa.getOwner() instanceof Subcomponent)) {
Subcomponent subco = (Subcomponent) pa.getOwner();
if (subco.getAllClassifier() != null) {
res = subco.getAllClassifier().findNamedElement(name);
}
} else {
res = AadlUtil.getContainingClassifier(context).findNamedElement(name);
}
}
}
if (res != null && res instanceof Mode) {
searchResult = res;
}
} else if (Aadl2Package.eINSTANCE.getNamedElement() == requiredType) {
// containment path element
if (context instanceof ContainmentPathElement) {
EObject res = null;
if (((ContainmentPathElement) context).getOwner() instanceof ContainmentPathElement) {
// find next element in namespace of previous element
ContainmentPathElement el = (ContainmentPathElement) ((ContainmentPathElement) context).getOwner();
NamedElement ne = el.getNamedElement();
if (ne instanceof Subcomponent) {
Subcomponent subcomponent = (Subcomponent) ne;
while (subcomponent.getSubcomponentType() == null && subcomponent.getRefined() != null) {
subcomponent = subcomponent.getRefined();
}
ComponentClassifier ns = null;
if (subcomponent.getSubcomponentType() instanceof ComponentClassifier) {
ns = (ComponentClassifier) subcomponent.getSubcomponentType();
} else if (subcomponent.getSubcomponentType() instanceof ComponentPrototype) {
ns = ResolvePrototypeUtil.resolveComponentPrototype((ComponentPrototype) subcomponent.getSubcomponentType(), el);
}
if (ns != null) {
res = ns.findNamedElement(name);
if (res == null && (ne instanceof ThreadSubcomponent || ne instanceof SubprogramSubcomponent || ne instanceof AbstractSubcomponent) && ns instanceof BehavioredImplementation) {
res = AadlUtil.findNamedElementInList(((BehavioredImplementation) ns).subprogramCalls(), name);
}
}
} else if (ne instanceof FeatureGroup) {
FeatureGroup featureGroup = (FeatureGroup) ne;
while (featureGroup.getFeatureType() == null && featureGroup.getRefined() instanceof FeatureGroup) {
featureGroup = (FeatureGroup) featureGroup.getRefined();
}
FeatureGroupType ns = null;
if (featureGroup.getFeatureType() instanceof FeatureGroupType) {
ns = (FeatureGroupType) featureGroup.getFeatureType();
} else if (featureGroup.getFeatureType() instanceof FeatureGroupPrototype) {
ns = ResolvePrototypeUtil.resolveFeatureGroupPrototype((FeatureGroupPrototype) featureGroup.getFeatureType(), el);
}
if (ns != null) {
res = ns.findNamedElement(name);
}
}
} else {
// the first containment path element
Classifier ns = null;
PropertyAssociation containingPropertyAssociation = AadlUtil.getContainingPropertyAssociation(context);
if (containingPropertyAssociation != null) {
// need to make sure we look in the correct name space
if (containingPropertyAssociation.getOwner() instanceof Subcomponent) {
Subcomponent subcomponent = (Subcomponent) containingPropertyAssociation.getOwner();
while (subcomponent.getSubcomponentType() == null && subcomponent.getRefined() != null) {
subcomponent = subcomponent.getRefined();
}
if (subcomponent.getSubcomponentType() instanceof ComponentClassifier) {
ns = (ComponentClassifier) subcomponent.getSubcomponentType();
} else if (subcomponent.getSubcomponentType() instanceof ComponentPrototype) {
ns = ResolvePrototypeUtil.resolveComponentPrototype((ComponentPrototype) subcomponent.getSubcomponentType(), AadlUtil.getContainingClassifier(context));
}
} else if (containingPropertyAssociation.getOwner() instanceof FeatureGroup) {
FeatureGroup fg = (FeatureGroup) containingPropertyAssociation.getOwner();
while (fg.getFeatureType() == null && fg.getRefined() instanceof FeatureGroup) {
fg = (FeatureGroup) fg.getRefined();
}
if (fg.getFeatureType() instanceof FeatureGroupType) {
ns = (FeatureGroupType) fg.getFeatureType();
} else if (fg.getFeatureType() instanceof FeatureGroupPrototype) {
ns = ResolvePrototypeUtil.resolveFeatureGroupPrototype((FeatureGroupPrototype) fg.getFeatureType(), AadlUtil.getContainingClassifier(context));
}
} else {
ns = containingPropertyAssociation.getContainingClassifier();
}
}
if (ns != null) {
res = ns.findNamedElement(name);
}
}
if (res != null && res instanceof NamedElement) {
searchResult = res;
}
}
} else {
List<EObject> superes = super.getLinkedObjects(context, reference, node);
return superes;
}
if (searchResult != null) {
return Collections.singletonList(searchResult);
}
return Collections.<EObject>emptyList();
}
Aggregations