Search in sources :

Example 76 with ListValue

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

the class PropertyResult method convertValue.

private static Object convertValue(final QueryService queryService, final PropertyExpression propertyExpression, final int processedAppliedToPathElements) {
    if (propertyExpression == null) {
        return null;
    }
    if (propertyExpression instanceof ListValue) {
        // Convert the ListValue to a java list
        final ListValue lv = (ListValue) propertyExpression;
        final List<Object> convertedList = new LinkedList<>();
        for (final PropertyExpression innerExpression : lv.getOwnedListElements()) {
            final Object innerValue = convertValue(queryService, innerExpression, processedAppliedToPathElements);
            if (innerValue != null) {
                convertedList.add(innerValue);
            }
        }
        return convertedList;
    } else if (propertyExpression instanceof ReferenceValue) {
        return new ReferenceValueWithContext((ReferenceValue) propertyExpression, processedAppliedToPathElements);
    } else {
        return propertyExpression;
    }
}
Also used : ReferenceValue(org.osate.aadl2.ReferenceValue) ListValue(org.osate.aadl2.ListValue) PropertyExpression(org.osate.aadl2.PropertyExpression) LinkedList(java.util.LinkedList)

Example 77 with ListValue

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

the class CachePropertyAssociationsSwitch method cacheConnectionPropertyAssociations.

