use of org.osate.aadl2.ClassifierValue in project osate2 by osate.
the class GetProperties method getRequiredVirtualBusClass.
/**
* Get the virtual bus required for a connection, virtual bus, port, etc.
*
* @param io
* - the component which has the property
* @return - the list of virtual bus classifier
*/
public static List<ComponentClassifier> getRequiredVirtualBusClass(final NamedElement io) {
Property requiredVirtualBusClass;
ArrayList<ComponentClassifier> components;
requiredVirtualBusClass = lookupPropertyDefinition(io, DeploymentProperties._NAME, DeploymentProperties.REQUIRED_VIRTUAL_BUS_CLASS);
components = new ArrayList<ComponentClassifier>();
List<? extends PropertyExpression> propertyValues;
try {
propertyValues = io.getPropertyValueList(requiredVirtualBusClass);
} catch (Exception e) {
return components;
}
for (PropertyExpression propertyExpression : propertyValues) {
components.add((ComponentClassifier) ((ClassifierValue) propertyExpression).getClassifier());
}
return components;
}
use of org.osate.aadl2.ClassifierValue in project osate2 by osate.
the class GetProperties method getAllowedConnectionBindingClass.
public static List<Classifier> getAllowedConnectionBindingClass(final InstanceObject io) {
Property allowedConnectionBindingClass = lookupPropertyDefinition(io, DeploymentProperties._NAME, DeploymentProperties.ALLOWED_CONNECTION_BINDING_CLASS);
ArrayList<Classifier> components = new ArrayList<>();
List<? extends PropertyExpression> propertyValues;
try {
propertyValues = io.getPropertyValueList(allowedConnectionBindingClass);
} 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 GetProperties method getAllowedProcessorBindingClass.
public static List<Classifier> getAllowedProcessorBindingClass(final ComponentInstance io) {
Property allowedProcessorBindingClass = lookupPropertyDefinition(io, DeploymentProperties._NAME, DeploymentProperties.ALLOWED_PROCESSOR_BINDING_CLASS);
ArrayList<Classifier> components = new ArrayList<Classifier>();
List<? extends PropertyExpression> propertyValues;
try {
propertyValues = io.getPropertyValueList(allowedProcessorBindingClass);
} 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 DefaultBusinessObjectTreeUpdater method createPropertyValues.
private void createPropertyValues(final BusinessObjectNode node, final Property property, final PropertyResult pr, final Object value, final Deque<Integer> indicesStack, final String appliesToDescendantRef, final Multimap<BusinessObjectNode, AgePropertyValue> dstToPropertyValues) {
if (value instanceof List) {
@SuppressWarnings("unchecked") final List<Object> valueList = ((List<Object>) value);
int idx = 0;
for (final Object innerValue : valueList) {
indicesStack.addLast(idx);
createPropertyValues(node, property, pr, innerValue, indicesStack, appliesToDescendantRef, dstToPropertyValues);
indicesStack.removeLast();
idx++;
}
} else {
final BusinessObjectNode dst;
boolean fullyResolved = true;
if (value instanceof ReferenceValueWithContext) {
final AadlPropertyResolutionResults rr = ((ReferenceValueWithContext) value).resolve(node, queryService);
dst = (BusinessObjectNode) rr.dst;
fullyResolved = !rr.isPartial;
} else if (value instanceof ClassifierValue) {
dst = (BusinessObjectNode) PropertyValueUtil.getReferencedClassifier(node, (ClassifierValue) value, queryService);
} else if (value instanceof InstanceReferenceValue) {
final InstanceReferenceValue irv = (InstanceReferenceValue) value;
final InstanceObject referencedInstanceObject = irv.getReferencedInstanceObject();
final AadlPropertyResolutionResults rr = PropertyValueUtil.getReferencedInstanceObject(node, referencedInstanceObject, queryService);
dst = (BusinessObjectNode) rr.dst;
fullyResolved = !rr.isPartial;
} else {
dst = null;
}
dstToPropertyValues.put(dst, new AgePropertyValue(pr, indicesStack, appliesToDescendantRef, fullyResolved));
}
}
use of org.osate.aadl2.ClassifierValue in project AGREE by loonwerks.
the class AgreeTypeSystem method typeDefFromClassifier.
public static TypeDef typeDefFromClassifier(Classifier c) {
if (c instanceof DataType || (c instanceof DataImplementation && ((DataImplementation) c).getAllSubcomponents().isEmpty() && ((DataImplementation) c).getType() != null)) {
// Includes special case for data implementations implementing extensions of primitive types
Classifier classifierType = c instanceof DataImplementation ? ((DataImplementation) c).getType() : c;
List<PropertyAssociation> pas = classifierType.getAllPropertyAssociations();
for (Classifier classType : classifierType.getSelfPlusAllExtended()) {
if (classType != null && hasIntegerDataRepresentation(classType)) {
for (PropertyAssociation choice : pas) {
Property p = choice.getProperty();
PropertyExpression v = choice.getOwnedValues().get(0).getOwnedValue();
String key = p.getQualifiedName();
if (key.equals("Data_Model::Integer_Range")) {
if (v instanceof RangeValue) {
try {
RangeValue rangeValue = (RangeValue) v;
long min = intFromPropExp(rangeValue.getMinimum()).get();
long max = intFromPropExp(rangeValue.getMaximum()).get();
return new RangeIntTypeDef(min, max);
} catch (Exception e) {
return Prim.ErrorTypeDef;
}
}
}
}
return Prim.IntTypeDef;
} else if (classType != null && hasFloatDataRepresentation(classType)) {
for (PropertyAssociation choice : pas) {
Property p = choice.getProperty();
PropertyExpression v = choice.getOwnedValues().get(0).getOwnedValue();
String key = p.getQualifiedName();
if (key.equals("Data_Model::Real_Range")) {
if (v instanceof RangeValue) {
try {
RangeValue rangeValue = (RangeValue) v;
double min = realFromPropExp(rangeValue.getMinimum()).get();
double max = realFromPropExp(rangeValue.getMaximum()).get();
return new RangeRealTypeDef(min, max);
} catch (Exception e) {
return Prim.ErrorTypeDef;
}
}
}
}
return Prim.RealTypeDef;
} else if (classType != null && hasBooleanDataRepresentation(classType)) {
return Prim.BoolTypeDef;
}
}
boolean prop_isArray = false;
int prop_arraySize = 0;
TypeDef prop_arrayBaseType = null;
boolean prop_isEnum = false;
List<String> prop_enumValues = null;
for (PropertyAssociation choice : pas) {
Property p = choice.getProperty();
PropertyExpression v = choice.getOwnedValues().get(0).getOwnedValue();
String key = p.getQualifiedName();
key = key == null ? p.getName() : key;
if (key == null) {
return Prim.ErrorTypeDef;
}
if (key.equalsIgnoreCase("Data_Model::Data_Representation")) {
if (v instanceof NamedValue) {
AbstractNamedValue anv = ((NamedValue) v).getNamedValue();
if (anv instanceof EnumerationLiteral) {
EnumerationLiteral el = (EnumerationLiteral) anv;
prop_isArray = el.getName().equals("Array");
prop_isEnum = el.getName().equals("Enum");
}
}
} else if (key.equalsIgnoreCase("Data_Model::Enumerators")) {
if (v instanceof ListValue) {
EList<PropertyExpression> peList = ((ListValue) v).getOwnedListElements();
String prefix = c.getQualifiedName() + "_";
prop_enumValues = new ArrayList<>();
for (PropertyExpression pe : peList) {
if (pe instanceof StringLiteral) {
String enumString = prefix + ((StringLiteral) pe).getValue();
prop_enumValues.add(enumString);
}
}
}
} else if (key.equalsIgnoreCase("Data_Model::Base_Type")) {
if (v instanceof ListValue) {
ListValue l = (ListValue) v;
PropertyExpression pe = l.getOwnedListElements().get(0);
if (pe instanceof ClassifierValue) {
prop_arrayBaseType = typeDefFromClassifier(((ClassifierValue) pe).getClassifier());
}
}
} else if (key.equalsIgnoreCase("Data_Model::Dimension")) {
if (v instanceof ListValue) {
ListValue l = (ListValue) v;
PropertyExpression pe = l.getOwnedListElements().get(0);
prop_arraySize = Math.toIntExact(intFromPropExp(pe).orElse((long) -1).longValue());
}
}
}
if (prop_isArray && prop_arraySize > 0 && prop_arrayBaseType != null) {
return new ArrayTypeDef(prop_arrayBaseType, prop_arraySize, Optional.of(c));
} else if (prop_isEnum && prop_enumValues != null) {
String name = c.getQualifiedName();
return new EnumTypeDef(name, prop_enumValues, c);
}
} else if (c instanceof ComponentClassifier) {
Map<String, TypeDef> fields = new HashMap<>();
Classifier currClsfr = c;
while (currClsfr != null) {
ComponentType ct = null;
if (currClsfr instanceof ComponentImplementation) {
EList<Subcomponent> subcomps = ((ComponentImplementation) currClsfr).getAllSubcomponents();
for (Subcomponent sub : subcomps) {
String fieldName = sub.getName();
if (sub.getClassifier() != null) {
boolean prop_isArray = false;
int prop_arraySize = 0;
boolean prop_isEnum = false;
List<String> prop_enumValues = null;
for (PropertyAssociation pa : sub.getOwnedPropertyAssociations()) {
Property p = pa.getProperty();
String key = p.getQualifiedName();
key = key == null ? p.getName() : key;
PropertyExpression v = null;
if (!pa.getOwnedValues().isEmpty()) {
v = pa.getOwnedValues().get(0).getOwnedValue();
} else {
continue;
}
if (key.equals("Data_Model::Data_Representation")) {
if (v instanceof NamedValue) {
AbstractNamedValue anv = ((NamedValue) v).getNamedValue();
if (anv instanceof EnumerationLiteral) {
EnumerationLiteral el = (EnumerationLiteral) anv;
prop_isArray = el.getName().equals("Array");
prop_isEnum = el.getName().equals("Enum");
}
}
} else if (key.equals("Data_Model::Dimension")) {
if (v instanceof ListValue) {
ListValue l = (ListValue) v;
PropertyExpression pe = l.getOwnedListElements().get(0);
prop_arraySize = Math.toIntExact(intFromPropExp(pe).orElse((long) -1).longValue());
}
} else if (key.equals("Data_Model::Enumerators")) {
if (v instanceof ListValue) {
EList<PropertyExpression> peList = ((ListValue) v).getOwnedListElements();
String prefix = c.getQualifiedName() + "_";
prop_enumValues = new ArrayList<>();
for (PropertyExpression pe : peList) {
if (pe instanceof StringLiteral) {
String enumString = prefix + ((StringLiteral) pe).getValue();
prop_enumValues.add(enumString);
}
}
}
}
}
if (prop_isArray && prop_arraySize > 0) {
TypeDef typeDef = new ArrayTypeDef(typeDefFromClassifier(sub.getClassifier()), prop_arraySize, Optional.empty());
fields.putIfAbsent(fieldName, typeDef);
} else if (prop_isEnum && prop_enumValues != null) {
String name = c.getQualifiedName();
TypeDef typeDef = new EnumTypeDef(name, prop_enumValues, c);
fields.putIfAbsent(fieldName, typeDef);
} else if (sub.getArrayDimensions().size() == 0) {
TypeDef typeDef = typeDefFromClassifier(sub.getClassifier());
fields.putIfAbsent(fieldName, typeDef);
} else if (sub.getArrayDimensions().size() == 1) {
ArrayDimension ad = sub.getArrayDimensions().get(0);
int size = Math.toIntExact(getArraySize(ad));
TypeDef stem = typeDefFromClassifier(sub.getClassifier());
TypeDef typeDef = new ArrayTypeDef(stem, size, Optional.empty());
fields.putIfAbsent(fieldName, typeDef);
}
}
}
ct = ((ComponentImplementation) currClsfr).getType();
} else if (c instanceof ComponentType) {
ct = (ComponentType) currClsfr;
}
if (ct != null) {
EList<Feature> features = ct.getAllFeatures();
for (Feature feature : features) {
String fieldName = feature.getName();
if (feature.getClassifier() != null) {
if (feature.getArrayDimensions().size() == 0) {
TypeDef typeDef = typeDefFromClassifier(feature.getClassifier());
fields.putIfAbsent(fieldName, typeDef);
} else if (feature.getArrayDimensions().size() == 1) {
ArrayDimension ad = feature.getArrayDimensions().get(0);
int size = Math.toIntExact(getArraySize(ad));
TypeDef stem = typeDefFromClassifier(feature.getClassifier());
TypeDef typeDef = new ArrayTypeDef(stem, size, Optional.empty());
fields.putIfAbsent(fieldName, typeDef);
}
}
}
for (AnnexSubclause annex : AnnexUtil.getAllAnnexSubclauses(currClsfr, AgreePackage.eINSTANCE.getAgreeContractSubclause())) {
AgreeContract contract = (AgreeContract) ((AgreeContractSubclause) annex).getContract();
for (SpecStatement spec : contract.getSpecs()) {
List<Arg> args = new ArrayList<>();
if (spec instanceof EqStatement) {
args = ((EqStatement) spec).getLhs();
} else if (spec instanceof InputStatement) {
args = ((InputStatement) spec).getLhs();
}
for (Arg arg : args) {
String fieldName = arg.getName();
TypeDef typeDef = typeDefFromNE(arg);
fields.putIfAbsent(fieldName, typeDef);
}
if (spec instanceof ConstStatement) {
String fieldName = ((ConstStatement) spec).getName();
TypeDef typeDef = AgreeTypeSystem.typeDefFromType(((ConstStatement) spec).getType());
fields.putIfAbsent(fieldName, typeDef);
}
}
}
}
currClsfr = currClsfr.getExtended();
}
String name = c.getQualifiedName();
return new RecordTypeDef(name, fields, c);
}
return Prim.ErrorTypeDef;
}
Aggregations