use of org.osate.aadl2.ClassifierValue in project osate2 by osate.
the class GetProperties method getAllowedMemoryBindingClass.
public static List<Classifier> getAllowedMemoryBindingClass(final InstanceObject io) {
Property allowedMemoryBindingClass = lookupPropertyDefinition(io, DeploymentProperties._NAME, DeploymentProperties.ALLOWED_MEMORY_BINDING_CLASS);
ArrayList<Classifier> components = new ArrayList<>();
List<? extends PropertyExpression> propertyValues;
try {
propertyValues = io.getPropertyValueList(allowedMemoryBindingClass);
} catch (Exception e) {
return components;
}
for (PropertyExpression propertyExpression : propertyValues) {
components.add(((ClassifierValue) propertyExpression).getClassifier());
}
return components;
}
use of org.osate.aadl2.ClassifierValue 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;
}
use of org.osate.aadl2.ClassifierValue in project osate2 by osate.
the class AadlBaUtils method getClassifier.
/**
* Returns the given Element object's classifier.
* If the Element object is a prototype, it will try to resolve it as
* follow: returns the data prototype binded classifier at first withing the
* element's parent container otherwise the constraining classifier.
* It returns {@code null} if the prototype is not defined.
* <BR><BR>
* This method support instances of:<BR>
* <BR>_Feature (port, data access, subprogram access, parameter, etc.)
* <BR>_Subcomponent (data subcomponent, subprogram subcomponent, etc.)
* <BR>_BehaviorVariable
* <BR>_IterativeVariable (for/forall's iterative variable)
* <BR>_Prototype (all excepted FeatureGroupPrototype)
* <BR>_PrototypeBinding (all excepted FeatureGroupPrototypeBinding)
* <BR>_ClassifierValue (struct or union data subcomponent)
* <BR><BR>
* If the given Element object is not one of those types, an
* UnsupportedOperationException is thrown.
*
* @param el the given Element object
* @param parentContainer the element's parent component.
* @return the given element's classifier or {@code null} if the prototype is
* not defined
* @exception UnsupportedOperationException for unsupported element
* object types.
*/
public static Classifier getClassifier(Element el, Classifier parentContainer) {
Classifier result = null;
if (el instanceof Feature) {
Feature f = (Feature) el;
if (el instanceof FeatureGroup) {
org.osate.aadl2.FeatureType ft = ((FeatureGroup) el).getFeatureType();
if (ft != null) {
if (ft instanceof FeatureGroupType) {
result = (FeatureGroupType) ft;
} else // FeatureGroupPrototype case
{
result = getClassifier((FeatureGroupPrototype) ft, parentContainer);
}
}
} else {
// Feature case.
result = f.getClassifier();
// Feature without classifier returns null.
if (result == null && f.getPrototype() != null) {
result = prototypeResolver(f.getPrototype(), parentContainer);
}
}
} else if (el instanceof Subcomponent) {
Subcomponent sub = (Subcomponent) el;
if (el instanceof SubprogramGroupSubcomponent) {
result = ((SubprogramGroupSubcomponent) el).getClassifier();
} else {
// Subcomponent case.
result = sub.getClassifier();
// Subcomponent without classifier returns null.
if (result == null && sub.getPrototype() != null) {
result = prototypeResolver(sub.getPrototype(), parentContainer);
}
}
} else if (el instanceof BehaviorVariable) {
// Local variable case (BehaviorVariable).
BehaviorVariable bv = (BehaviorVariable) el;
result = bv.getDataClassifier();
} else if (el instanceof IterativeVariable) {
// Iterative variable case.
result = ((IterativeVariable) el).getDataClassifier();
} else if (el instanceof Prototype) {
result = prototypeResolver((Prototype) el, parentContainer);
} else if (el instanceof PrototypeBinding) {
// Prototype binding case.
result = prototypeBindingResolver((PrototypeBinding) el);
} else if (el instanceof ClassifierValue) {
// struct or union member case (ClassifierValue).
result = ((ClassifierValue) el).getClassifier();
} else if (el instanceof StructUnionElement) {
return ((StructUnionElement) el).getDataClassifier();
} else {
// Reports error.
String errorMsg = "getClassifier : " + el.getClass().getSimpleName() + " is not supported yet.";
System.err.println(errorMsg);
throw new UnsupportedOperationException(errorMsg);
}
return result;
}
use of org.osate.aadl2.ClassifierValue in project osate2 by osate.
the class AadlBaUtils method getBaseType.
/**
* Returns the last value of the base type property of the given component or
* {@code null} if the base type property is not set.
*
* @param component the given component
* @return the last value of the base type property or {@code null}
*/
public static ClassifierValue getBaseType(Classifier component) {
PropertyExpression pe;
EList<PropertyExpression> le;
Element el;
EList<PropertyExpression> lpe = PropertyUtils.findPropertyExpression(component, DataModelProperties.BASE_TYPE);
if (lpe != null && (!lpe.isEmpty())) {
pe = lpe.get(lpe.size() - 1);
// Syntax with ()
if (pe instanceof ListValue) {
le = ((ListValue) pe).getOwnedListElements();
if (le != null && (!le.isEmpty())) {
el = le.get(le.size() - 1);
if (el instanceof ClassifierValue) {
return (ClassifierValue) el;
}
}
} else // Syntax without ()
if (pe instanceof ClassifierValue) {
return (ClassifierValue) pe;
}
}
return null;
}
use of org.osate.aadl2.ClassifierValue 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;
}
}
Aggregations