use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.
the class PropertyUtils method getListRecordValue.
public static List<RecordValue> getListRecordValue(NamedElement ne, String propertyName) {
List<RecordValue> result = null;
ListValue lv = getListValue(ne, propertyName);
if (lv != null) {
EList<PropertyExpression> pes = lv.getOwnedListElements();
if (pes.size() != 0 && pes.get(0) instanceof RecordValue) {
result = new ArrayList<RecordValue>(pes.size());
for (PropertyExpression pe : pes) {
result.add((RecordValue) pe);
}
}
}
return result;
}
use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.
the class PropertyUtils method getValue.
/**
* Returns the first property expression or abstract named element (
* EnumerationLiteral, Property, PropertyConstant, UnitLiteral) that matches
* to the given String object within the given ProperyExpression object.
* If the property expression doesn't exist, it returns {@code null}.
*
* @param pe the given ProperyExpression object
* @param toBeMatched the given String object
* @return the first matching property expression or abstract named element.
* otherwise return {@code null}
*
* @throws UnsupportedOperationException for other property values than:
* _ StringLiteral
* _ ListValue (recursion supported)
* _ ClassifierValue
* _ InstanceReferenceValue
* _ ComputedValue
* _ RecordValue (based on field matching)
* _ NamedValue (returns abstract named element)
*/
public static Element getValue(PropertyExpression pe, String toBeMatched) {
Element tmp = null;
int id = pe.eClass().getClassifierID();
switch(id) {
case Aadl2Package.STRING_LITERAL:
{
StringLiteral sl = (StringLiteral) pe;
if (sl.getValue().equalsIgnoreCase(toBeMatched)) {
return sl;
}
return null;
}
case Aadl2Package.LIST_VALUE:
{
ListValue lv = (ListValue) pe;
EList<PropertyExpression> pel = lv.getOwnedListElements();
for (PropertyExpression ownedPe : pel) {
tmp = getValue(ownedPe, toBeMatched);
if (tmp != null) {
return tmp;
}
}
return null;
}
case Aadl2Package.RECORD_VALUE:
{
RecordValue rv = (RecordValue) pe;
for (BasicPropertyAssociation bpa : rv.getOwnedFieldValues()) {
if (bpa.getProperty().getName().equalsIgnoreCase(toBeMatched)) {
return bpa.getValue();
}
}
return null;
}
case Aadl2Package.CLASSIFIER_VALUE:
{
ClassifierValue cv = (ClassifierValue) pe;
if (cv.getClassifier().getName().equalsIgnoreCase(toBeMatched)) {
return cv;
} else {
return null;
}
}
case Aadl2Package.REFERENCE_VALUE:
{
InstanceReferenceValue irv = (InstanceReferenceValue) pe;
if (irv.getReferencedInstanceObject().getName().equalsIgnoreCase(toBeMatched)) {
return irv;
} else {
return null;
}
}
case Aadl2Package.COMPUTED_VALUE:
{
ComputedValue cv = (ComputedValue) pe;
if (cv.getFunction().equalsIgnoreCase(toBeMatched)) {
return cv;
} else {
return null;
}
}
case Aadl2Package.NAMED_VALUE:
{
NamedValue nv = (NamedValue) pe;
AbstractNamedValue anv = nv.getNamedValue();
if (anv instanceof NamedElement) {
NamedElement ne = (NamedElement) anv;
String name = ((NamedElement) anv).getName();
// Consider as a final node.
if (name.equalsIgnoreCase(toBeMatched)) {
return ne;
} else if (// Or a structure.
ne instanceof Property) {
Property p = (Property) ne;
if (p.getDefaultValue() != null) {
tmp = getValue(p.getDefaultValue(), toBeMatched);
return tmp;
}
}
} else {
String msg = anv.getClass().getSimpleName() + " is not supported";
System.err.println(msg);
throw new UnsupportedOperationException(msg);
}
return null;
}
default:
{
String msg = pe.getClass().getSimpleName() + " is not supported";
System.err.println(msg);
throw new UnsupportedOperationException(msg);
}
}
}
use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.
the class ProgrammingProperties method getSourceLanguage.
public static Optional<List<SupportedSourceLanguages>> getSourceLanguage(NamedElement lookupContext, Optional<Mode> mode) {
Property property = getSourceLanguage_Property(lookupContext);
try {
PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
return Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> {
PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode);
return SupportedSourceLanguages.valueOf(resolved1);
}).collect(Collectors.toList()));
} catch (PropertyNotPresentException e) {
return Optional.empty();
}
}
use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.
the class AadlProject method getSupportedClassifierEquivalenceMatches.
public static List<List<Classifier>> getSupportedClassifierEquivalenceMatches(EObject lookupContext) {
PropertyConstant constant = getSupportedClassifierEquivalenceMatches_PropertyConstant(lookupContext);
PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue());
return ((ListValue) resolved).getOwnedListElements().stream().map(element1 -> {
PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1);
return ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> {
PropertyExpression resolved2 = CodeGenUtil.resolveNamedValue(element2);
return ((ClassifierValue) resolved2).getClassifier();
}).collect(Collectors.toList());
}).collect(Collectors.toList());
}
use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.
the class AadlProject method getSupportedClassifierSubsetMatches.
public static List<List<Classifier>> getSupportedClassifierSubsetMatches(EObject lookupContext) {
PropertyConstant constant = getSupportedClassifierSubsetMatches_PropertyConstant(lookupContext);
PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue());
return ((ListValue) resolved).getOwnedListElements().stream().map(element1 -> {
PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1);
return ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> {
PropertyExpression resolved2 = CodeGenUtil.resolveNamedValue(element2);
return ((ClassifierValue) resolved2).getClassifier();
}).collect(Collectors.toList());
}).collect(Collectors.toList());
}
Aggregations