Search in sources :

Example 1 with EnumerationLiteralImpl

use of org.osate.aadl2.impl.EnumerationLiteralImpl 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 EnumerationLiteralImpl

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

the class Aadl2Vdm method getStrRepofExpr.

/**
 * @author Paul Meng
 * The calling function should know the size of the return array
 */
String[] getStrRepofExpr(PropertyExpression expr) {
    String[] values = new String[4];
    if (expr instanceof BooleanLiteralImpl) {
        BooleanLiteralImpl bool = ((BooleanLiteralImpl) expr);
        // values[0] = bool.getValue()?"1":"0";
        values[0] = bool.getValue() ? "true" : "false";
    } else if (expr instanceof IntegerLiteralImpl) {
        IntegerLiteralImpl intVal = ((IntegerLiteralImpl) expr);
        values[0] = String.valueOf((int) intVal.getValue());
    } else if (expr instanceof NamedValueImpl) {
        NamedValueImpl namedValue = ((NamedValueImpl) expr);
        if (namedValue.getNamedValue() instanceof EnumerationLiteralImpl) {
            EnumerationLiteralImpl enu = ((EnumerationLiteralImpl) namedValue.getNamedValue());
            values[0] = enu.getName();
        } else {
            throw new RuntimeException("Unsupported property value: " + namedValue.getNamedValue());
        }
    } else if (expr instanceof ListValueImpl) {
        ListValueImpl listValue = (ListValueImpl) expr;
        if (listValue.getOwnedListElements().size() == 1) {
            values = getStrRepofExpr(listValue.getOwnedListElements().get(0));
        } else {
            throw new RuntimeException("Unexpected!");
        }
    } else if (expr instanceof ReferenceValueImpl) {
        // We only consider the value of expr is a bus expression here.
        ReferenceValueImpl refValue = (ReferenceValueImpl) expr;
        if (refValue.getContainmentPathElements().size() == 1) {
            ContainmentPathElement element = refValue.getContainmentPathElements().get(0);
            NamedElement namedElement = element.getNamedElement();
            if (namedElement instanceof BusSubcomponent) {
                ComponentImplementation impl = ((BusSubcomponent) namedElement).getContainingComponentImpl();
                String compTypeName = impl.getTypeName();
                values[0] = compTypeName;
                values[1] = impl.getName();
                values[2] = "";
                values[3] = namedElement.getName();
            } else {
                throw new RuntimeException("Unexpected!");
            }
        } else if (refValue.getContainmentPathElements().size() == 2) {
            // This is to deal with the expression "subcomponent . bus"
            ContainmentPathElement elementZero = refValue.getContainmentPathElements().get(0);
            ContainmentPathElement elementOne = refValue.getContainmentPathElements().get(1);
            NamedElement namedElementZero = elementZero.getNamedElement();
            NamedElement namedElementOne = elementOne.getNamedElement();
            if (namedElementZero instanceof SystemSubcomponent) {
                ComponentImplementation impl = ((SystemSubcomponent) namedElementZero).getComponentImplementation();
                values[0] = impl.getTypeName();
                values[1] = impl.getName();
                values[2] = namedElementZero.getName();
                values[3] = namedElementOne.getName();
            } else {
                throw new RuntimeException("Unexpected!");
            }
        } else {
            throw new RuntimeException("Unexpected number of property values: " + refValue.getContainmentPathElements().size());
        }
    } else if (expr instanceof StringLiteralImpl) {
        StringLiteralImpl strVal = ((StringLiteralImpl) expr);
        values[0] = strVal.getValue();
    } else {
        throw new RuntimeException("Unsupported property value: " + expr);
    }
    return values;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) StringLiteralImpl(org.osate.aadl2.impl.StringLiteralImpl) NamedValueImpl(org.osate.aadl2.impl.NamedValueImpl) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) BusSubcomponent(org.osate.aadl2.BusSubcomponent) BooleanLiteralImpl(org.osate.aadl2.impl.BooleanLiteralImpl) ReferenceValueImpl(org.osate.aadl2.impl.ReferenceValueImpl) EnumerationLiteralImpl(org.osate.aadl2.impl.EnumerationLiteralImpl) SystemSubcomponent(org.osate.aadl2.SystemSubcomponent) IntegerLiteralImpl(org.osate.aadl2.impl.IntegerLiteralImpl) ListValueImpl(org.osate.aadl2.impl.ListValueImpl) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement)

Example 3 with EnumerationLiteralImpl

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

the class Aadl2CsvTranslator method getStrRepofExpr.

/**
 * The calling function should know the size of the return array
 */
