Search in sources :

Example 46 with ListValue

use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.

the class AadlBaParserVisitor method clonePropertyExpression.

private PropertyExpression clonePropertyExpression(PropertyExpression sourcePropertyExpression) {
    PropertyExpression targetPropertyExpression = null;
    if (sourcePropertyExpression instanceof ListValue) {
        ListValue sourceLV = (ListValue) sourcePropertyExpression;
        ListValue targetLV = _coreFact.createListValue();
        for (PropertyExpression propInList : sourceLV.getOwnedListElements()) {
            targetLV.getOwnedListElements().add(clonePropertyExpression(propInList));
        }
        targetPropertyExpression = targetLV;
    } else if (sourcePropertyExpression instanceof StringLiteral) {
        StringLiteral sourceSL = (StringLiteral) sourcePropertyExpression;
        StringLiteral targetSL = _coreFact.createStringLiteral();
        targetSL.setValue(sourceSL.getValue());
        targetPropertyExpression = targetSL;
    } else if (sourcePropertyExpression instanceof IntegerLiteral) {
        IntegerLiteral sourceIL = (IntegerLiteral) sourcePropertyExpression;
        IntegerLiteral targetIL = _coreFact.createIntegerLiteral();
        targetIL.setValue(sourceIL.getValue());
        targetIL.setUnit(sourceIL.getUnit());
        targetPropertyExpression = targetIL;
    } else if (sourcePropertyExpression instanceof RealLiteral) {
        RealLiteral sourceRL = (RealLiteral) sourcePropertyExpression;
        RealLiteral targetRL = _coreFact.createRealLiteral();
        targetRL.setValue(sourceRL.getValue());
        targetRL.setUnit(sourceRL.getUnit());
        targetPropertyExpression = targetRL;
    } else if (sourcePropertyExpression instanceof RecordValue) {
        RecordValue sourceRV = (RecordValue) sourcePropertyExpression;
        RecordValue targetRV = _coreFact.createRecordValue();
        targetRV.getOwnedFieldValues().addAll(sourceRV.getOwnedFieldValues());
        targetPropertyExpression = targetRV;
    } else if (sourcePropertyExpression instanceof BooleanLiteral) {
        BooleanLiteral sourceBL = (BooleanLiteral) sourcePropertyExpression;
        BooleanLiteral targetBL = _coreFact.createBooleanLiteral();
        targetBL.setValue(sourceBL.getValue());
        targetPropertyExpression = targetBL;
    } else if (sourcePropertyExpression instanceof RangeValue) {
        RangeValue sourceRV = (RangeValue) sourcePropertyExpression;
        RangeValue targetRV = _coreFact.createRangeValue();
        targetRV.setMinimum(clonePropertyExpression(sourceRV.getMinimum()));
        targetRV.setMaximum(clonePropertyExpression(sourceRV.getMaximum()));
        targetPropertyExpression = targetRV;
    } else if (sourcePropertyExpression instanceof DeclarativeReferenceValue) {
        DeclarativeReferenceValue sourceDRV = (DeclarativeReferenceValue) sourcePropertyExpression;
        ReferenceValue targetRV = _coreFact.createReferenceValue();
        targetRV.setPath(sourceDRV.getRef());
        targetPropertyExpression = targetRV;
    } else if (sourcePropertyExpression instanceof DeclarativeClassifierValue) {
        DeclarativeClassifierValue sourceDCV = (DeclarativeClassifierValue) sourcePropertyExpression;
        ClassifierValue targetCV = _coreFact.createClassifierValue();
        targetCV.setClassifier(sourceDCV.getClassifier());
        targetPropertyExpression = targetCV;
    }
    return targetPropertyExpression;
}
Also used : RealLiteral(org.osate.aadl2.RealLiteral) BehaviorRealLiteral(org.osate.ba.aadlba.BehaviorRealLiteral) ClassifierValue(org.osate.aadl2.ClassifierValue) DeclarativeClassifierValue(org.osate.ba.declarative.DeclarativeClassifierValue) BehaviorStringLiteral(org.osate.ba.aadlba.BehaviorStringLiteral) StringLiteral(org.osate.aadl2.StringLiteral) DeclarativeReferenceValue(org.osate.ba.declarative.DeclarativeReferenceValue) BehaviorBooleanLiteral(org.osate.ba.aadlba.BehaviorBooleanLiteral) BooleanLiteral(org.osate.aadl2.BooleanLiteral) DeclarativeReferenceValue(org.osate.ba.declarative.DeclarativeReferenceValue) ReferenceValue(org.osate.aadl2.ReferenceValue) DeclarativeClassifierValue(org.osate.ba.declarative.DeclarativeClassifierValue) ListValue(org.osate.aadl2.ListValue) RecordValue(org.osate.aadl2.RecordValue) PropertyExpression(org.osate.aadl2.PropertyExpression) DeclarativePropertyExpression(org.osate.ba.declarative.DeclarativePropertyExpression) IntegerLiteral(org.osate.aadl2.IntegerLiteral) BehaviorIntegerLiteral(org.osate.ba.aadlba.BehaviorIntegerLiteral) RangeValue(org.osate.aadl2.RangeValue)

