Search in sources :

Example 6 with ListValue

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

the class PropertiesValidator method typeCheckPropertyValues.

/**
 * checks and report mismatch in type of value and type
 *
 * @param pt:
 *            PropertyType or unresolved proxy or null
 * @param pv:
 *            PropertyExpression or null
 * @param prefix:
 *            String prefix to error message used for lists
 * @since 2.0
 */
protected void typeCheckPropertyValues(PropertyType pt, PropertyExpression pv, String prefix, Element holder, String defName, int depth) {
    if (Aadl2Util.isNull(pt) || pv == null || holder == null) {
        return;
    }
    if (depth > 50) {
        error(holder, "Cyclic value discovered for '" + defName + "'");
        return;
    }
    depth++;
    String msg = " to property '" + defName + "' of type '" + pt.eClass().getName() + "'";
    if (!prefix.isEmpty() && !prefix.startsWith(" ")) {
        prefix = prefix + " ";
    }
    if (pv instanceof ListValue) {
        if (pt instanceof ListType) {
            typeMatchListElements(((ListType) pt).getElementType(), ((ListValue) pv).getOwnedListElements(), holder, defName, depth);
        } else {
            error(holder, prefix + "Assigning a list of values" + msg);
        }
    } else if (pv instanceof Operation || pv instanceof BooleanLiteral) {
        if (!(pt instanceof AadlBoolean)) {
            error(holder, prefix + "Assigning a Boolean value" + msg);
        }
    } else if (pv instanceof StringLiteral) {
        if (!(pt instanceof AadlString)) {
            error(prefix + "Assigning String value" + msg, holder, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, Diagnostic.LINKING_DIAGNOSTIC);
        }
    } else if (pv instanceof EnumerationLiteral || (pv instanceof NamedValue && ((NamedValue) pv).getNamedValue() instanceof EnumerationLiteral)) {
        if (!(pt instanceof EnumerationType)) {
            error(holder, prefix + "Assigning Enumeration literal" + msg);
        }
    } else if (pv instanceof UnitLiteral || (pv instanceof NamedValue && ((NamedValue) pv).getNamedValue() instanceof UnitLiteral)) {
        if (!(pt instanceof UnitsType)) {
            error(holder, prefix + "Assigning Unit literal" + msg);
        }
    } else if (pv instanceof IntegerLiteral) {
        if (!(pt instanceof AadlInteger)) {
            error(holder, prefix + "Assigning Integer value" + msg);
        } else if (checkUnits((AadlInteger) pt, (IntegerLiteral) pv, holder)) {
            checkInRange((AadlInteger) pt, (IntegerLiteral) pv);
        }
    } else if (pv instanceof RealLiteral) {
        if (!(pt instanceof AadlReal)) {
            error(holder, prefix + "Assigning Real value" + msg);
        } else if (checkUnits((AadlReal) pt, (RealLiteral) pv, holder)) {
            checkInRange((AadlReal) pt, (RealLiteral) pv);
        }
    } else if (pv instanceof RangeValue) {
        if (!(pt instanceof RangeType)) {
            error(holder, prefix + "Assigning Range value" + msg);
        } else {
            typeCheckPropertyValues(((RangeType) pt).getNumberType(), ((RangeValue) pv).getMinimumValue(), holder, defName, depth);
            typeCheckPropertyValues(((RangeType) pt).getNumberType(), ((RangeValue) pv).getMaximumValue(), holder, defName, depth);
            typeCheckPropertyValues(((RangeType) pt).getNumberType(), ((RangeValue) pv).getDeltaValue(), holder, defName, depth);
        }
    } else if (pv instanceof ClassifierValue) {
        if (!(pt instanceof ClassifierType)) {
            error(holder, prefix + "Assigning incorrect Classifier value" + msg);
            return;
        }
        ClassifierValue cv = (ClassifierValue) pv;
        ClassifierType ct = (ClassifierType) pt;
        if (ct.getClassifierReferences().isEmpty()) {
            return;
        }
        for (MetaclassReference mcri : ct.getClassifierReferences()) {
            if (mcri.getMetaclass() != null && mcri.getMetaclass().isSuperTypeOf(cv.getClassifier().eClass())) {
                return;
            }
        }
        error(holder, prefix + "Assigning classifier value with incorrect Classifier" + msg);
    } else if (pv instanceof RecordValue) {
        if (!(pt instanceof RecordType)) {
            error(holder, prefix + "Assigning Record value" + msg);
        } else {
            typeMatchRecordFields(((RecordValue) pv).getOwnedFieldValues(), holder, defName, depth);
        }
    } else if (pv instanceof ReferenceValue) {
        if (!(pt instanceof ReferenceType)) {
            error(holder, prefix + "Assigning incorrect reference value" + msg);
        } else {
            ReferenceType ptrt = (ReferenceType) pt;
            if (ptrt.getNamedElementReferences().isEmpty()) {
                return;
            }
            ReferenceValue pvrv = (ReferenceValue) pv;
            EList<ContainmentPathElement> cpes = pvrv.getContainmentPathElements();
            if (!cpes.isEmpty()) {
                NamedElement ne = cpes.get(cpes.size() - 1).getNamedElement();
                for (MetaclassReference mcri : ptrt.getNamedElementReferences()) {
                    if (mcri.getMetaclass().isSuperTypeOf(ne.eClass())) {
                        return;
                    }
                }
                error(holder, prefix + "Assigning reference value with incorrect Named Element class" + msg);
            }
        }
    } else if (pv instanceof NamedValue) {
        AbstractNamedValue nv = ((NamedValue) pv).getNamedValue();
        if (nv instanceof PropertyConstant) {
            final PropertyConstant propertyConstant = (PropertyConstant) nv;
            final PropertyType pct = propertyConstant.getPropertyType();
            if (!Aadl2Util.isNull(pct) && !Aadl2Util.arePropertyTypesEqual(pt, pct)) {
                final String expected = getTypeName(pt);
                final String actual = getTypeName(pct);
                if (actual != null) {
                    if (expected != null) {
                        error(holder, "Property value of type " + actual + "; expected type " + expected);
                    } else {
                        error(holder, "Propery value of type " + actual + " does not match expected type");
                    }
                } else {
                    if (expected != null) {
                        error(holder, "Property value is not of expected type " + expected);
                    } else {
                        error(holder, "Propery value is not of expected type");
                    }
                }
            } else {
                // Issue 2222: is this still really necessary?
                typeCheckPropertyValues(pt, propertyConstant.getConstantValue(), holder, defName, depth);
            }
        } else if (nv instanceof Property) {
            PropertyType pvt = ((Property) nv).getPropertyType();
            if (!Aadl2Util.isNull(pvt)) {
                if (pvt.eClass() != pt.eClass() || !Aadl2Util.arePropertyTypesEqual(pt, pvt)) {
                    final String expected = getTypeName(pt);
                    final String actual = getTypeName(pvt);
                    if (actual != null) {
                        if (expected != null) {
                            error(holder, "Property value of type " + actual + "; expected type " + expected);
                        } else {
                            error(holder, "Propery value of type " + actual + " does not match expected type");
                        }
                    } else {
                        if (expected != null) {
                            error(holder, "Property value is not of expected type " + expected);
                        } else {
                            error(holder, "Propery value is not of expected type");
                        }
                    }
                }
            }
        } else {
            error(holder, "Enum/Unit literal validation should have happened before");
        }
    }
}
Also used : ClassifierType(org.osate.aadl2.ClassifierType) ClassifierValue(org.osate.aadl2.ClassifierValue) BooleanLiteral(org.osate.aadl2.BooleanLiteral) ReferenceValue(org.osate.aadl2.ReferenceValue) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) NamedValue(org.osate.aadl2.NamedValue) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) AadlString(org.osate.aadl2.AadlString) Operation(org.osate.aadl2.Operation) PropertyType(org.osate.aadl2.PropertyType) RangeValue(org.osate.aadl2.RangeValue) ReferenceType(org.osate.aadl2.ReferenceType) RealLiteral(org.osate.aadl2.RealLiteral) RangeType(org.osate.aadl2.RangeType) RecordType(org.osate.aadl2.RecordType) ListType(org.osate.aadl2.ListType) UnitLiteral(org.osate.aadl2.UnitLiteral) AadlInteger(org.osate.aadl2.AadlInteger) MetaclassReference(org.osate.aadl2.MetaclassReference) AadlString(org.osate.aadl2.AadlString) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral) ArraySizeProperty(org.osate.aadl2.ArraySizeProperty) Property(org.osate.aadl2.Property) IntegerLiteral(org.osate.aadl2.IntegerLiteral) AadlReal(org.osate.aadl2.AadlReal) ListValue(org.osate.aadl2.ListValue) EnumerationType(org.osate.aadl2.EnumerationType) RecordValue(org.osate.aadl2.RecordValue) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) PropertyConstant(org.osate.aadl2.PropertyConstant) AadlBoolean(org.osate.aadl2.AadlBoolean) StringLiteral(org.osate.aadl2.StringLiteral) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) UnitsType(org.osate.aadl2.UnitsType)

