Search in sources :

Example 21 with BasicPropertyAssociation

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

the class Collocated method toPropertyExpression.

@Override
public RecordValue toPropertyExpression(ResourceSet resourceSet) {
    if (!targets.isPresent() && !location.isPresent()) {
        throw new IllegalStateException("Record must have at least one field set.");
    }
    RecordValue recordValue = Aadl2Factory.eINSTANCE.createRecordValue();
    targets.ifPresent(field -> {
        BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue();
        fieldAssociation.setProperty(loadField(resourceSet, TARGETS__URI, TARGETS__NAME));
        fieldAssociation.setOwnedValue(CodeGenUtil.toPropertyExpression(field, element1 -> {
            return CodeGenUtil.toPropertyExpression(element1);
        }));
    });
    location.ifPresent(field -> {
        BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue();
        fieldAssociation.setProperty(loadField(resourceSet, LOCATION__URI, LOCATION__NAME));
        fieldAssociation.setOwnedValue(CodeGenUtil.toPropertyExpression(field));
    });
    return recordValue;
}
Also used : BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ClassifierValue(org.osate.aadl2.ClassifierValue) ListValue(org.osate.aadl2.ListValue) URI(org.eclipse.emf.common.util.URI) InstanceReferenceValue(org.osate.aadl2.instance.InstanceReferenceValue) Collectors(java.util.stream.Collectors) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Objects(java.util.Objects) Mode(org.osate.aadl2.Mode) PropertyExpression(org.osate.aadl2.PropertyExpression) CodeGenUtil(org.osate.pluginsupport.properties.CodeGenUtil) GeneratedRecord(org.osate.pluginsupport.properties.GeneratedRecord) List(java.util.List) Aadl2Factory(org.osate.aadl2.Aadl2Factory) Classifier(org.osate.aadl2.Classifier) RecordValue(org.osate.aadl2.RecordValue) Optional(java.util.Optional) NamedElement(org.osate.aadl2.NamedElement) InstanceObject(org.osate.aadl2.instance.InstanceObject) PropertyNotPresentException(org.osate.aadl2.properties.PropertyNotPresentException) RecordValue(org.osate.aadl2.RecordValue) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation)

Example 22 with BasicPropertyAssociation

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

the class PriorityMapping method toPropertyExpression.

@Override
public RecordValue toPropertyExpression(ResourceSet resourceSet) {
    if (!aadlPriority.isPresent() && !rtosPriority.isPresent()) {
        throw new IllegalStateException("Record must have at least one field set.");
    }
    RecordValue recordValue = Aadl2Factory.eINSTANCE.createRecordValue();
    aadlPriority.ifPresent(field -> {
        BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue();
        fieldAssociation.setProperty(loadField(resourceSet, AADL_PRIORITY__URI, AADL_PRIORITY__NAME));
        fieldAssociation.setOwnedValue(CodeGenUtil.toPropertyExpression(field));
    });
    rtosPriority.ifPresent(field -> {
        BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue();
        fieldAssociation.setProperty(loadField(resourceSet, RTOS_PRIORITY__URI, RTOS_PRIORITY__NAME));
        fieldAssociation.setOwnedValue(CodeGenUtil.toPropertyExpression(field));
    });
    return recordValue;
}
Also used : RecordValue(org.osate.aadl2.RecordValue) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation)

Example 23 with BasicPropertyAssociation

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

the class AccessTime method toPropertyExpression.

@Override
public RecordValue toPropertyExpression(ResourceSet resourceSet) {
    if (!first.isPresent() && !last.isPresent()) {
        throw new IllegalStateException("Record must have at least one field set.");
    }
    RecordValue recordValue = Aadl2Factory.eINSTANCE.createRecordValue();
    first.ifPresent(field -> {
        BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue();
        fieldAssociation.setProperty(loadField(resourceSet, FIRST__URI, FIRST__NAME));
        fieldAssociation.setOwnedValue(field.toPropertyExpression(resourceSet));
    });
    last.ifPresent(field -> {
        BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue();
        fieldAssociation.setProperty(loadField(resourceSet, LAST__URI, LAST__NAME));
        fieldAssociation.setOwnedValue(field.toPropertyExpression(resourceSet));
    });
    return recordValue;
}
Also used : RecordValue(org.osate.aadl2.RecordValue) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation)

Example 24 with BasicPropertyAssociation

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

the class AssignTime method toPropertyExpression.

@Override
public RecordValue toPropertyExpression(ResourceSet resourceSet) {
    if (!fixed.isPresent() && !perbyte.isPresent()) {
        throw new IllegalStateException("Record must have at least one field set.");
    }
    RecordValue recordValue = Aadl2Factory.eINSTANCE.createRecordValue();
    fixed.ifPresent(field -> {
        BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue();
        fieldAssociation.setProperty(loadField(resourceSet, FIXED__URI, FIXED__NAME));
        fieldAssociation.setOwnedValue(field.toPropertyExpression(resourceSet));
    });
    perbyte.ifPresent(field -> {
        BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue();
        fieldAssociation.setProperty(loadField(resourceSet, PERBYTE__URI, PERBYTE__NAME));
        fieldAssociation.setOwnedValue(field.toPropertyExpression(resourceSet));
    });
    return recordValue;
}
Also used : RecordValue(org.osate.aadl2.RecordValue) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation)

Example 25 with BasicPropertyAssociation

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

the class PropertyUtils method getValue.

