Search in sources :

Example 1 with ModalPropertyValue

use of org.osate.aadl2.ModalPropertyValue in project VERDICT by ge-high-assurance.

the class Agree2Vdm method updateVDMDatatypeUsingProperties.

/**
 *  @param vdm dataType,
 * 	@param list of property associations
 *  this method checks if the property indicates if it is an enum definition
 *  and gets information from the properties to define the enum in the VDM
 *  *
 */
public boolean updateVDMDatatypeUsingProperties(verdict.vdm.vdm_data.DataType dtype, EList<PropertyAssociation> properties) {
    if (properties.size() == 2) {
        // check if the property specifies it is enum type
        PropertyAssociation firstProperty = properties.get(0);
        EList<ModalPropertyValue> firstPropertyValues = firstProperty.getOwnedValues();
        if (firstPropertyValues.size() == 1) {
            PropertyExpression ownedval = firstPropertyValues.get(0).getOwnedValue();
            if (ownedval instanceof NamedValueImpl) {
                NamedValue namedVal = (NamedValue) ownedval;
                if (namedVal.getNamedValue() instanceof EnumerationLiteralImpl) {
                    EnumerationLiteral namedValEnumLit = (EnumerationLiteral) namedVal.getNamedValue();
                    if (namedValEnumLit.getName().equalsIgnoreCase("Enum")) {
                        EnumType vdmEnumType = new EnumType();
                        // Fetch the enum values which are defined as the next property
                        PropertyAssociation secondProperty = properties.get(1);
                        EList<ModalPropertyValue> secondPropertyValues = secondProperty.getOwnedValues();
                        if (firstPropertyValues.size() == 1) {
                            PropertyExpression secPropValue = secondPropertyValues.get(0).getOwnedValue();
                            // enum should have multiple values so check if a list of values are defined
                            if (secPropValue instanceof ListValueImpl) {
                                ListValueImpl listValueImpl = (ListValueImpl) secPropValue;
                                EList<PropertyExpression> listOfValues = listValueImpl.getOwnedListElements();
                                for (PropertyExpression enumvalue : listOfValues) {
                                    if (enumvalue instanceof StringLiteralImpl) {
                                        StringLiteralImpl stringEnumVal = (StringLiteralImpl) enumvalue;
                                        vdmEnumType.getEnumValue().add(stringEnumVal.getValue());
                                    } else {
                                        System.out.println("Unexpected non-string value for data type of type enum.");
                                    }
                                }
                                dtype.setEnumType(vdmEnumType);
                                return true;
                            } else {
                                System.out.println("The second property of the data definition is not of ListValueImp type");
                            }
                        } else {
                            System.out.println("Unresolved data property. The first property of the data definition has no values or multiple values.");
                        }
                    } else {
                        System.out.println("Unresolved data property value. Property's owned value's named value does not contain Enum");
                    }
                } else {
                    System.out.println("Unresolved data property value. Property's owned value's named value is not EnumerationLiteralImpl type.");
                }
            } else {
                System.out.println("Unresolved data property value. Property's owned value is not NamedValueImpl type.");
            }
        } else {
            System.out.println("Unresolved data property with no values or multiple values.");
        }
    } else {
        System.out.println("Unresolved data property. Data definition has 0 or more than 2 properties associated with it");
    }
    return false;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) StringLiteralImpl(org.osate.aadl2.impl.StringLiteralImpl) PropertyAssociation(org.osate.aadl2.PropertyAssociation) EnumType(verdict.vdm.vdm_data.EnumType) NamedValueImpl(org.osate.aadl2.impl.NamedValueImpl) PropertyExpression(org.osate.aadl2.PropertyExpression) NamedValue(org.osate.aadl2.NamedValue) ListValueImpl(org.osate.aadl2.impl.ListValueImpl) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral) EnumerationLiteralImpl(org.osate.aadl2.impl.EnumerationLiteralImpl)

Example 2 with ModalPropertyValue

use of org.osate.aadl2.ModalPropertyValue in project osate2 by osate.

the class AadlBaNameResolver method propertyFieldIndexResolver.