Example 7 with ListValue

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

the class Aadl2LabelProvider method text.

String text(PropertyExpression pe) {
    if (pe instanceof BooleanLiteral) {
        return "boolean " + ((BooleanLiteral) pe).getValue() + "";
    }
    if (pe instanceof RealLiteral) {
        return "real " + ((RealLiteral) pe).getValue() + "";
    }
    if (pe instanceof IntegerLiteral) {
        return text((IntegerLiteral) pe);
    }
    if (pe instanceof StringLiteral) {
        return text((StringLiteral) pe);
    }
    if (pe instanceof NamedValue) {
        return text((NamedValue) pe);
    }
    if (pe instanceof ReferenceValue) {
        ReferenceValue rv = ((ReferenceValue) pe);
        List<ContainmentPathElement> cpe = rv.getContainmentPathElements();
        return "reference " + cpe.get(0).getNamedElement().getName();
    }
    if (pe instanceof RangeValue) {
        return text(((RangeValue) pe));
    }
    if (pe instanceof ListValue) {
        return text(((ListValue) pe));
    }
    if (pe instanceof RecordValue) {
        return text(((RecordValue) pe));
    }
    // OsateDebug.osateDebug("unknown pe=" + pe);
    return null;
}
Also used : RealLiteral(org.osate.aadl2.RealLiteral) StringLiteral(org.osate.aadl2.StringLiteral) BooleanLiteral(org.osate.aadl2.BooleanLiteral) ReferenceValue(org.osate.aadl2.ReferenceValue) ListValue(org.osate.aadl2.ListValue) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) RecordValue(org.osate.aadl2.RecordValue) NamedValue(org.osate.aadl2.NamedValue) IntegerLiteral(org.osate.aadl2.IntegerLiteral) RangeValue(org.osate.aadl2.RangeValue)

