Search in sources :

Example 11 with BasicProperty

use of org.osate.aadl2.BasicProperty in project osate2 by osate.

the class AadlBaUtils method getDataRepresentation.

/**
 * Returns the data representation associated to the given PropertyReference
 * object <BR><BR>
 * Note : {@link #getDataRepresentation(PropertyType)} and
 * {@link #getDataRepresentation(PropertyExpression)} to see restrictions.
 * <BR><BR>
 * @param pv the given PropertyReference object
 * @return the data representation associated to the given
 * PropertyReference object
 * @exception UnsupportedOperationException for the unsupported types
 */
public static DataRepresentation getDataRepresentation(PropertyReference pr) {
    EList<PropertyNameHolder> holders = pr.getProperties();
    PropertyNameHolder last = holders.get(holders.size() - 1);
    Element el = last.getProperty().getElement();
    if (el instanceof PropertyType || el instanceof BasicProperty) {
        return getDataRepresentation(((BasicProperty) el).getPropertyType());
    } else if (el instanceof PropertyAssociation) {
        return getDataRepresentation((PropertyAssociation) el);
    } else if (el instanceof PropertyExpression) {
        return getDataRepresentation((PropertyExpression) el);
    } else if (el instanceof EnumerationLiteral) {
        return DataRepresentation.ENUM_LITERAL;
    } else {
        String errorMsg = "getDataRepresentation: " + el.getClass().getSimpleName() + " is not supported yet.";
        System.err.println(errorMsg);
        throw new UnsupportedOperationException(errorMsg);
    }
}
Also used : BasicProperty(org.osate.aadl2.BasicProperty) PropertyNameHolder(org.osate.ba.aadlba.PropertyNameHolder) PropertyAssociation(org.osate.aadl2.PropertyAssociation) StructUnionElement(org.osate.ba.aadlba.StructUnionElement) BehaviorNamedElement(org.osate.ba.aadlba.BehaviorNamedElement) NamedElement(org.osate.aadl2.NamedElement) ArrayableElement(org.osate.aadl2.ArrayableElement) Element(org.osate.aadl2.Element) BehaviorElement(org.osate.ba.aadlba.BehaviorElement) IndexableElement(org.osate.ba.aadlba.IndexableElement) PropertyExpression(org.osate.aadl2.PropertyExpression) PropertyType(org.osate.aadl2.PropertyType) AadlString(org.osate.aadl2.AadlString) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral)

Example 12 with BasicProperty

use of org.osate.aadl2.BasicProperty in project osate2 by osate.

the class AadlBaUtils method getPropertyType.

/**
 * Returns the PropertyType object associated to the given PropertyElementHolder
 * given object.
 * @param holder the PropertyElementHolder given object
 * @return the associated PropertyType object
 */
public static PropertyType getPropertyType(PropertyElementHolder holder) {
    PropertyType result = null;
    Element el = holder.getElement();
    if (el instanceof PropertyType) {
        result = (PropertyType) el;
    } else if (el instanceof BasicProperty) {
        result = ((BasicProperty) el).getPropertyType();
    } else if (el instanceof PropertyAssociation) {
        result = ((PropertyAssociation) el).getProperty().getPropertyType();
    } else if (el instanceof PropertyExpression) {
        result = PropertyUtils.getContainingProperty((PropertyExpression) el).getPropertyType();
    } else if (el instanceof EnumerationLiteral) {
        result = (EnumerationType) el.eContainer();
    }
    return result;
}
Also used : BasicProperty(org.osate.aadl2.BasicProperty) PropertyAssociation(org.osate.aadl2.PropertyAssociation) StructUnionElement(org.osate.ba.aadlba.StructUnionElement) BehaviorNamedElement(org.osate.ba.aadlba.BehaviorNamedElement) NamedElement(org.osate.aadl2.NamedElement) ArrayableElement(org.osate.aadl2.ArrayableElement) Element(org.osate.aadl2.Element) BehaviorElement(org.osate.ba.aadlba.BehaviorElement) IndexableElement(org.osate.ba.aadlba.IndexableElement) PropertyExpression(org.osate.aadl2.PropertyExpression) PropertyType(org.osate.aadl2.PropertyType) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral)

Example 13 with BasicProperty

use of org.osate.aadl2.BasicProperty 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;
}
Also used : ClassifierValue(org.osate.aadl2.ClassifierValue) ReferenceValue(org.osate.aadl2.ReferenceValue) DeclarativePropertyReference(org.osate.ba.declarative.DeclarativePropertyReference) Reference(org.osate.ba.declarative.Reference) PackageSection(org.osate.aadl2.PackageSection) ListValue(org.osate.aadl2.ListValue) DeclarativeListValue(org.osate.ba.declarative.DeclarativeListValue) DeclarativeListValue(org.osate.ba.declarative.DeclarativeListValue) RecordValue(org.osate.aadl2.RecordValue) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) Feature(org.osate.aadl2.Feature) ClassifierFeature(org.osate.aadl2.ClassifierFeature) RangeValue(org.osate.aadl2.RangeValue) RealLiteral(org.osate.aadl2.RealLiteral) BasicProperty(org.osate.aadl2.BasicProperty) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) Identifier(org.osate.ba.declarative.Identifier) ArrayableIdentifier(org.osate.ba.declarative.ArrayableIdentifier) Subcomponent(org.osate.aadl2.Subcomponent) PropertyExpression(org.osate.aadl2.PropertyExpression) DeclarativeBasicPropertyAssociation(org.osate.ba.declarative.DeclarativeBasicPropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) DeclarativeBasicPropertyAssociation(org.osate.ba.declarative.DeclarativeBasicPropertyAssociation) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) NamedElement(org.osate.aadl2.NamedElement) IntegerLiteral(org.osate.aadl2.IntegerLiteral) BehaviorIntegerLiteral(org.osate.ba.aadlba.BehaviorIntegerLiteral)

