Search in sources :

Example 1 with DataRepresentation

use of org.osate.ba.aadlba.DataRepresentation in project osate2 by osate.

the class AadlBaNameResolver method structOrUnionOrArrayIdResolver.

// Resolves the given identifier within the property Data_Model::Element
// Names of a declared struct or union component (event if element names is
// set). If the given component is not declared as a struct or union, it
// returns false and reports error according to the hasToReport flag.
private boolean structOrUnionOrArrayIdResolver(Identifier id, DataClassifier component, boolean hasToReport) {
    boolean result = false;
    DataRepresentation rep = AadlBaUtils.getDataRepresentation(component);
    if (rep == DataRepresentation.STRUCT || rep == DataRepresentation.UNION) {
        EList<PropertyExpression> lpv = PropertyUtils.findPropertyExpression(component, DataModelProperties.ELEMENT_NAMES);
        ListValue lv = null;
        StringLiteral sl = null;
        int index1 = 0;
        int index2 = 0;
        for1: for (PropertyExpression pe : lpv) {
            lv = (ListValue) pe;
            for (PropertyExpression pex : lv.getOwnedListElements()) {
                sl = (StringLiteral) pex;
                if (id.getId().equalsIgnoreCase(sl.getValue())) {
                    result = true;
                    break for1;
                }
                index2++;
            }
            index1++;
        }
        // Binds the element name's base type.
        if (result) {
            EList<PropertyExpression> lpv2 = PropertyUtils.findPropertyExpression(component, DataModelProperties.BASE_TYPE);
            ClassifierValue cv;
            cv = (ClassifierValue) ((ListValue) lpv2.get(index1)).getOwnedListElements().get(index2);
            id.setOsateRef(cv);
        }
    } else if (rep == DataRepresentation.ARRAY) {
        EList<PropertyExpression> lpv = PropertyUtils.findPropertyExpression(component, DataModelProperties.BASE_TYPE);
        if (lpv.isEmpty() == false) {
            ClassifierValue cv;
            cv = (ClassifierValue) ((ListValue) lpv.get(0)).getOwnedListElements().get(0);
            result = identifierComponentResolver(id, cv.getClassifier(), hasToReport);
        } else {
            result = false;
        }
    }
    if (!result && hasToReport) {
        reportNameError(id, id.getId());
    }
    return result;
}
Also used : ClassifierValue(org.osate.aadl2.ClassifierValue) BasicEList(org.eclipse.emf.common.util.BasicEList) EList(org.eclipse.emf.common.util.EList) StringLiteral(org.osate.aadl2.StringLiteral) DataRepresentation(org.osate.ba.aadlba.DataRepresentation) ListValue(org.osate.aadl2.ListValue) DeclarativeListValue(org.osate.ba.declarative.DeclarativeListValue) PropertyExpression(org.osate.aadl2.PropertyExpression)

Example 2 with DataRepresentation

use of org.osate.ba.aadlba.DataRepresentation in project osate2 by osate.

the class AadlBaUtils method getDataRepresentation.

/**
 * Returns the last data representation from the property stack of the given data
 * classifier or DataRepresentation.UNKNOWN if Data_Model::Data_Representation
 * property is not set or if the data classifier represents a data structure.
 *
 * @param c the given data classifier
 * @return the data representation or DataRepresentation.UNKNOWN
 */
public static DataRepresentation getDataRepresentation(DataClassifier c) {
    DataRepresentation result = null;
    if (c == null) {
        result = DataRepresentation.UNKNOWN;
    } else {
        EList<PropertyExpression> l = PropertyUtils.findPropertyExpression(c, DataModelProperties.DATA_REPRESENTATION);
        if (l.size() > 0) {
            // Fetches the last enumeration value from the inheritance stack of
            // properties.
            NamedValue nv = (NamedValue) l.get(l.size() - 1);
            String tmp = ((EnumerationLiteral) nv.getNamedValue()).getName();
            result = DataRepresentation.getByName(tmp);
            if (result == null) {
                result = DataRepresentation.UNKNOWN;
            }
        } else {
            result = DataRepresentation.UNKNOWN;
        }
    }
    return result;
}
Also used : DataRepresentation(org.osate.ba.aadlba.DataRepresentation) PropertyExpression(org.osate.aadl2.PropertyExpression) NamedValue(org.osate.aadl2.NamedValue) AadlString(org.osate.aadl2.AadlString) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral)

Aggregations

PropertyExpression (org.osate.aadl2.PropertyExpression)2 DataRepresentation (org.osate.ba.aadlba.DataRepresentation)2 BasicEList (org.eclipse.emf.common.util.BasicEList)1 EList (org.eclipse.emf.common.util.EList)1 AadlString (org.osate.aadl2.AadlString)1 ClassifierValue (org.osate.aadl2.ClassifierValue)1 EnumerationLiteral (org.osate.aadl2.EnumerationLiteral)1 ListValue (org.osate.aadl2.ListValue)1 NamedValue (org.osate.aadl2.NamedValue)1 StringLiteral (org.osate.aadl2.StringLiteral)1 DeclarativeListValue (org.osate.ba.declarative.DeclarativeListValue)1