Example 8 with ListValue

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

the class Aadl2LabelProvider method text.

String text(ModalPropertyValue ele) {
    EList<Mode> ml = ele.getInModes();
    String label = "";
    if (ml.isEmpty()) {
        label = "Non-Modal Value";
        // OsateDebug.osateDebug("non modal value" + ele.getOwnedValue());
        if ((ele.getOwnedValue() != null) && (!(ele.getOwnedValue() instanceof RangeValue)) && (!(ele.getOwnedValue() instanceof RecordValue)) && (!(ele.getOwnedValue() instanceof ListValue))) {
            label += " " + text(ele.getOwnedValue());
        }
    } else {
        String modes = "";
        for (Mode m : ml) {
            modes = modes + " " + m.getName();
        }
        label = "Modal property value (" + modes + ")";
    }
    return label;
}
Also used : Mode(org.osate.aadl2.Mode) ListValue(org.osate.aadl2.ListValue) RecordValue(org.osate.aadl2.RecordValue) RangeValue(org.osate.aadl2.RangeValue)

Example 9 with ListValue

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

the class SetBindingTool method createPropertyAssociations.

private void createPropertyAssociations(final AadlModificationService aadlModService) {
    final BusinessObjectContext ciBoc = currentWindow.getComponentImplementationBoc();
    final ComponentImplementation ci = (ComponentImplementation) ciBoc.getBusinessObject();
    aadlModService.modify(Modification.create(ci, new SimpleModifier<ComponentClassifier>() {

        @Override
        public void modify(final ComponentClassifier ci) {
            for (final BusinessObjectContext bocToBind : currentWindow.getBocsToBind()) {
                final PropertyAssociation newPa = AgeAadlUtil.getAadl2Factory().createPropertyAssociation();
                // Set property
                newPa.setProperty(currentWindow.getSelectedProperty());
                // Set applies to
                if (ciBoc != bocToBind) {
                    setContainedNamedElementPath(newPa.createAppliesTo(), ciBoc, bocToBind);
                }
                // Create owned values
                final ModalPropertyValue pv = newPa.createOwnedValue();
                final ListValue lv = (ListValue) pv.createOwnedValue(Aadl2Package.eINSTANCE.getListValue());
                for (final BusinessObjectContext targetBoc : currentWindow.getTargetBocs()) {
                    // Ignore diagram selections
                    final ReferenceValue rv = (ReferenceValue) lv.createOwnedListElement(Aadl2Package.eINSTANCE.getReferenceValue());
                    setContainedNamedElementPath(rv, ciBoc, targetBoc);
                }
                removeOldPropertyAssociation(ci, newPa);
                // Add the property association
                ci.setNoProperties(false);
                ci.getOwnedPropertyAssociations().add(newPa);
            }
        }

        // Deletes any existing property associations/removes the bound element from any property associations that matches the property association
        // being created.
        private void removeOldPropertyAssociation(final ComponentClassifier cc, final PropertyAssociation newPa) {
            final List<PropertyAssociation> propertyAssociationsToDelete = new ArrayList<PropertyAssociation>();
            for (final PropertyAssociation existingPa : cc.getOwnedPropertyAssociations()) {
                // If Property matches
                if (newPa.getProperty().getFullName().equals(existingPa.getProperty().getFullName())) {
                    if (existingPa.getAppliesTos().size() == 0 || newPa.getAppliesTos().size() == 0) {
                        if (existingPa.getAppliesTos().size() == 0 && newPa.getAppliesTos().size() == 0) {
                            propertyAssociationsToDelete.add(existingPa);
                        }
                    } else {
                        final List<ContainedNamedElement> containedElementsToDelete = new ArrayList<ContainedNamedElement>();
                        for (final ContainedNamedElement existingContainedElement : existingPa.getAppliesTos()) {
                            if (containmentPathsMatch(existingContainedElement.getPath(), newPa.getAppliesTos().get(0).getPath())) {
                                // Add the contained element to the list of objects to delete
                                containedElementsToDelete.add(existingContainedElement);
                            }
                        }
                        // Delete objects
                        for (final EObject ce : containedElementsToDelete) {
                            EcoreUtil.delete(ce);
                        }
                        // Delete the property association if it was the last element in the applies to clause
                        if (existingPa.getAppliesTos().size() == 0) {
                            propertyAssociationsToDelete.add(existingPa);
                        }
                    }
                }
            }
            // Delete property association(s) that are being replaced
            for (final PropertyAssociation pa : propertyAssociationsToDelete) {
                EcoreUtil.delete(pa);
            }
        }
    }));
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentClassifier(org.osate.aadl2.ComponentClassifier) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) ReferenceValue(org.osate.aadl2.ReferenceValue) ListValue(org.osate.aadl2.ListValue) ArrayList(java.util.ArrayList) SimpleModifier(org.osate.ge.internal.services.AadlModificationService.SimpleModifier) EObject(org.eclipse.emf.ecore.EObject) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 10 with ListValue

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