Example 47 with ListValue

use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.

the class PropertyUtils method getStringListValue.

/**
 * Extract String list value from a specified property. May return null.
 *
 * @param i
 *            component instance.
 * @param propertyName
 *            property name.
 * @return property value.
 */
public static List<String> getStringListValue(NamedElement i, String propertyName) {
    List<String> res = new ArrayList<String>();
    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 ListValue) {
                    ListValue lv = (ListValue) expr;
                    for (PropertyExpression pe : lv.getOwnedListElements()) {
                        if (pe instanceof StringLiteral) {
                            StringLiteral sl = (StringLiteral) pe;
                            res.add(sl.getValue());
                        } else if (pe instanceof NamedValue) {
                            NamedValue nv = (NamedValue) pe;
                            if (nv.getNamedValue() instanceof EnumerationLiteral) {
                                EnumerationLiteral el = (EnumerationLiteral) nv.getNamedValue();
                                res.add(el.getName());
                            }
                        }
                    }
                    if (!res.isEmpty()) {
                        return res;
                    }
                }
            }
        }
    }
    return null;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) StringLiteral(org.osate.aadl2.StringLiteral) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ListValue(org.osate.aadl2.ListValue) ArrayList(java.util.ArrayList) PropertyExpression(org.osate.aadl2.PropertyExpression) NamedValue(org.osate.aadl2.NamedValue) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral)

Example 48 with ListValue

use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.

the class AadlBaNameResolver method propertyExpressionResolver.

/**
 * Resolves the property expressions used in behavior annex.
 * @param p
 *
 * @return {@code true} if all names are resolved. {@code false} otherwise.
 */