String[] getStrRepofExpr(PropertyExpression expr) {
    String[] values = new String[4];
    if (expr instanceof BooleanLiteralImpl) {
        BooleanLiteralImpl bool = ((BooleanLiteralImpl) expr);
        values[0] = bool.getValue() ? "1" : "0";
    } else if (expr instanceof IntegerLiteralImpl) {
        IntegerLiteralImpl intVal = ((IntegerLiteralImpl) expr);
        values[0] = String.valueOf((int) intVal.getValue());
    } else if (expr instanceof NamedValueImpl) {
        NamedValueImpl namedValue = ((NamedValueImpl) expr);
        if (namedValue.getNamedValue() instanceof EnumerationLiteralImpl) {
            EnumerationLiteralImpl enu = ((EnumerationLiteralImpl) namedValue.getNamedValue());
            values[0] = enu.getName();
        } else {
            throw new RuntimeException("Unsupported property value: " + namedValue.getNamedValue());
        }
    } else if (expr instanceof ListValueImpl) {
        ListValueImpl listValue = (ListValueImpl) expr;
        if (listValue.getOwnedListElements().size() == 1) {
            values = getStrRepofExpr(listValue.getOwnedListElements().get(0));
        } else {
            throw new RuntimeException("Unexpected!");
        }
    } else if (expr instanceof ReferenceValueImpl) {
        // We only consider the value of expr is a bus expression here.
        ReferenceValueImpl refValue = (ReferenceValueImpl) expr;
        if (refValue.getContainmentPathElements().size() == 1) {
            ContainmentPathElement element = refValue.getContainmentPathElements().get(0);
            NamedElement namedElement = element.getNamedElement();
            if (namedElement instanceof BusSubcomponent) {
                ComponentImplementation impl = ((BusSubcomponent) namedElement).getContainingComponentImpl();
                String compTypeName = impl.getTypeName();
                values[0] = compTypeName;
                values[1] = impl.getName();
                values[2] = "";
                values[3] = namedElement.getName();
            } else {
                throw new RuntimeException("Unexpected!");
            }
        } else if (refValue.getContainmentPathElements().size() == 2) {
            // This is to deal with the expression "subcomponent . bus"
            ContainmentPathElement elementZero = refValue.getContainmentPathElements().get(0);
            ContainmentPathElement elementOne = refValue.getContainmentPathElements().get(1);
            NamedElement namedElementZero = elementZero.getNamedElement();
            NamedElement namedElementOne = elementOne.getNamedElement();
            if (namedElementZero instanceof SystemSubcomponent) {
                ComponentImplementation impl = ((SystemSubcomponent) namedElementZero).getComponentImplementation();
                values[0] = impl.getTypeName();
                values[1] = impl.getName();
                values[2] = namedElementZero.getName();
                values[3] = namedElementOne.getName();
            } else {
                throw new RuntimeException("Unexpected!");
            }
        } else {
            throw new RuntimeException("Unexpected number of property values: " + refValue.getContainmentPathElements().size());
        }
    } else if (expr instanceof StringLiteralImpl) {
        StringLiteralImpl strVal = ((StringLiteralImpl) expr);
        values[0] = strVal.getValue();
    } else {
        throw new RuntimeException("Unsupported property value: " + expr);
    }
    return values;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) StringLiteralImpl(org.osate.aadl2.impl.StringLiteralImpl) NamedValueImpl(org.osate.aadl2.impl.NamedValueImpl) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) BusSubcomponent(org.osate.aadl2.BusSubcomponent) BooleanLiteralImpl(org.osate.aadl2.impl.BooleanLiteralImpl) ReferenceValueImpl(org.osate.aadl2.impl.ReferenceValueImpl) EnumerationLiteralImpl(org.osate.aadl2.impl.EnumerationLiteralImpl) SystemSubcomponent(org.osate.aadl2.SystemSubcomponent) IntegerLiteralImpl(org.osate.aadl2.impl.IntegerLiteralImpl) ListValueImpl(org.osate.aadl2.impl.ListValueImpl) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement)

Aggregations

EnumerationLiteralImpl (org.osate.aadl2.impl.EnumerationLiteralImpl)3 ListValueImpl (org.osate.aadl2.impl.ListValueImpl)3 NamedValueImpl (org.osate.aadl2.impl.NamedValueImpl)3 StringLiteralImpl (org.osate.aadl2.impl.StringLiteralImpl)3 BusSubcomponent (org.osate.aadl2.BusSubcomponent)2 ComponentImplementation (org.osate.aadl2.ComponentImplementation)2 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)2 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)2 NamedElement (org.osate.aadl2.NamedElement)2 SystemSubcomponent (org.osate.aadl2.SystemSubcomponent)2 BooleanLiteralImpl (org.osate.aadl2.impl.BooleanLiteralImpl)2 IntegerLiteralImpl (org.osate.aadl2.impl.IntegerLiteralImpl)2 ReferenceValueImpl (org.osate.aadl2.impl.ReferenceValueImpl)2 EnumerationLiteral (org.osate.aadl2.EnumerationLiteral)1 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)1 NamedValue (org.osate.aadl2.NamedValue)1 PropertyAssociation (org.osate.aadl2.PropertyAssociation)1 PropertyExpression (org.osate.aadl2.PropertyExpression)1 EnumType (verdict.vdm.vdm_data.EnumType)1