Search in sources :

Example 81 with ListValue

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

the class ValidateConnectionsSwitch method classifiersFoundInSupportedTypeConversionsProperty.

// XXX How can I avoid duplicating this method for the instance and the declarative models?
private boolean classifiersFoundInSupportedTypeConversionsProperty(ConnectionInstance connection, Classifier source, Classifier destination) {
    PropertyConstant conversionsPropertyConstant = GetProperties.lookupPropertyConstant(connection, AadlProject.SUPPORTED_TYPE_CONVERSIONS);
    if (conversionsPropertyConstant == null) {
        return false;
    }
    PropertyExpression constantValue = conversionsPropertyConstant.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 82 with ListValue

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

the class AbstractInstanceSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == Aadl2Package.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case Aadl2Package.ARRAY_RANGE:
                sequence_ArrayRange(context, (ArrayRange) semanticObject);
                return;
            case Aadl2Package.BASIC_PROPERTY_ASSOCIATION:
                sequence_FieldPropertyAssociation(context, (BasicPropertyAssociation) semanticObject);
                return;
            case Aadl2Package.BOOLEAN_LITERAL:
                sequence_BooleanLiteral(context, (BooleanLiteral) semanticObject);
                return;
            case Aadl2Package.CLASSIFIER_VALUE:
                sequence_ComponentClassifierTerm(context, (ClassifierValue) semanticObject);
                return;
            case Aadl2Package.COMPUTED_VALUE:
                sequence_ComputedTerm(context, (ComputedValue) semanticObject);
                return;
            case Aadl2Package.CONTAINED_NAMED_ELEMENT:
                sequence_ContainmentPath(context, (ContainedNamedElement) semanticObject);
                return;
            case Aadl2Package.CONTAINMENT_PATH_ELEMENT:
                sequence_ContainmentPathElement(context, (ContainmentPathElement) semanticObject);
                return;
            case Aadl2Package.INTEGER_LITERAL:
                sequence_IntegerTerm(context, (IntegerLiteral) semanticObject);
                return;
            case Aadl2Package.LIST_VALUE:
                sequence_ListTerm(context, (ListValue) semanticObject);
                return;
            case Aadl2Package.MODAL_PROPERTY_VALUE:
                if (rule == grammarAccess.getModalPropertyValueRule()) {
                    sequence_ModalPropertyValue(context, (ModalPropertyValue) semanticObject);
                    return;
                } else if (rule == grammarAccess.getOptionalModalPropertyValueRule()) {
                    sequence_OptionalModalPropertyValue(context, (ModalPropertyValue) semanticObject);
                    return;
                } else if (rule == grammarAccess.getPropertyValueRule()) {
                    sequence_PropertyValue(context, (ModalPropertyValue) semanticObject);
                    return;
                } else
                    break;
            case Aadl2Package.NAMED_VALUE:
                if (rule == grammarAccess.getConstantValueRule() || rule == grammarAccess.getNumAltRule()) {
                    sequence_ConstantValue(context, (NamedValue) semanticObject);
                    return;
                } else if (rule == grammarAccess.getPropertyExpressionRule() || rule == grammarAccess.getLiteralorReferenceTermRule()) {
                    sequence_LiteralorReferenceTerm(context, (NamedValue) semanticObject);
                    return;
                } else
                    break;
            case Aadl2Package.OPERATION:
                sequence_SignedConstant(context, (Operation) semanticObject);
                return;
            case Aadl2Package.PROPERTY_ASSOCIATION:
                if (rule == grammarAccess.getBasicPropertyAssociationRule()) {
                    sequence_BasicPropertyAssociation(context, (PropertyAssociation) semanticObject);
                    return;
                } else if (rule == grammarAccess.getPModelRule() || rule == grammarAccess.getContainedPropertyAssociationRule()) {
                    sequence_ContainedPropertyAssociation(context, (PropertyAssociation) semanticObject);
                    return;
                } else if (rule == grammarAccess.getPropertyAssociationRule()) {
                    sequence_PropertyAssociation(context, (PropertyAssociation) semanticObject);
                    return;
                } else
                    break;
            case Aadl2Package.RANGE_VALUE:
                sequence_NumericRangeTerm(context, (RangeValue) semanticObject);
                return;
            case Aadl2Package.REAL_LITERAL:
                sequence_RealTerm(context, (RealLiteral) semanticObject);
                return;
            case Aadl2Package.RECORD_VALUE:
                if (rule == grammarAccess.getOldRecordTermRule()) {
                    sequence_OldRecordTerm(context, (RecordValue) semanticObject);
                    return;
                } else if (rule == grammarAccess.getPropertyExpressionRule() || rule == grammarAccess.getRecordTermRule()) {
                    sequence_RecordTerm(context, (RecordValue) semanticObject);
                    return;
                } else
                    break;
            case Aadl2Package.REFERENCE_VALUE:
                sequence_ReferenceTerm(context, (ReferenceValue) semanticObject);
                return;
            case Aadl2Package.STRING_LITERAL:
                sequence_StringTerm(context, (StringLiteral) semanticObject);
                return;
        }
    else if (epackage == InstancePackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case InstancePackage.COMPONENT_INSTANCE:
                sequence_ComponentInstance(context, (ComponentInstance) semanticObject);
                return;
            case InstancePackage.CONNECTION_INSTANCE:
                sequence_ConnectionInstance(context, (ConnectionInstance) semanticObject);
                return;
            case InstancePackage.CONNECTION_REFERENCE:
                sequence_ConnectionReference(context, (ConnectionReference) semanticObject);
                return;
            case InstancePackage.END_TO_END_FLOW_INSTANCE:
                sequence_EndToEndFlowInstance(context, (EndToEndFlowInstance) semanticObject);
                return;
            case InstancePackage.FEATURE_INSTANCE:
                sequence_FeatureInstance(context, (FeatureInstance) semanticObject);
                return;
            case InstancePackage.FLOW_SPECIFICATION_INSTANCE:
                sequence_FlowSpecificationInstance(context, (FlowSpecificationInstance) semanticObject);
                return;
            case InstancePackage.INSTANCE_REFERENCE_VALUE:
                sequence_InstanceReferenceValue(context, (InstanceReferenceValue) semanticObject);
                return;
            case InstancePackage.MODE_INSTANCE:
                sequence_ModeInstance(context, (ModeInstance) semanticObject);
                return;
            case InstancePackage.MODE_TRANSITION_INSTANCE:
                sequence_ModeTransitionInstance(context, (ModeTransitionInstance) semanticObject);
                return;
            case InstancePackage.PROPERTY_ASSOCIATION_INSTANCE:
                sequence_PropertyAssociationInstance(context, (PropertyAssociationInstance) semanticObject);
                return;
            case InstancePackage.SYSTEM_INSTANCE:
                sequence_SystemInstance(context, (SystemInstance) semanticObject);
                return;
            case InstancePackage.SYSTEM_OPERATION_MODE:
                sequence_SystemOperationMode(context, (SystemOperationMode) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) ComputedValue(org.osate.aadl2.ComputedValue) Action(org.eclipse.xtext.Action) ClassifierValue(org.osate.aadl2.ClassifierValue) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) BooleanLiteral(org.osate.aadl2.BooleanLiteral) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) InstanceReferenceValue(org.osate.aadl2.instance.InstanceReferenceValue) ReferenceValue(org.osate.aadl2.ReferenceValue) ListValue(org.osate.aadl2.ListValue) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) RecordValue(org.osate.aadl2.RecordValue) ArrayRange(org.osate.aadl2.ArrayRange) NamedValue(org.osate.aadl2.NamedValue) Operation(org.osate.aadl2.Operation) RangeValue(org.osate.aadl2.RangeValue) EPackage(org.eclipse.emf.ecore.EPackage) RealLiteral(org.osate.aadl2.RealLiteral) StringLiteral(org.osate.aadl2.StringLiteral) Parameter(org.eclipse.xtext.Parameter) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) IntegerLiteral(org.osate.aadl2.IntegerLiteral)