private boolean propertyExpressionResolver(BehaviorVariable bv, Property p, PropertyExpression pe) {
    QualifiedNamedElement qne = (QualifiedNamedElement) p;
    String propertyName = "";
    boolean hasNamespace = qne.getBaNamespace() != null;
    if (hasNamespace) {
        propertyName = qne.getBaNamespace().getId() + "::";
    }
    propertyName += qne.getBaName().getId();
    boolean result = true;
    if (pe instanceof DeclarativeListValue) {
        ListValue dlv = (DeclarativeListValue) pe;
        for (PropertyExpression peInList : dlv.getOwnedListElements()) {
            result &= propertyExpressionResolver(bv, p, peInList);
        }
    } else if (pe instanceof IntegerLiteral) {
        IntegerLiteral il = (IntegerLiteral) pe;
        if (il.getUnit() != null && il.getUnit() instanceof QualifiedNamedElement) {
            result &= unitResolver(il, bv, p);
        }
    } else if (pe instanceof RealLiteral) {
        RealLiteral rl = (RealLiteral) pe;
        if (rl.getUnit() != null && rl.getUnit() instanceof QualifiedNamedElement) {
            result &= unitResolver(rl, bv, p);
        }
    } else if (pe instanceof RecordValue) {
        RecordValue rv = (RecordValue) pe;
        for (BasicPropertyAssociation bpa : rv.getOwnedFieldValues()) {
            if (bpa instanceof DeclarativeBasicPropertyAssociation) {
                DeclarativeBasicPropertyAssociation dbpa = (DeclarativeBasicPropertyAssociation) bpa;
                String basicPropertyName = dbpa.getBasicPropertyName();
                BasicProperty basicProp = getBasicPropertyResolver(bv, p, basicPropertyName);
                if (basicProp == null) {
                    _errManager.error(bv, "Property field \'" + basicPropertyName + "\' of property " + propertyName + " is not found");
                    result = false;
                }
                dbpa.setProperty(basicProp);
            }
        }
    } else if (pe instanceof RangeValue) {
        RangeValue rv = (RangeValue) pe;
        result &= propertyExpressionResolver(bv, p, rv.getMaximum());
        result &= propertyExpressionResolver(bv, p, rv.getMinimum());
    } else if (pe instanceof ReferenceValue) {
        ReferenceValue rv = (ReferenceValue) pe;
        Reference r = (Reference) (rv.getPath());
        ContainmentPathElement firstCne = Aadl2Factory.eINSTANCE.createContainmentPathElement();
        ContainmentPathElement prevCne = null;
        boolean first = true;
        Classifier context = _baParentContainer;
        for (Identifier subPath : r.getIds()) {
            ContainmentPathElement currentCne;
            if (!first) {
                currentCne = Aadl2Factory.eINSTANCE.createContainmentPathElement();
            } else {
                currentCne = firstCne;
            }
            first = false;
            NamedElement ne = Aadl2Visitors.findSubcomponentInComponent(context, subPath.getId());
            if (ne == null) {
                ne = Aadl2Visitors.findFeatureInComponent(context, subPath.getId());
            }
            if (ne == null) {
                _errManager.error(bv, "Element \'" + subPath.getId() + "\' is not found in " + context.getName() + "(property " + propertyName + ")");
                result = false;
            } else {
                currentCne.setNamedElement(ne);
                if (prevCne != null) {
                    prevCne.setPath(currentCne);
                }
                if (ne instanceof Subcomponent) {
                    Subcomponent sub = (Subcomponent) ne;
                    context = sub.getClassifier();
                } else if (ne instanceof Feature) {
                    Feature f = (Feature) ne;
                    context = f.getClassifier();
                }
            }
            prevCne = currentCne;
        }
        rv.setPath(firstCne);
    } else if (pe instanceof ClassifierValue) {
        ClassifierValue cv = (ClassifierValue) pe;
        QualifiedNamedElement classifierQne = (QualifiedNamedElement) cv.getClassifier();
        String qneClassPackageName = "";
        boolean qneClassHasNamespace = classifierQne.getBaNamespace() != null;
        if (qneClassHasNamespace) {
            qneClassPackageName = classifierQne.getBaNamespace().getId();
        }
        boolean resolved = false;
        for (PackageSection context : _contextsTab) {
            NamedElement ne = Aadl2Visitors.findElementInPackage(classifierQne.getBaName().getId(), qneClassPackageName, context);
            if (ne != null && ne instanceof Classifier) {
                cv.setClassifier((Classifier) ne);
                resolved = true;
                break;
            }
        }
        if (!resolved) {
            String cvQualifiedName = "";
            if (!qneClassPackageName.isEmpty()) {
                cvQualifiedName += qneClassPackageName + "::";
            }
            cvQualifiedName += classifierQne.getBaName().getId();
            _errManager.error(bv, "Classifier \'" + cvQualifiedName + "\' associated to property " + propertyName + " is not found");
            result = false;
        }
    }
    return result;
}
Also used : ClassifierValue(org.osate.aadl2.ClassifierValue) ReferenceValue(org.osate.aadl2.ReferenceValue) DeclarativePropertyReference(org.osate.ba.declarative.DeclarativePropertyReference) Reference(org.osate.ba.declarative.Reference) PackageSection(org.osate.aadl2.PackageSection) ListValue(org.osate.aadl2.ListValue) DeclarativeListValue(org.osate.ba.declarative.DeclarativeListValue) DeclarativeListValue(org.osate.ba.declarative.DeclarativeListValue) RecordValue(org.osate.aadl2.RecordValue) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) Feature(org.osate.aadl2.Feature) ClassifierFeature(org.osate.aadl2.ClassifierFeature) RangeValue(org.osate.aadl2.RangeValue) RealLiteral(org.osate.aadl2.RealLiteral) BasicProperty(org.osate.aadl2.BasicProperty) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) Identifier(org.osate.ba.declarative.Identifier) ArrayableIdentifier(org.osate.ba.declarative.ArrayableIdentifier) Subcomponent(org.osate.aadl2.Subcomponent) PropertyExpression(org.osate.aadl2.PropertyExpression) DeclarativeBasicPropertyAssociation(org.osate.ba.declarative.DeclarativeBasicPropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) DeclarativeBasicPropertyAssociation(org.osate.ba.declarative.DeclarativeBasicPropertyAssociation) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) NamedElement(org.osate.aadl2.NamedElement) IntegerLiteral(org.osate.aadl2.IntegerLiteral) BehaviorIntegerLiteral(org.osate.ba.aadlba.BehaviorIntegerLiteral)

Example 49 with ListValue

use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.

the class DeploymentProperties method getAllowedPhysicalAccess.

public static Optional<List<InstanceObject>> getAllowedPhysicalAccess(NamedElement lookupContext, Optional<Mode> mode) {
    Property property = getAllowedPhysicalAccess_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 ((InstanceReferenceValue) resolved1).getReferencedInstanceObject();
        }).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) InstanceReferenceValue(org.osate.aadl2.instance.InstanceReferenceValue) Property(org.osate.aadl2.Property)

Example 50 with ListValue

use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.

the class DeploymentProperties method getRequiredConnectionQualityOfService.

public static Optional<List<SupportedConnectionQos>> getRequiredConnectionQualityOfService(NamedElement lookupContext, Optional<Mode> mode) {
    Property property = getRequiredConnectionQualityOfService_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 SupportedConnectionQos.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)

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