Search in sources :

Example 26 with PropertyConstant

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

the class AadlBaUtils method getFeatureType.

/**
 * Analyze the given AADL Osate element and return its enumeration type.
 *
 * It's an improved version of Osate2 org.osate.parser.AadlSemanticCheckSwitch#getFeatureType
 *
 * @param el the given AADL Osate element
 * @return the given AADL Osate element's type
 * @exception UnsupportedOperationException for the unsupported types
 */
/*
	 * <copyright>
	 * Copyright 2009 by Carnegie Mellon University, all rights reserved.
	 *
	 * Use of the Open Source AADL Tool Environment (OSATE) is subject to the terms of the license set forth
	 * at http://www.eclipse.org/legal/cpl-v10.html.
	 *
	 * NO WARRANTY
	 *
	 * ANY INFORMATION, MATERIALS, SERVICES, INTELLECTUAL PROPERTY OR OTHER PROPERTY OR RIGHTS GRANTED OR PROVIDED BY
	 * CARNEGIE MELLON UNIVERSITY PURSUANT TO THIS LICENSE (HEREINAFTER THE "DELIVERABLES") ARE ON AN "AS-IS" BASIS.
	 * CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED AS TO ANY MATTER INCLUDING,
	 * BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, INFORMATIONAL CONTENT,
	 * NONINFRINGEMENT, OR ERROR-FREE OPERATION. CARNEGIE MELLON UNIVERSITY SHALL NOT BE LIABLE FOR INDIRECT, SPECIAL OR
	 * CONSEQUENTIAL DAMAGES, SUCH AS LOSS OF PROFITS OR INABILITY TO USE SAID INTELLECTUAL PROPERTY, UNDER THIS LICENSE,
	 * REGARDLESS OF WHETHER SUCH PARTY WAS AWARE OF THE POSSIBILITY OF SUCH DAMAGES. LICENSEE AGREES THAT IT WILL NOT
	 * MAKE ANY WARRANTY ON BEHALF OF CARNEGIE MELLON UNIVERSITY, EXPRESS OR IMPLIED, TO ANY PERSON CONCERNING THE
	 * APPLICATION OF OR THE RESULTS TO BE OBTAINED WITH THE DELIVERABLES UNDER THIS LICENSE.
	 *
	 * Licensee hereby agrees to defend, indemnify, and hold harmless Carnegie Mellon University, its trustees, officers,
	 * employees, and agents from all claims or demands made against them (and any related losses, expenses, or
	 * attorney's fees) arising out of, or relating to Licensee's and/or its sub licensees' negligent use or willful
	 * misuse of or negligent conduct or willful misconduct regarding the Software, facilities, or other rights or
	 * assistance granted by Carnegie Mellon University under this License, including, but not limited to, any claims of
	 * product liability, personal injury, death, damage to property, or violation of any laws or regulations.
	 *
	 * Carnegie Mellon University Software Engineering Institute authored documents are sponsored by the U.S. Department
	 * of Defense under Contract F19628-00-C-0003. Carnegie Mellon University retains copyrights in all material produced
	 * under this contract. The U.S. Government retains a non-exclusive, royalty-free license to publish or reproduce these
	 * documents, or allow others to do so, for U.S. Government purposes only pursuant to the copyright license
	 * under the contract clause at 252.227.7013.
	 * </copyright>
	 */