/**
 * Returns the first property expression or abstract named element (
 * EnumerationLiteral, Property, PropertyConstant, UnitLiteral) that matches
 * to the given String object within the given ProperyExpression object.
 * If the property expression doesn't exist, it returns {@code null}.
 *
 * @param pe the given ProperyExpression object
 * @param toBeMatched the given String object
 * @return the first matching property expression or abstract named element.
 * otherwise return {@code null}
 *
 * @throws UnsupportedOperationException for other property values than:
 *   _ StringLiteral
 *   _ ListValue (recursion supported)
 *   _ ClassifierValue
 *   _ InstanceReferenceValue
 *   _ ComputedValue
 *   _ RecordValue (based on field matching)
 *   _ NamedValue (returns abstract named element)
 */
public static Element getValue(PropertyExpression pe, String toBeMatched) {
    Element tmp = null;
    int id = pe.eClass().getClassifierID();
    switch(id) {
        case Aadl2Package.STRING_LITERAL:
            {
                StringLiteral sl = (StringLiteral) pe;
                if (sl.getValue().equalsIgnoreCase(toBeMatched)) {
                    return sl;
                }
                return null;
            }
        case Aadl2Package.LIST_VALUE:
            {
                ListValue lv = (ListValue) pe;
                EList<PropertyExpression> pel = lv.getOwnedListElements();
                for (PropertyExpression ownedPe : pel) {
                    tmp = getValue(ownedPe, toBeMatched);
                    if (tmp != null) {
                        return tmp;
                    }
                }
                return null;
            }
        case Aadl2Package.RECORD_VALUE:
            {
                RecordValue rv = (RecordValue) pe;
                for (BasicPropertyAssociation bpa : rv.getOwnedFieldValues()) {
                    if (bpa.getProperty().getName().equalsIgnoreCase(toBeMatched)) {
                        return bpa.getValue();
                    }
                }
                return null;
            }
        case Aadl2Package.CLASSIFIER_VALUE:
            {
                ClassifierValue cv = (ClassifierValue) pe;
                if (cv.getClassifier().getName().equalsIgnoreCase(toBeMatched)) {
                    return cv;
                } else {
                    return null;
                }
            }
        case Aadl2Package.REFERENCE_VALUE:
            {
                InstanceReferenceValue irv = (InstanceReferenceValue) pe;
                if (irv.getReferencedInstanceObject().getName().equalsIgnoreCase(toBeMatched)) {
                    return irv;
                } else {
                    return null;
                }
            }
        case Aadl2Package.COMPUTED_VALUE:
            {
                ComputedValue cv = (ComputedValue) pe;
                if (cv.getFunction().equalsIgnoreCase(toBeMatched)) {
                    return cv;
                } else {
                    return null;
                }
            }
        case Aadl2Package.NAMED_VALUE:
            {
                NamedValue nv = (NamedValue) pe;
                AbstractNamedValue anv = nv.getNamedValue();
                if (anv instanceof NamedElement) {
                    NamedElement ne = (NamedElement) anv;
                    String name = ((NamedElement) anv).getName();
                    // Consider as a final node.
                    if (name.equalsIgnoreCase(toBeMatched)) {
                        return ne;
                    } else if (// Or a structure.
                    ne instanceof Property) {
                        Property p = (Property) ne;
                        if (p.getDefaultValue() != null) {
                            tmp = getValue(p.getDefaultValue(), toBeMatched);
                            return tmp;
                        }
                    }
                } else {
                    String msg = anv.getClass().getSimpleName() + " is not supported";
                    System.err.println(msg);
                    throw new UnsupportedOperationException(msg);
                }
                return null;
            }
        default:
            {
                String msg = pe.getClass().getSimpleName() + " is not supported";
                System.err.println(msg);
                throw new UnsupportedOperationException(msg);
            }
    }
}
Also used : ComputedValue(org.osate.aadl2.ComputedValue) ClassifierValue(org.osate.aadl2.ClassifierValue) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) Element(org.osate.aadl2.Element) RefinableElement(org.osate.aadl2.RefinableElement) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) ListValue(org.osate.aadl2.ListValue) RecordValue(org.osate.aadl2.RecordValue) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) NamedValue(org.osate.aadl2.NamedValue) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) BasicEList(org.eclipse.emf.common.util.BasicEList) EList(org.eclipse.emf.common.util.EList) StringLiteral(org.osate.aadl2.StringLiteral) PropertyExpression(org.osate.aadl2.PropertyExpression) InstanceReferenceValue(org.osate.aadl2.instance.InstanceReferenceValue) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property)

Aggregations

BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)42 RecordValue (org.osate.aadl2.RecordValue)30 ListValue (org.osate.aadl2.ListValue)17 PropertyExpression (org.osate.aadl2.PropertyExpression)16 ClassifierValue (org.osate.aadl2.ClassifierValue)11 NamedValue (org.osate.aadl2.NamedValue)11 StringLiteral (org.osate.aadl2.StringLiteral)11 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)10 RangeValue (org.osate.aadl2.RangeValue)10 IntegerLiteral (org.osate.aadl2.IntegerLiteral)9 PropertyAssociation (org.osate.aadl2.PropertyAssociation)9 RealLiteral (org.osate.aadl2.RealLiteral)9 ComputedValue (org.osate.aadl2.ComputedValue)8 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)8 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)8 ArrayRange (org.osate.aadl2.ArrayRange)7 BasicProperty (org.osate.aadl2.BasicProperty)7 BooleanLiteral (org.osate.aadl2.BooleanLiteral)7 NamedElement (org.osate.aadl2.NamedElement)7 ReferenceValue (org.osate.aadl2.ReferenceValue)7