private boolean propertyFieldIndexResolver(Element el, IntegerValue field, BasicProperty bProperty, int fieldIndex, DeclarativePropertyName declProName) {
    if (integerValueResolver(field)) {
        // Link to the default value, if it exists.
        if (Aadl2Package.LIST_VALUE == el.eClass().getClassifierID() && propertyFieldListValueResolver(field, (ListValue) el, fieldIndex, declProName)) {
            return true;
        } else if (Aadl2Package.PROPERTY_ASSOCIATION == el.eClass().getClassifierID()) {
            PropertyAssociation pa = (PropertyAssociation) el;
            ModalPropertyValue mpv = pa.getOwnedValues().get(pa.getOwnedValues().size() - 1);
            PropertyExpression pe = mpv.getOwnedValue();
            if (Aadl2Package.LIST_VALUE == pe.eClass().getClassifierID()) {
                return propertyFieldListValueResolver(field, (ListValue) pe, fieldIndex, declProName);
            }
        }
        // the else statements: link with the property type.
        ListType lt = (ListType) bProperty.getPropertyType();
        declProName.setOsateRef(lt.getElementType());
        return true;
    } else {
        return false;
    }
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) DeclarativeBasicPropertyAssociation(org.osate.ba.declarative.DeclarativeBasicPropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ListValue(org.osate.aadl2.ListValue) DeclarativeListValue(org.osate.ba.declarative.DeclarativeListValue) ListType(org.osate.aadl2.ListType) PropertyExpression(org.osate.aadl2.PropertyExpression)

Example 3 with ModalPropertyValue

use of org.osate.aadl2.ModalPropertyValue in project osate2 by osate.

the class AadlBaNameResolver method behaviorVariableResolver.

/**
 * Resolves the behavior annex's variables.
 *
 * @return {@code true} if all names are resolved. {@code false} otherwise.
 */
private boolean behaviorVariableResolver() {
    boolean result = true;
    QualifiedNamedElement uccr;
    // classifier reference exists.
    for (BehaviorVariable v : _ba.getVariables()) {
        uccr = (QualifiedNamedElement) v.getDataClassifier();
        result &= qualifiedNamedElementResolver(uccr, true);
        for (ArrayDimension tmp : v.getArrayDimensions()) {
            IntegerValueConstant ivc = ((DeclarativeArrayDimension) tmp).getDimension();
            result &= integerValueConstantResolver(ivc);
        }
        List<PropertyAssociation> paList = v.getOwnedPropertyAssociations();
        List<PropertyAssociation> paPropertyNotFound = new ArrayList<PropertyAssociation>();
        Set<PropertyAssociation> paPropertyValueError = new HashSet<PropertyAssociation>();
        for (PropertyAssociation pa : paList) {
            QualifiedNamedElement p = (QualifiedNamedElement) pa.getProperty();
            boolean valid = qualifiedNamedElementResolver(p, false);
            if (valid) {
                for (ModalPropertyValue mpv : pa.getOwnedValues()) {
                    result &= propertyExpressionResolver(v, p, mpv.getOwnedValue());
                    paPropertyValueError.add(pa);
                }
            }
            if (!valid) {
                paPropertyNotFound.add(pa);
            }
            result &= valid;
        }
        StringBuilder msg = new StringBuilder();
        if (paPropertyNotFound.size() > 1) {
            msg.append("Properties ");
        } else {
            msg.append("Property ");
        }
        boolean first = true;
        for (PropertyAssociation paToRemove : paPropertyNotFound) {
            QualifiedNamedElement p = (QualifiedNamedElement) paToRemove.getProperty();
            StringBuilder qualifiedName = new StringBuilder();
            if (p.getBaNamespace() != null) {
                qualifiedName.append(p.getBaNamespace().getId());
                qualifiedName.append("::");
            }
            qualifiedName.append(p.getBaName().getId());
            if (first) {
                msg.append("\'" + qualifiedName + "\' ");
            } else {
                msg.append(" and \'" + qualifiedName + "\' ");
            }
            first = false;
        }
        paList.removeAll(paPropertyNotFound);
        paList.removeAll(paPropertyValueError);
        if (paPropertyNotFound.size() > 0) {
            msg.append("not found");
            _errManager.error(v, msg.toString());
        }
    }
    return result;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) BehaviorVariable(org.osate.ba.aadlba.BehaviorVariable) PropertyAssociation(org.osate.aadl2.PropertyAssociation) DeclarativeBasicPropertyAssociation(org.osate.ba.declarative.DeclarativeBasicPropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ArrayList(java.util.ArrayList) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) DeclarativeArrayDimension(org.osate.ba.declarative.DeclarativeArrayDimension) IntegerValueConstant(org.osate.ba.aadlba.IntegerValueConstant) ArrayDimension(org.osate.aadl2.ArrayDimension) DeclarativeArrayDimension(org.osate.ba.declarative.DeclarativeArrayDimension) HashSet(java.util.HashSet)

Example 4 with ModalPropertyValue

use of org.osate.aadl2.ModalPropertyValue in project osate2 by osate.

the class PropertyUtils method createIntegerAssignment.

public static PropertyAssociation createIntegerAssignment(String propertyName, long value) {
    Property property = Aadl2Factory.eINSTANCE.createProperty();
    PropertyAssociation assignment = Aadl2Factory.eINSTANCE.createPropertyAssociation();
    ModalPropertyValue modalPropertyValue = Aadl2Factory.eINSTANCE.createModalPropertyValue();
    IntegerLiteral propertyValue = Aadl2Factory.eINSTANCE.createIntegerLiteral();
    property.setName(propertyName);
    propertyValue.setValue(value);
    modalPropertyValue.setOwnedValue(propertyValue);
    assignment.setProperty(property);
    assignment.getOwnedValues().add(modalPropertyValue);
    return assignment;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property) IntegerLiteral(org.osate.aadl2.IntegerLiteral)

Example 5 with ModalPropertyValue

use of org.osate.aadl2.ModalPropertyValue in project osate2 by osate.

the class PropertyUtils method getListValue.

public static ListValue getListValue(NamedElement ne, String propertyName) {
    PropertyAssociation pa = findPropertyAssociation(propertyName, ne);
    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) {
                    return (ListValue) expr;
                }
            }
        }
    }
    return null;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ListValue(org.osate.aadl2.ListValue) PropertyExpression(org.osate.aadl2.PropertyExpression) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property)

Aggregations

ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)56 PropertyAssociation (org.osate.aadl2.PropertyAssociation)44 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)29 PropertyExpression (org.osate.aadl2.PropertyExpression)29 Property (org.osate.aadl2.Property)28 BasicProperty (org.osate.aadl2.BasicProperty)21 ListValue (org.osate.aadl2.ListValue)20 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)11 IntegerLiteral (org.osate.aadl2.IntegerLiteral)11 NamedValue (org.osate.aadl2.NamedValue)11 ReferenceValue (org.osate.aadl2.ReferenceValue)11 ArrayList (java.util.ArrayList)10 Mode (org.osate.aadl2.Mode)10 RangeValue (org.osate.aadl2.RangeValue)10 StringLiteral (org.osate.aadl2.StringLiteral)10 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)9 RecordValue (org.osate.aadl2.RecordValue)9 BooleanLiteral (org.osate.aadl2.BooleanLiteral)8 ClassifierValue (org.osate.aadl2.ClassifierValue)7 RealLiteral (org.osate.aadl2.RealLiteral)7