Example 83 with ListValue

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

the class NamedElementImpl method setPropertyValue.

public final PropertyAssociation setPropertyValue(final Property pd, final List<? extends PropertyExpression> pes) {
    checkPropertyAssociation(pd, pes);
    PropertyAssociation pa = Aadl2Factory.eINSTANCE.createPropertyAssociation();
    pa.setProperty(pd);
    ModalPropertyValue mpv = pa.createOwnedValue();
    ListValue lv = (ListValue) mpv.createOwnedValue(Aadl2Package.eINSTANCE.getListValue());
    lv.getOwnedListElements().addAll(pes);
    if (this instanceof InstanceObject) {
        final SystemInstance si = ((InstanceObject) this).getSystemInstance();
        final SystemOperationMode som = si.getCurrentSystemOperationMode();
        if (som == null) {
            // non-modal instance model
            removePropertyAssociations(pd);
        } else {
            mpv.getInModes().add(som);
            removePropertyAssociations(pd, Collections.singletonList(som));
        }
    } else {
        removePropertyAssociations(pd);
    }
    getOwnedPropertyAssociations().add(pa);
    return pa;
}
Also used : InstanceObject(org.osate.aadl2.instance.InstanceObject) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) SystemInstance(org.osate.aadl2.instance.SystemInstance) ListValue(org.osate.aadl2.ListValue) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode)