public static org.osate.ba.aadlba.FeatureType getFeatureType(Element el) {
    if (el instanceof DataPort) {
        switch(((DataPort) el).getDirection()) {
            case IN:
                return FeatureType.IN_DATA_PORT;
            case OUT:
                return FeatureType.OUT_DATA_PORT;
            case IN_OUT:
                return FeatureType.IN_OUT_DATA_PORT;
        }
    } else if (el instanceof EventPort) {
        switch(((EventPort) el).getDirection()) {
            case IN:
                return FeatureType.IN_EVENT_PORT;
            case OUT:
                return FeatureType.OUT_EVENT_PORT;
            case IN_OUT:
                return FeatureType.IN_OUT_EVENT_PORT;
        }
    } else if (el instanceof EventDataPort) {
        switch(((EventDataPort) el).getDirection()) {
            case IN:
                return FeatureType.IN_EVENT_DATA_PORT;
            case OUT:
                return FeatureType.OUT_EVENT_DATA_PORT;
            case IN_OUT:
                return FeatureType.IN_OUT_EVENT_DATA_PORT;
        }
    } else if (el instanceof FeatureGroup) {
        return FeatureType.FEATURE_GROUP;
    } else if (el instanceof DataAccess) {
        switch(((DataAccess) el).getKind()) {
            case PROVIDES:
                return FeatureType.PROVIDES_DATA_ACCESS;
            case REQUIRES:
                return FeatureType.REQUIRES_DATA_ACCESS;
        }
    } else if (el instanceof SubprogramAccess) {
        switch(((SubprogramAccess) el).getKind()) {
            case PROVIDES:
                return FeatureType.PROVIDES_SUBPROGRAM_ACCESS;
            case REQUIRES:
                return FeatureType.REQUIRES_SUBPROGRAM_ACCESS;
        }
    } else if (el instanceof SubprogramGroupAccess) {
        switch(((SubprogramGroupAccess) el).getKind()) {
            case PROVIDES:
                return FeatureType.PROVIDES_SUBPROGRAM_GROUP_ACCESS;
            case REQUIRES:
                return FeatureType.REQUIRES_SUBPROGRAM_GROUP_ACCESS;
        }
    } else if (el instanceof BusAccess) {
        switch(((BusAccess) el).getKind()) {
            case PROVIDES:
                return FeatureType.PROVIDES_BUS_ACCESS;
            case REQUIRES:
                return FeatureType.REQUIRES_BUS_ACCESS;
        }
    } else if (el instanceof AbstractFeature) {
        return FeatureType.ABSTRACT_FEATURE;
    } else if (el instanceof Parameter) {
        switch(((Parameter) el).getDirection()) {
            case IN:
                return FeatureType.IN_PARAMETER;
            case OUT:
                return FeatureType.OUT_PARAMETER;
            case IN_OUT:
                return FeatureType.IN_OUT_PARAMETER;
        }
    } else if (el instanceof Prototype) {
        if (el instanceof ComponentPrototype) {
            switch(el.eClass().getClassifierID()) {
                case Aadl2Package.SUBPROGRAM_PROTOTYPE:
                    return FeatureType.SUBPROGRAM_PROTOTYPE;
                case Aadl2Package.SUBPROGRAM_GROUP_PROTOTYPE:
                    return FeatureType.SUBPROGRAM_GROUP_PROTOTYPE;
                case Aadl2Package.THREAD_PROTOTYPE:
                    return FeatureType.THREAD_PROTOTYPE;
                case Aadl2Package.THREAD_GROUP_PROTOTYPE:
                    return FeatureType.THREAD_GROUP_PROTOTYPE;
                default:
                    return FeatureType.COMPONENT_PROTOTYPE;
            }
        } else if (el instanceof FeaturePrototype) {
            return getFeaturePrototypeType((FeaturePrototype) el);
        } else if (el instanceof FeatureGroupPrototype) {
            return FeatureType.FEATURE_GROUP_PROTOTYPE;
        }
    } else if (el instanceof PrototypeBinding) {
        if (el instanceof ComponentPrototypeBinding) {
            return FeatureType.COMPONENT_PROTOTYPE_BINDING;
        } else if (el instanceof FeatureGroupPrototypeBinding) {
            return FeatureType.FEATURE_GROUP_PROTOTYPE_BINDING;
        } else // FeaturePrototypeBinding case.
        {
            return FeatureType.FEATURE_PROTOTYPE_BINDING;
        }
    } else if (el instanceof org.osate.aadl2.PropertyConstant) {
        return FeatureType.PROPERTY_CONSTANT;
    } else if (el instanceof org.osate.aadl2.Property) {
        return FeatureType.PROPERTY_VALUE;
    } else if (el instanceof ClassifierValue) {
        return FeatureType.CLASSIFIER_VALUE;
    } else if (el instanceof SubprogramGroup) {
        return FeatureType.SUBPROGRAM_GROUP;
    } else if (el instanceof SubprogramGroupAccess) {
        switch(((SubprogramGroupAccess) el).getKind()) {
            case PROVIDES:
                return FeatureType.PROVIDES_SUBPROGRAM_GROUP_ACCESS;
            case REQUIRES:
                return FeatureType.REQUIRES_SUBPROGRAM_GROUP_ACCESS;
        }
    } else if (el instanceof ThreadGroup) {
        return FeatureType.THREAD_GROUP;
    } else if (el instanceof SystemSubcomponent) {
        return FeatureType.SYSTEM_SUBCOMPONENT;
    } else if (el instanceof SubprogramSubcomponent) {
        return FeatureType.SUBPROGRAM_SUBCOMPONENT;
    } else if (el instanceof SubprogramClassifier) {
        return FeatureType.SUBPROGRAM_CLASSIFIER;
    } else if (el instanceof DataSubcomponent) {
        return FeatureType.DATA_SUBCOMPONENT;
    } else if (el instanceof DataClassifier) {
        return FeatureType.DATA_CLASSIFIER;
    } else if (el instanceof ProcessorClassifier) {
        return FeatureType.PROCESSOR_CLASSIFIER;
    } else if (el instanceof ProcessClassifier) {
        return FeatureType.PROCESS_CLASSIFIER;
    }
    String errorMsg = "getFeatureType : " + el.getClass().getSimpleName() + " is not supported yet at line " + Aadl2Utils.getLocationReference(el).getLine() + ".";
    System.err.println(errorMsg);
    throw new UnsupportedOperationException(errorMsg);
}
Also used : SubprogramGroup(org.osate.aadl2.SubprogramGroup) FeatureGroup(org.osate.aadl2.FeatureGroup) Prototype(org.osate.aadl2.Prototype) DataPrototype(org.osate.aadl2.DataPrototype) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) FeaturePrototype(org.osate.aadl2.FeaturePrototype) ComponentPrototype(org.osate.aadl2.ComponentPrototype) ClassifierValue(org.osate.aadl2.ClassifierValue) DataClassifier(org.osate.aadl2.DataClassifier) AadlString(org.osate.aadl2.AadlString) SubprogramClassifier(org.osate.aadl2.SubprogramClassifier) DataAccess(org.osate.aadl2.DataAccess) ComponentPrototype(org.osate.aadl2.ComponentPrototype) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) EventPort(org.osate.aadl2.EventPort) SubprogramAccess(org.osate.aadl2.SubprogramAccess) ThreadGroup(org.osate.aadl2.ThreadGroup) EventDataPort(org.osate.aadl2.EventDataPort) PrototypeBinding(org.osate.aadl2.PrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) BusAccess(org.osate.aadl2.BusAccess) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) ProcessClassifier(org.osate.aadl2.ProcessClassifier) AbstractFeature(org.osate.aadl2.AbstractFeature) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) SubprogramGroupAccess(org.osate.aadl2.SubprogramGroupAccess) BehaviorPropertyConstant(org.osate.ba.aadlba.BehaviorPropertyConstant) SystemSubcomponent(org.osate.aadl2.SystemSubcomponent) FeaturePrototype(org.osate.aadl2.FeaturePrototype) DataSubcomponent(org.osate.aadl2.DataSubcomponent) Parameter(org.osate.aadl2.Parameter)

