Search in sources :

Example 21 with EnumerationLiteral

use of org.osate.aadl2.EnumerationLiteral in project osate-plugin by sireum.

the class HAMRPropertyProvider method getPlatformsFromElement.

public static List<Platform> getPlatformsFromElement(NamedElement ne) {
    List<Platform> r = new ArrayList<>();
    try {
        Property p = GetProperties.lookupPropertyDefinition(ne, PROP_HAMR__PLATFORM);
        List<? extends PropertyExpression> propertyValues = ne.getPropertyValueList(p);
        for (PropertyExpression pe : propertyValues) {
            String v = ((EnumerationLiteral) ((NamedValue) pe).getNamedValue()).getName();
            r.add(Platform.valueOf(v));
        }
    } catch (PropertyLookupException e) {
    }
    return r;
}
Also used : ArrayList(java.util.ArrayList) PropertyExpression(org.osate.aadl2.PropertyExpression) Property(org.osate.aadl2.Property) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral) PropertyLookupException(org.osate.aadl2.properties.PropertyLookupException)

Example 22 with EnumerationLiteral

use of org.osate.aadl2.EnumerationLiteral in project osate-plugin by sireum.

the class HAMRPropertyProvider method getHWsFromElement.

public static List<HW> getHWsFromElement(NamedElement ne) {
    List<HW> r = new ArrayList<>();
    try {
        Property p = GetProperties.lookupPropertyDefinition(ne, PROP_HAMR__HW);
        List<? extends PropertyExpression> propertyValues = ne.getPropertyValueList(p);
        for (PropertyExpression pe : propertyValues) {
            String v = ((EnumerationLiteral) ((NamedValue) pe).getNamedValue()).getName();
            r.add(HW.valueOf(v));
        }
    } catch (PropertyLookupException e) {
    }
    return r;
}
Also used : ArrayList(java.util.ArrayList) PropertyExpression(org.osate.aadl2.PropertyExpression) Property(org.osate.aadl2.Property) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral) PropertyLookupException(org.osate.aadl2.properties.PropertyLookupException)

Example 23 with EnumerationLiteral

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

the class AadlBaUnparser method unparse.

// This is very specific to AADL BA. It cannot be used elsewhere.
private static String unparse(PropertyExpression pe) {
    int type = pe.eClass().getClassifierID();
    String result = "";
    switch(type) {
        case Aadl2Package.STRING_LITERAL:
            {
                // TODO: Should quotes be added there?
                result = ((StringLiteral) pe).getValue();
                break;
            }
        case Aadl2Package.LIST_VALUE:
        case Aadl2Package.REAL_LITERAL:
        case Aadl2Package.BOOLEAN_LITERAL:
        case Aadl2Package.NUMBER_VALUE:
        case Aadl2Package.INTEGER_LITERAL:
        case Aadl2Package.RECORD_VALUE:
        case Aadl2Package.RANGE_VALUE:
            {
                BasicProperty container = PropertyUtils.getContainingProperty(pe);
                result = container.getName();
                break;
            }
        case Aadl2Package.NAMED_VALUE:
            {
                NamedValue nv = (NamedValue) pe;
                AbstractNamedValue anv = nv.getNamedValue();
                if (anv instanceof PropertyExpression) {
                    result = unparse((PropertyExpression) anv);
                } else if (anv instanceof EnumerationLiteral) {
                    BasicProperty container = PropertyUtils.getContainingProperty(pe);
                    result = container.getName();
                    break;
                } else {
                    String msg = anv.getClass().getSimpleName() + " is not supported (in NamedValue)";
                    System.err.println(msg);
                    throw new UnsupportedOperationException(msg);
                }
                break;
            }
        default:
            {
                String msg = "unparsing " + pe.getClass().getSimpleName() + " is not supported yet";
                System.err.println(msg);
                throw new UnsupportedOperationException(msg);
            }
    }
    return result;
}
Also used : BasicProperty(org.osate.aadl2.BasicProperty) BehaviorStringLiteral(org.osate.ba.aadlba.BehaviorStringLiteral) StringLiteral(org.osate.aadl2.StringLiteral) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) NamedValue(org.osate.aadl2.NamedValue) PropertyExpression(org.osate.aadl2.PropertyExpression) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral)