Example 84 with ListValue

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

the class NamedElementImpl method getPropertyValueList.

/**
 * Retrieves a non-modal property value as a list.  Use this method if you
 * know that the property is defined as a LIST OF.  While this method can be used
 * on scalar properties, getSimplePropertyValue should be used if you know that it is
 * scalar.  If the property is scalar, a list of length 1 is returned.
 *
 * @param property PropertyDefinition
 * @return A list of PropertyValues.  This does not return null.
 */
public final List<PropertyExpression> getPropertyValueList(final Property property) throws InvalidModelException, IllegalArgumentException, PropertyNotPresentException, PropertyIsModalException, IllegalStateException, PropertyDoesNotApplyToHolderException {
    try {
        PropertyExpression pe = getNonModalPropertyValue(property);
        if (pe instanceof ListValue) {
            return ((ListValue) pe).getOwnedListElements();
        } else {
            List<PropertyExpression> pes = new BasicEList<PropertyExpression>();
            pes.add(pe);
            return pes;
        }
    } catch (Exception e) {
        return Collections.emptyList();
    }
}
Also used : ListValue(org.osate.aadl2.ListValue) BasicEList(org.eclipse.emf.common.util.BasicEList) PropertyExpression(org.osate.aadl2.PropertyExpression) PropertyIsListException(org.osate.aadl2.properties.PropertyIsListException) PropertyIsModalException(org.osate.aadl2.properties.PropertyIsModalException) InvalidModelException(org.osate.aadl2.properties.InvalidModelException) PropertyDoesNotApplyToHolderException(org.osate.aadl2.properties.PropertyDoesNotApplyToHolderException) PropertyNotPresentException(org.osate.aadl2.properties.PropertyNotPresentException)

Example 85 with ListValue

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

the class ListValueImpl method evaluate.

/*
	 * (non-Javadoc)
	 *
	 * @see org.osate.aadl2.impl.PropertyExpressionImpl#evaluate(org.osate.aadl2.properties.EvaluationContext, int)
	 */
public EvaluatedProperty evaluate(EvaluationContext ctx, int depth) {
    // evaluate each list element
    ListValue newVal = Aadl2Factory.eINSTANCE.createListValue();
    int i = 0;
    for (PropertyExpression elem : getOwnedListElements()) {
        i += 1;
        EvaluatedProperty elemVal = elem.evaluate(ctx, depth + 1);
        if (elemVal.isEmpty()) {
            throw new InvalidModelException(this, "Element " + i + " has no value");
        }
        if (elemVal.size() > 1) {
            throw new InvalidModelException(this, "Element " + i + " has multiple values");
        }
        if (elemVal.first().isModal()) {
            throw new InvalidModelException(this, "Element " + i + ": value is modal");
        }
        PropertyExpression exp = elemVal.first().getValue();
        newVal.getOwnedListElements().add(exp);
    }
    return new EvaluatedProperty(newVal);
}
Also used : InvalidModelException(org.osate.aadl2.properties.InvalidModelException) ListValue(org.osate.aadl2.ListValue) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) PropertyExpression(org.osate.aadl2.PropertyExpression)

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