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