Example 24 with EnumerationLiteral

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

the class Aadl2Utils method getAccessRight.

/**
 * Returns the access right of the given NamedElement object.<BR>
 * <BR>
 *
 * Returns the local "Access_Right" property value, if it is set. Otherwise,
 * returns the default access right value found in Memory_Properties (pre
 * declared property set). If the default access right is not found, it
 * returns "unknown".
 *
 * @param ne the given NamedElement object
 * @return local access right or default access right or "unknown"
 */
public static String getAccessRight(NamedElement ne) {
    String result = PropertyUtils.getEnumValue(ne, "Access_Right");
    if (result == null) {
        if (DEFAULT_ACCESS_RIGHT == null) {
            Property prop = GetProperties.lookupPropertyDefinition(ne, "Memory_Properties", "Access_Right");
            if (prop != null) {
                NamedValue nv = (NamedValue) prop.getDefaultValue();
                result = ((EnumerationLiteral) nv.getNamedValue()).getName();
                DEFAULT_ACCESS_RIGHT = result;
            } else {
                return "unknown";
            }
        } else {
            return DEFAULT_ACCESS_RIGHT;
        }
    }
    return result;
}
Also used : NamedValue(org.osate.aadl2.NamedValue) Property(org.osate.aadl2.Property)

Example 25 with EnumerationLiteral

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

the class PropertyUtils method getStringListValue.

/**
 * Extract String list value from a specified property. May return null.
 *
 * @param i
 *            component instance.
 * @param propertyName
 *            property name.
 * @return property value.
 */
public static List<String> getStringListValue(NamedElement i, String propertyName) {
    List<String> res = new ArrayList<String>();
    PropertyAssociation pa = findPropertyAssociation(propertyName, i);
    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 StringLiteral) {
                            StringLiteral sl = (StringLiteral) pe;
                            res.add(sl.getValue());
                        } else if (pe instanceof NamedValue) {
                            NamedValue nv = (NamedValue) pe;
                            if (nv.getNamedValue() instanceof EnumerationLiteral) {
                                EnumerationLiteral el = (EnumerationLiteral) nv.getNamedValue();
                                res.add(el.getName());
                            }
                        }
                    }
                    if (!res.isEmpty()) {
                        return res;
                    }
                }
            }
        }
    }
    return null;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) StringLiteral(org.osate.aadl2.StringLiteral) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ListValue(org.osate.aadl2.ListValue) ArrayList(java.util.ArrayList) PropertyExpression(org.osate.aadl2.PropertyExpression) NamedValue(org.osate.aadl2.NamedValue) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral)

Aggregations

EnumerationLiteral (org.osate.aadl2.EnumerationLiteral)43 Property (org.osate.aadl2.Property)27 NamedValue (org.osate.aadl2.NamedValue)26 PropertyExpression (org.osate.aadl2.PropertyExpression)24 BasicProperty (org.osate.aadl2.BasicProperty)18 AbstractNamedValue (org.osate.aadl2.AbstractNamedValue)13 PropertyAssociation (org.osate.aadl2.PropertyAssociation)13 ArrayList (java.util.ArrayList)9 ListValue (org.osate.aadl2.ListValue)9 StringLiteral (org.osate.aadl2.StringLiteral)8 PropertyLookupException (org.osate.aadl2.properties.PropertyLookupException)8 AadlString (org.osate.aadl2.AadlString)7 ArraySizeProperty (org.osate.aadl2.ArraySizeProperty)6 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)6 NamedElement (org.osate.aadl2.NamedElement)6 RecordValue (org.osate.aadl2.RecordValue)6 ClassifierValue (org.osate.aadl2.ClassifierValue)5 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)5 BooleanLiteral (org.osate.aadl2.BooleanLiteral)4 Classifier (org.osate.aadl2.Classifier)4