Example 27 with PropertyConstant

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

the class AadlBaTypeChecker method integerValueConstantToArrayDimension.

private ArrayDimension integerValueConstantToArrayDimension(IntegerValueConstant ivc) {
    ArrayDimension result = Aadl2Factory.eINSTANCE.createArrayDimension();
    ArraySize size = result.createSize();
    result.setSize(size);
    result.setLocationReference(ivc.getLocationReference());
    size.setLocationReference(ivc.getLocationReference());
    if (ivc instanceof BehaviorIntegerLiteral) {
        size.setSize(((BehaviorIntegerLiteral) ivc).getValue());
    } else if (ivc instanceof BehaviorPropertyConstant) {
        PropertyExpression pe = null;
        PropertyConstant pc = ((BehaviorPropertyConstant) ivc).getProperty();
        pe = pc.getConstantValue();
        if (pe instanceof NumberValue) {
            double value = ((NumberValue) pe).getScaledValue();
            size.setSize((long) value);
        } else {
            String msg = "cannot evaluate the property constant";
            _errManager.warning(ivc, msg);
        }
    } else if (ivc instanceof PropertyReference) {
        PropertyReference pr = (PropertyReference) ivc;
        PropertyNameHolder last = pr.getProperties().get(pr.getProperties().size() - 1);
        Element el = last.getProperty().getElement();
        if (el instanceof NumberValue) {
            double value = ((NumberValue) el).getScaledValue();
            size.setSize((long) value);
        } else {
            String msg = "cannot evaluate the property value";
            _errManager.warning(ivc, msg);
        }
    } else {
        String errorMsg = "integerValueConstantToArrayDimension : " + ivc.getClass().getSimpleName() + " is not supported yet.";
        System.err.println(errorMsg);
        throw new UnsupportedOperationException(errorMsg);
    }
    return result;
}
Also used : Element(org.osate.aadl2.Element) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) DeclarativeBehaviorElement(org.osate.ba.declarative.DeclarativeBehaviorElement) NamedElement(org.osate.aadl2.NamedElement) PropertyConstant(org.osate.aadl2.PropertyConstant) DeclarativePropertyReference(org.osate.ba.declarative.DeclarativePropertyReference) NumberValue(org.osate.aadl2.NumberValue) ArraySize(org.osate.aadl2.ArraySize) PropertyExpression(org.osate.aadl2.PropertyExpression) ArrayDimension(org.osate.aadl2.ArrayDimension) DeclarativeArrayDimension(org.osate.ba.declarative.DeclarativeArrayDimension)