the class EMV2Properties method getFailure.

/**
 * @param element - the EMV2 element that referes to the artifact
 * @param relatedComponent - the component the component (instance, subcomponent or classifier) that have the property association
 * @return - the text related to the failure part of the hazards property. Null if not defined
 */
public static String getFailure(NamedElement element, NamedElement relatedComponent) {
    TypeSet ts = null;
    if (element instanceof ErrorBehaviorState) {
        ts = ((ErrorBehaviorState) element).getTypeSet();
    }
    if (element instanceof ErrorPropagation) {
        ts = ((ErrorPropagation) element).getTypeSet();
    }
    if (element instanceof ErrorEvent) {
        ts = ((ErrorEvent) element).getTypeSet();
    }
    List<EMV2PropertyAssociation> PA = EMV2Properties.getHazardsProperty(relatedComponent, element, ts);
    if (PA.isEmpty()) {
        return null;
    }
    // XXX TODO we may get more than one back, one each for different types
    PropertyExpression val = getPropertyValue(PA.get(0));
    if (val instanceof RecordValue) {
        RecordValue rv = (RecordValue) val;
        EList<BasicPropertyAssociation> fields = rv.getOwnedFieldValues();
        BasicPropertyAssociation xref = GetProperties.getRecordField(fields, "failure");
        if (xref != null) {
            PropertyExpression peVal = getPropertyValue(xref);
            if (peVal instanceof StringLiteral) {
                return ((StringLiteral) peVal).getValue();
            }
        }
    }
    if (val instanceof ListValue) {
        ListValue lv = (ListValue) val;
        for (PropertyExpression pe : lv.getOwnedListElements()) {
            if (pe instanceof RecordValue) {
                RecordValue rv = (RecordValue) pe;
                EList<BasicPropertyAssociation> fields = rv.getOwnedFieldValues();
                BasicPropertyAssociation xref = GetProperties.getRecordField(fields, "failure");
                if (xref != null) {
                    PropertyExpression peVal = getPropertyValue(xref);
                    if (peVal instanceof StringLiteral) {
                        return ((StringLiteral) peVal).getValue();
                    }
                }
            }
        }
    }
    return null;
}
Also used : ErrorBehaviorState(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState) StringLiteral(org.osate.aadl2.StringLiteral) TypeSet(org.osate.xtext.aadl2.errormodel.errorModel.TypeSet) ListValue(org.osate.aadl2.ListValue) ErrorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorEvent) EMV2PropertyAssociation(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PropertyAssociation) RecordValue(org.osate.aadl2.RecordValue) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation) PropertyExpression(org.osate.aadl2.PropertyExpression) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation)

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