Example 14 with BasicProperty

use of org.osate.aadl2.BasicProperty in project osate2 by osate.

the class AadlBaNameResolver method propertyIndexResolver.

private boolean propertyIndexResolver(DeclarativePropertyName declProName) {
    Element el = declProName.getOsateRef();
    BasicProperty bProperty = getPropertyDeclaration(el);
    int nameTypeId = bProperty.getPropertyType().eClass().getClassifierID();
    EList<IntegerValue> indexes = declProName.getIndexes();
    if (nameTypeId == Aadl2Package.ENUMERATION_TYPE) {
        if (indexes.size() == 1) {
            return integerValueResolver(indexes.get(0));
        } else {
            String msg = "multiple integer index is not only supported for property enumeration";
            _errManager.error(indexes.get(1), msg);
            return false;
        }
    } else if (nameTypeId == Aadl2Package.LIST_TYPE || Aadl2Package.LIST_VALUE == el.eClass().getClassifierID()) {
        for (int fieldIndex = 0; fieldIndex < indexes.size(); fieldIndex++) {
            IntegerValue iv = indexes.get(fieldIndex);
            if (propertyFieldIndexResolver(el, iv, bProperty, fieldIndex, declProName)) {
                continue;
            } else {
                return false;
            }
        }
        return true;
    } else {
        String msg = "integer index is only supported for list of properties or " + "property enumerations";
        _errManager.error(indexes.get(0), msg);
        return false;
    }
}
Also used : BasicProperty(org.osate.aadl2.BasicProperty) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) DeclarativeBehaviorElement(org.osate.ba.declarative.DeclarativeBehaviorElement) NamedElement(org.osate.aadl2.NamedElement) Element(org.osate.aadl2.Element) BehaviorElement(org.osate.ba.aadlba.BehaviorElement) IntegerValue(org.osate.ba.aadlba.IntegerValue)

Example 15 with BasicProperty

use of org.osate.aadl2.BasicProperty in project osate2 by osate.

the class AadlBaTypeChecker method propertyElementHolderResolver.

private PropertyElementHolder propertyElementHolderResolver(Element el, LocationReference loc) {
    PropertyElementHolder result = null;
    if (el instanceof BasicProperty) {
        BasicProperty bp = (BasicProperty) el;
        BasicPropertyHolder tmp = _fact.createBasicPropertyHolder();
        tmp.setBasicProperty(bp);
        result = tmp;
    } else if (el instanceof PropertyAssociation) {
        PropertyAssociation pa = (PropertyAssociation) el;
        PropertyAssociationHolder tmp = _fact.createPropertyAssociationHolder();
        tmp.setPropertyAssociation(pa);
        result = tmp;
    } else if (el instanceof PropertyExpression) {
        PropertyExpression pe = (PropertyExpression) el;
        PropertyExpressionHolder tmp = _fact.createPropertyExpressionHolder();
        tmp.setPropertyExpression(pe);
        result = tmp;
    } else if (el instanceof PropertyType) {
        PropertyType pt = (PropertyType) el;
        PropertyTypeHolder tmp = _fact.createPropertyTypeHolder();
        tmp.setPropertyType(pt);
        result = tmp;
    } else if (el instanceof EnumerationLiteral) {
        EnumerationLiteral enumLit = (EnumerationLiteral) el;
        EnumLiteralHolder tmp = _fact.createEnumLiteralHolder();
        tmp.setEnumLiteral(enumLit);
        result = tmp;
    } else {
        String errorMsg = "type: " + el.getClass().getSimpleName() + " is not supported yet.";
        System.err.println(errorMsg);
        throw new UnsupportedOperationException(errorMsg);
    }
    result.setLocationReference(loc);
    return result;
}
Also used : PropertyAssociation(org.osate.aadl2.PropertyAssociation) PropertyType(org.osate.aadl2.PropertyType) BasicProperty(org.osate.aadl2.BasicProperty) PropertyExpression(org.osate.aadl2.PropertyExpression) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral)

Aggregations

BasicProperty (org.osate.aadl2.BasicProperty)17 PropertyAssociation (org.osate.aadl2.PropertyAssociation)8 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)7 NamedElement (org.osate.aadl2.NamedElement)7 PropertyExpression (org.osate.aadl2.PropertyExpression)7 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)6 Element (org.osate.aadl2.Element)6 Property (org.osate.aadl2.Property)5 BehaviorElement (org.osate.ba.aadlba.BehaviorElement)5 QualifiedNamedElement (org.osate.ba.declarative.QualifiedNamedElement)5 EnumerationLiteral (org.osate.aadl2.EnumerationLiteral)4 PropertyType (org.osate.aadl2.PropertyType)4 RecordType (org.osate.aadl2.RecordType)3 EObject (org.eclipse.emf.ecore.EObject)2 EOperation (org.eclipse.emf.ecore.EOperation)2 AadlPackage (org.osate.aadl2.AadlPackage)2 AadlString (org.osate.aadl2.AadlString)2 AbstractSubcomponent (org.osate.aadl2.AbstractSubcomponent)2 ArrayableElement (org.osate.aadl2.ArrayableElement)2 Classifier (org.osate.aadl2.Classifier)2