use of org.osate.aadl2.PropertyExpression in project osate2 by osate.
the class AadlBaUtils method processArrayDataRepresentation.
// Evaluates the array behavior of the given type in the Data Model Annex
// standard way. Set up dimension and dimension sizes of the given
// TypeHolder object.
// The given expression dimension is used as an dimension offset.
private static void processArrayDataRepresentation(Element el, TypeHolder type, int exprDim) throws DimensionException {
// Treats only type declared as an array. Otherwise returns.
if (type.getDataRep() == DataRepresentation.ARRAY) {
// Fetches the array element data type.
ClassifierValue cv = AadlBaUtils.getBaseType(type.getKlass());
if (cv != null && cv.getClassifier() instanceof DataClassifier) {
DataClassifier dc = (DataClassifier) cv.getClassifier();
type.setKlass(dc);
type.setDataRep(AadlBaUtils.getDataRepresentation(dc));
} else {
type.setKlass(null);
}
EList<PropertyExpression> pel = PropertyUtils.findPropertyExpression(type.getKlass(), DataModelProperties.DIMENSION);
int declareDimBT = 0;
long[] declareDimSizeBT;
if (false == pel.isEmpty()) {
// pel has only one element, according to AADL core standard.
PropertyExpression pe = pel.get(pel.size() - 1);
if (pe instanceof ListValue) {
ListValue lv = (ListValue) pe;
EList<PropertyExpression> lve = lv.getOwnedListElements();
declareDimBT = lve.size();
if (declareDimBT >= exprDim) {
declareDimSizeBT = new long[declareDimBT - exprDim];
for (int i = exprDim; i < declareDimBT; i++) {
IntegerLiteral il = (IntegerLiteral) lve.get(i);
declareDimSizeBT[i - exprDim] = il.getValue();
}
type.setDimension(declareDimBT - exprDim);
type.setDimensionSizes(declareDimSizeBT);
} else {
String msg = "must be an array but is resolved as " + type.getKlass().getQualifiedName();
throw new DimensionException(el, msg, false);
}
}
} else {
// Returning -1 and null means that the expression is declared as an
// array but the dimension property is not set.
type.setDimension(-1);
type.setDimensionSizes(null);
return;
// String msg = "is declared as an array but the dimension property is not set" ;
// throw new DimensionException(el, msg, true) ;
}
} else {
return;
}
}
use of org.osate.aadl2.PropertyExpression in project osate2 by osate.
the class PropertyUtils method getListValue.
public static ListValue getListValue(NamedElement ne, String propertyName) {
PropertyAssociation pa = findPropertyAssociation(propertyName, ne);
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) {
return (ListValue) expr;
}
}
}
}
return null;
}
use of org.osate.aadl2.PropertyExpression in project osate2 by osate.
the class PropertyUtils method getStringValue.
/**
* Extract String value from a specified property. May return null.
*
* @param i
* component instance.
* @param propertyName
* property name.
* @return property value.
*/
public static String getStringValue(NamedElement i, String propertyName) {
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 StringLiteral) {
return ((StringLiteral) expr).getValue();
}
}
}
}
return null;
}
use of org.osate.aadl2.PropertyExpression in project osate2 by osate.
the class PropertyUtils method getBooleanValue.
/**
* Extract boolean value from a specified property. May return null.
*
* @param i
* component instance.
* @param propertyName
* property name.
* @return property value.
*/
public static Boolean getBooleanValue(NamedElement i, String propertyName) {
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 BooleanLiteral) {
return (boolean) ((BooleanLiteral) expr).getValue();
}
}
}
}
return null;
}
use of org.osate.aadl2.PropertyExpression in project osate2 by osate.
the class PropertyUtils method getMaxRangeValue.
/**
* Extract maximum range value from a specified property. May return null.
*
* @param i
* component instance.
* @param propertyName
* property name.
* @return property value.
*/
public static NumberValue getMaxRangeValue(NamedElement i, String propertyName) {
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 RangeValue) {
NumberValue n = ((RangeValue) expr).getMaximumValue();
return n;
} else if (expr instanceof NumberValue) {
return (NumberValue) expr;
}
}
}
}
return null;
}
Aggregations