protected void cacheConnectionPropertyAssociations(final ConnectionInstance conni) {
    PropertyAssociation setPA;
    PropertyExpression defaultvalue;
    try {
        /*
			 * propertyFilter contains all properties used by the system, so, we try to
			 * use the one associated to the connection instance and their reference and
			 * see if the user declares a specific value.
			 */
        for (Property prop : propertyFilter) {
            setPA = null;
            defaultvalue = prop.getDefaultValue();
            for (final ConnectionReference connRef : conni.getConnectionReferences()) {
                /*
					 * In the following piece of code, we check that a property
					 * is consistent all along the connection reference.
					 * For example, we check that the timing property (immediate, delayed)
					 * is consistent for each connection.
					 */
                if (connRef.acceptsProperty(prop)) {
                    /*
						 * Just look up the property. The property doesn't yet have
						 * a local association, so lookup will get the value from
						 * the declarative model. Property lookup process now
						 * corrects reference values to instance reference values.
						 */
                    final PropertyAssociation propAssociation = scProps.retrieveSCProperty(conni, prop, connRef.getConnection());
                    final EvaluationContext ctx = new EvaluationContext(connRef, classifierCache, propAssociation);
                    PropertyEvaluationResult result = prop.evaluate(ctx, 0);
                    List<EvaluatedProperty> evaluated = result.getEvaluated();
                    if (!evaluated.isEmpty()) {
                        PropertyAssociationInstance newPA = InstanceFactory.eINSTANCE.createPropertyAssociationInstance();
                        newPA.setProperty(prop);
                        newPA.setPropertyAssociation(getDeclarativePA(result.getPa()));
                        fillPropertyValue(connRef, newPA, evaluated);
                        if (!newPA.getOwnedValues().isEmpty()) {
                            /*
								 * FIXME JD
								 *
								 * Try to look if the property references a component or not.
								 * This was done to fix the issue related to the Bound Bus analysis plugin
								 */
                            for (Iterator<Element> content = EcoreUtil.getAllProperContents(newPA, false); content.hasNext(); ) {
                                Element elem = content.next();
                                if (elem instanceof ModalPropertyValue) {
                                    ModalPropertyValue mpv = (ModalPropertyValue) elem;
                                    if (mpv.getOwnedValue() instanceof ListValue) {
                                        ListValue lv = (ListValue) mpv.getOwnedValue();
                                        for (Element e : lv.getOwnedListElements()) {
                                            if (e instanceof ReferenceValue) {
                                                PropertyExpression irv = ((ReferenceValue) e).instantiate(conni.getContainingComponentInstance());
                                                if (irv != null) {
                                                    EcoreUtil.replace(e, irv);
                                                }
                                            }
                                        }
                                    }
                                }
                                if (elem instanceof ReferenceValue) {
                                    PropertyExpression irv = ((ReferenceValue) elem).instantiate(conni.getContainingComponentInstance());
                                    if (irv != null) {
                                        EcoreUtil.replace(elem, irv);
                                    }
                                }
                            }
                            scProps.recordSCProperty(conni, prop, connRef.getConnection(), newPA);
                            if (setPA == null) {
                                setPA = newPA;
                                conni.getOwnedPropertyAssociations().add(newPA);
                            } else {
                                // check consistency
                                for (Mode m : conni.getSystemInstance().getSystemOperationModes()) {
                                    PropertyExpression newVal = newPA.valueInMode(m);
                                    PropertyExpression setVal = setPA.valueInMode(m);
                                    if (!newVal.sameAs(setVal)) {
                                        error(conni, "Value for property " + setPA.getProperty().getQualifiedName() + " not consistent along connection");
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            checkIfCancelled();
            if (cancelled()) {
                break;
            }
        }
    } catch (IllegalStateException e) {
        // circular dependency
        // xxx: this is a misleading place to put the marker
        error(conni, e.getMessage());
        System.out.println("IllegalStateException raised in cacheConnectionPropertyAssociations");
    } catch (InvalidModelException e) {
        error(conni, e.getMessage());
        System.out.println("InvalidModelException raised in cacheConnectionPropertyAssociations");
    }
}
Also used : PropertyEvaluationResult(org.osate.aadl2.properties.PropertyEvaluationResult) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) ReferenceValue(org.osate.aadl2.ReferenceValue) Element(org.osate.aadl2.Element) ListValue(org.osate.aadl2.ListValue) Mode(org.osate.aadl2.Mode) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) InvalidModelException(org.osate.aadl2.properties.InvalidModelException) PropertyAssociationInstance(org.osate.aadl2.instance.PropertyAssociationInstance) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) PropertyExpression(org.osate.aadl2.PropertyExpression) EvaluationContext(org.osate.aadl2.properties.EvaluationContext) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) Property(org.osate.aadl2.Property)

Example 78 with ListValue

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

the class InstantiateModel method getIndices.

private List<Long> getIndices(RecordValue rv, String field) {
    List<Long> indices = new ArrayList<Long>();
    for (BasicPropertyAssociation fv : rv.getOwnedFieldValues()) {
        if (fv.getProperty().getName().equalsIgnoreCase(field)) {
            ListValue lv = (ListValue) fv.getOwnedValue();
            EList<PropertyExpression> vlist = lv.getOwnedListElements();
            // PropertyExpression elem = vlist.get(i);
            for (PropertyExpression elem : vlist) {
                indices.add(((IntegerLiteral) elem).getValue());
            }
        }
    }
    return indices;
}
Also used : ListValue(org.osate.aadl2.ListValue) ArrayList(java.util.ArrayList) PropertyExpression(org.osate.aadl2.PropertyExpression) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation)

Example 79 with ListValue

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

the class ValidateConnectionsSwitch method classifiersFoundInSupportedClassifierSubsetMatchesProperty.

// XXX How can I avoid duplicating this method for the instance and the declarative models?
private boolean classifiersFoundInSupportedClassifierSubsetMatchesProperty(ConnectionInstance connection, Classifier source, Classifier destination) {
    PropertyConstant matchesPropertyConstant = GetProperties.lookupPropertyConstant(connection, AadlProject.SUPPORTED_CLASSIFIER_SUBSET_MATCHES);
    if (matchesPropertyConstant == null) {
        return false;
    }
    PropertyExpression constantValue = matchesPropertyConstant.getConstantValue();
    if (!(constantValue instanceof ListValue)) {
        return false;
    }
    for (PropertyExpression classifierPair : ((ListValue) constantValue).getOwnedListElements()) {
        if (classifierPair instanceof ListValue) {
            EList<PropertyExpression> innerListElements = ((ListValue) classifierPair).getOwnedListElements();
            if (innerListElements.size() == 2 && innerListElements.get(0) instanceof ClassifierValue && innerListElements.get(1) instanceof ClassifierValue) {
                Classifier firstPairElement = ((ClassifierValue) innerListElements.get(0)).getClassifier();
                Classifier secondPairElement = ((ClassifierValue) innerListElements.get(1)).getClassifier();
                if (firstPairElement == source && secondPairElement == destination) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : ClassifierValue(org.osate.aadl2.ClassifierValue) ListValue(org.osate.aadl2.ListValue) PropertyExpression(org.osate.aadl2.PropertyExpression) InstantiatedClassifier(org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier) Classifier(org.osate.aadl2.Classifier) PropertyConstant(org.osate.aadl2.PropertyConstant)

Example 80 with ListValue

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

the class ValidateConnectionsSwitch method classifiersFoundInSupportedClassifierEquivalenceMatchesProperty.

// XXX How can I avoid duplicating this method for the instance and the declarative models?
private boolean classifiersFoundInSupportedClassifierEquivalenceMatchesProperty(final ConnectionInstance connection, Classifier source, Classifier destination) {
    final PropertyConstant matchesPropertyConstant = GetProperties.lookupPropertyConstant(connection, AadlProject.SUPPORTED_CLASSIFIER_EQUIVALENCE_MATCHES);
    if (matchesPropertyConstant == null) {
        return false;
    }
    final PropertyExpression constantValue = matchesPropertyConstant.getConstantValue();
    if (!(constantValue instanceof ListValue)) {
        return false;
    }
    for (final PropertyExpression classifierPair : ((ListValue) constantValue).getOwnedListElements()) {
        if (classifierPair instanceof ListValue) {
            EList<PropertyExpression> innerListElements = ((ListValue) classifierPair).getOwnedListElements();
            if (innerListElements.size() == 2 && innerListElements.get(0) instanceof ClassifierValue && innerListElements.get(1) instanceof ClassifierValue) {
                Classifier firstPairElement = ((ClassifierValue) innerListElements.get(0)).getClassifier();
                Classifier secondPairElement = ((ClassifierValue) innerListElements.get(1)).getClassifier();
                if ((firstPairElement == source && secondPairElement == destination) || (firstPairElement == destination && secondPairElement == source)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : ClassifierValue(org.osate.aadl2.ClassifierValue) ListValue(org.osate.aadl2.ListValue) PropertyExpression(org.osate.aadl2.PropertyExpression) InstantiatedClassifier(org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier) Classifier(org.osate.aadl2.Classifier) 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