Example 28 with PropertyConstant

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

the class AadlBaTypeChecker method propertyReferenceResolver.

private ValueConstant propertyReferenceResolver(DeclarativePropertyReference ref) {
    ValueConstant result = null;
    if (ref.isPropertySet()) {
        DeclarativePropertyName firstName = ref.getPropertyNames().get(0);
        // Property constant from a property set.
        if (firstName.getOsateRef() instanceof PropertyConstant) {
            BehaviorPropertyConstant tmp = _fact.createBehaviorPropertyConstant();
            tmp.setProperty((PropertyConstant) firstName.getOsateRef());
            if (ref.getQualifiedName() != null) {
                tmp.setPropertySet((PropertySet) ref.getQualifiedName().getOsateRef());
            }
            result = tmp;
        } else // Property value case.
        {
            PropertySetPropertyReference tmp = _fact.createPropertySetPropertyReference();
            propertyNameListResolver(ref.getPropertyNames(), tmp.getProperties());
            if (ref.getQualifiedName() != null) {
                tmp.setPropertySet((PropertySet) ref.getQualifiedName().getOsateRef());
            }
            result = tmp;
        }
    } else if (// [qualified] classifier case.
    ref.getQualifiedName() != null) {
        ClassifierPropertyReference tmp = _fact.createClassifierPropertyReference();
        tmp.setClassifier((Classifier) ref.getQualifiedName().getOsateRef());
        propertyNameListResolver(ref.getPropertyNames(), tmp.getProperties());
        result = tmp;
    } else // Classifier feature case.
    {
        ClassifierFeaturePropertyReference tmp = _fact.createClassifierFeaturePropertyReference();
        classifierFeatureResolver(tmp, ref.getReference());
        propertyNameListResolver(ref.getPropertyNames(), tmp.getProperties());
        result = tmp;
    }
    result.setLocationReference(ref.getLocationReference());
    return result;
}
Also used : Classifier(org.osate.aadl2.Classifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) DeclarativePropertyName(org.osate.ba.declarative.DeclarativePropertyName) PropertyConstant(org.osate.aadl2.PropertyConstant)

Example 29 with PropertyConstant

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

the class AadlProject method getMaxTime.

public static IntegerWithUnits<TimeUnits> getMaxTime(EObject lookupContext) {
    PropertyConstant constant = getMaxTime_PropertyConstant(lookupContext);
    PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue());
    return new IntegerWithUnits<>(resolved, TimeUnits.class);
}
Also used : IntegerWithUnits(org.osate.pluginsupport.properties.IntegerWithUnits) PropertyExpression(org.osate.aadl2.PropertyExpression) PropertyConstant(org.osate.aadl2.PropertyConstant)

Example 30 with PropertyConstant

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

PropertyConstant (org.osate.aadl2.PropertyConstant)40 PropertyExpression (org.osate.aadl2.PropertyExpression)27 IntegerLiteral (org.osate.aadl2.IntegerLiteral)18 Property (org.osate.aadl2.Property)14 Classifier (org.osate.aadl2.Classifier)12 ClassifierValue (org.osate.aadl2.ClassifierValue)12 ListValue (org.osate.aadl2.ListValue)12 NamedValue (org.osate.aadl2.NamedValue)10 NamedElement (org.osate.aadl2.NamedElement)9 List (java.util.List)8 EObject (org.eclipse.emf.ecore.EObject)8 IntegerWithUnits (org.osate.pluginsupport.properties.IntegerWithUnits)7 AbstractNamedValue (org.osate.aadl2.AbstractNamedValue)6 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)6 ArraySize (org.osate.aadl2.ArraySize)5 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)5 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)5 PropertyType (org.osate.aadl2.PropertyType)5 Aadl2Package (org.osate.aadl2.Aadl2Package)4 ArrayDimension (org.osate.aadl2.ArrayDimension)4