Search in sources :

Example 66 with ListValue

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;
}
Also used : ListValue(org.osate.aadl2.ListValue) RecordValue(org.osate.aadl2.RecordValue) PropertyExpression(org.osate.aadl2.PropertyExpression)

Example 67 with ListValue

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);
            }
    }
}
Also used : ComputedValue(org.osate.aadl2.ComputedValue) ClassifierValue(org.osate.aadl2.ClassifierValue) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) Element(org.osate.aadl2.Element) RefinableElement(org.osate.aadl2.RefinableElement) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) ListValue(org.osate.aadl2.ListValue) RecordValue(org.osate.aadl2.RecordValue) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) NamedValue(org.osate.aadl2.NamedValue) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) BasicEList(org.eclipse.emf.common.util.BasicEList) EList(org.eclipse.emf.common.util.EList) StringLiteral(org.osate.aadl2.StringLiteral) PropertyExpression(org.osate.aadl2.PropertyExpression) InstanceReferenceValue(org.osate.aadl2.instance.InstanceReferenceValue) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property)

Example 68 with ListValue

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();
    }
}
Also used : PropertyNotPresentException(org.osate.aadl2.properties.PropertyNotPresentException) ListValue(org.osate.aadl2.ListValue) PropertyExpression(org.osate.aadl2.PropertyExpression) Property(org.osate.aadl2.Property)

Example 69 with ListValue

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());
}
Also used : ClassifierValue(org.osate.aadl2.ClassifierValue) ListValue(org.osate.aadl2.ListValue) IntegerWithUnits(org.osate.pluginsupport.properties.IntegerWithUnits) IntegerLiteral(org.osate.aadl2.IntegerLiteral) EObject(org.eclipse.emf.ecore.EObject) PropertyConstant(org.osate.aadl2.PropertyConstant) Collectors(java.util.stream.Collectors) Aadl2GlobalScopeUtil(org.osate.aadl2.modelsupport.scoping.Aadl2GlobalScopeUtil) PropertyExpression(org.osate.aadl2.PropertyExpression) CodeGenUtil(org.osate.pluginsupport.properties.CodeGenUtil) List(java.util.List) Classifier(org.osate.aadl2.Classifier) Aadl2Package(org.osate.aadl2.Aadl2Package) ClassifierValue(org.osate.aadl2.ClassifierValue) ListValue(org.osate.aadl2.ListValue) PropertyExpression(org.osate.aadl2.PropertyExpression) PropertyConstant(org.osate.aadl2.PropertyConstant)

Example 70 with ListValue

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());
}
Also used : ClassifierValue(org.osate.aadl2.ClassifierValue) ListValue(org.osate.aadl2.ListValue) IntegerWithUnits(org.osate.pluginsupport.properties.IntegerWithUnits) IntegerLiteral(org.osate.aadl2.IntegerLiteral) EObject(org.eclipse.emf.ecore.EObject) PropertyConstant(org.osate.aadl2.PropertyConstant) Collectors(java.util.stream.Collectors) Aadl2GlobalScopeUtil(org.osate.aadl2.modelsupport.scoping.Aadl2GlobalScopeUtil) PropertyExpression(org.osate.aadl2.PropertyExpression) CodeGenUtil(org.osate.pluginsupport.properties.CodeGenUtil) List(java.util.List) Classifier(org.osate.aadl2.Classifier) Aadl2Package(org.osate.aadl2.Aadl2Package) ClassifierValue(org.osate.aadl2.ClassifierValue) ListValue(org.osate.aadl2.ListValue) PropertyExpression(org.osate.aadl2.PropertyExpression) PropertyConstant(org.osate.aadl2.PropertyConstant)

Aggregations

ListValue (org.osate.aadl2.ListValue)101 PropertyExpression (org.osate.aadl2.PropertyExpression)85 Property (org.osate.aadl2.Property)64 PropertyNotPresentException (org.osate.aadl2.properties.PropertyNotPresentException)51 ClassifierValue (org.osate.aadl2.ClassifierValue)29 StringLiteral (org.osate.aadl2.StringLiteral)24 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)22 PropertyAssociation (org.osate.aadl2.PropertyAssociation)21 InstanceReferenceValue (org.osate.aadl2.instance.InstanceReferenceValue)21 IntegerLiteral (org.osate.aadl2.IntegerLiteral)19 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)19 RecordValue (org.osate.aadl2.RecordValue)19 ReferenceValue (org.osate.aadl2.ReferenceValue)16 NamedValue (org.osate.aadl2.NamedValue)15 Classifier (org.osate.aadl2.Classifier)14 RangeValue (org.osate.aadl2.RangeValue)13 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)12 ArrayList (java.util.ArrayList)11 BooleanLiteral (org.osate.aadl2.BooleanLiteral)11 PropertyConstant (org.osate.aadl2.PropertyConstant)11