Search in sources :

Example 11 with ComponentPrototype

use of org.osate.aadl2.ComponentPrototype 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 12 with ComponentPrototype

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

the class ComponentPrototypeBindingImpl method setFormal.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
public void setFormal(Prototype newFormal) {
    if (newFormal != null && !((EObject) newFormal).eIsProxy() && !(newFormal instanceof ComponentPrototype)) {
        return;
    }
    Prototype oldFormal = formal;
    formal = newFormal;
    if (eNotificationRequired()) {
        eNotify(new ENotificationImpl(this, Notification.SET, Aadl2Package.COMPONENT_PROTOTYPE_BINDING__FORMAL, oldFormal, formal));
    }
}
Also used : Prototype(org.osate.aadl2.Prototype) ComponentPrototype(org.osate.aadl2.ComponentPrototype) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) ComponentPrototype(org.osate.aadl2.ComponentPrototype)

Example 13 with ComponentPrototype

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

the class InstanceUtil method getInstantiatedClassifier.

/**
 * Get the component or feature group classifier that is instantiated by an
 * instance object. Resolve prototypes if needed.
 *
 * @param iobj the instance object
 * @param index the index of the instance object in an array
 * @param classifierCache an optional cache of known instantiated
 *            classifiers, may be null
 * @return the instantiated classifier together with bindings for anonymous
 *         classifiers
 */
public static InstantiatedClassifier getInstantiatedClassifier(InstanceObject iobj, int index, HashMap<InstanceObject, InstantiatedClassifier> classifierCache) {
    InstantiatedClassifier ic = null;
    if (classifierCache != null) {
        final InstantiatedClassifier temp = classifierCache.get(iobj);
        if (temp != null) {
            return temp == InstantiatedClassifier.NULL ? null : temp;
        }
    }
    if (iobj instanceof SystemInstance) {
        ic = new InstantiatedClassifier(((SystemInstance) iobj).getComponentImplementation(), null);
    }
    if (ic == null) {
        Classifier classifier = null;
        EList<PrototypeBinding> prototypeBindings = null;
        Prototype prototype = null;
        if (iobj instanceof ComponentInstance) {
            Subcomponent sub = ((ComponentInstance) iobj).getSubcomponent();
            classifier = sub.getClassifier();
            prototypeBindings = sub.getOwnedPrototypeBindings();
            prototype = sub.getPrototype();
        } else if (iobj instanceof FeatureInstance) {
            FeatureType ft = ((FeatureGroup) ((FeatureInstance) iobj).getFeature()).getFeatureType();
            classifier = (ft instanceof Classifier) ? (Classifier) ft : null;
            prototype = (ft instanceof Prototype) ? (Prototype) ft : null;
        } else {
            return null;
        }
        if (classifier != null) {
            ic = new InstantiatedClassifier(classifier, prototypeBindings);
        }
        // no classifier => try prototype
        if (ic == null) {
            if (prototype != null) {
                // resolve prototype
                if (prototype instanceof ComponentPrototype) {
                    ComponentPrototypeActual cpa = resolveComponentPrototype(prototype, iobj, classifierCache);
                    if (cpa != null) {
                        ic = new InstantiatedClassifier((ComponentClassifier) cpa.getSubcomponentType(), cpa.getBindings());
                    } else {
                        // ISSUE 986: If the constraining classifier is missing (null), then don't create an InstantiatedClassifier object
                        final ComponentClassifier cc = ((ComponentPrototype) prototype).getConstrainingClassifier();
                        if (cc != null) {
                            ic = new InstantiatedClassifier(cc, noBindings);
                        }
                    }
                } else if (prototype instanceof FeatureGroupPrototype) {
                    FeatureGroupPrototypeActual fpa = resolveFeatureGroupPrototype(prototype, iobj, classifierCache);
                    if (fpa != null) {
                        ic = new InstantiatedClassifier((FeatureGroupType) fpa.getFeatureType(), fpa.getBindings());
                    } else {
                        ic = new InstantiatedClassifier(((FeatureGroupPrototype) prototype).getConstrainingFeatureGroupType(), noBindings);
                    }
                }
            }
        }
    }
    if (classifierCache != null) {
        classifierCache.put(iobj, ic == null ? InstantiatedClassifier.NULL : ic);
    }
    return ic;
}
Also used : FeatureType(org.osate.aadl2.FeatureType) ComponentClassifier(org.osate.aadl2.ComponentClassifier) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) Prototype(org.osate.aadl2.Prototype) ComponentPrototype(org.osate.aadl2.ComponentPrototype) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) FeatureGroupPrototypeActual(org.osate.aadl2.FeatureGroupPrototypeActual) ComponentPrototype(org.osate.aadl2.ComponentPrototype) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) ComponentPrototypeActual(org.osate.aadl2.ComponentPrototypeActual) SystemInstance(org.osate.aadl2.instance.SystemInstance) Subcomponent(org.osate.aadl2.Subcomponent) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) PrototypeBinding(org.osate.aadl2.PrototypeBinding)

Example 14 with ComponentPrototype

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

the class PropertiesLinkingService method getLinkedObjects.

/**
 * returns the first linked object
 */
@Override
public List<EObject> getLinkedObjects(EObject context, EReference reference, INode node) throws IllegalNodeException {
    final EClass requiredType = reference.getEReferenceType();
    if (requiredType == null) {
        return Collections.<EObject>emptyList();
    }
    EObject searchResult = null;
    final EClass cl = Aadl2Package.eINSTANCE.getClassifier();
    final EClass sct = Aadl2Package.eINSTANCE.getSubcomponentType();
    final EClass pt = Aadl2Package.eINSTANCE.getPropertyType();
    final String name = getCrossRefNodeAsString(node);
    if (sct.isSuperTypeOf(requiredType) || cl.isSuperTypeOf(requiredType)) {
        // XXX: this code can be replicated in Aadl2LinkingService as it is called often in the core
        // resolve classifier reference
        EObject e = findClassifier(context, reference, name);
        if (e != null) {
            // the result satisfied the expected class
            return Collections.singletonList(e);
        }
        if (!(context instanceof Generalization) && sct.isSuperTypeOf(requiredType)) {
            // need to resolve prototype
            EObject res = AadlUtil.getContainingClassifier(context).findNamedElement(name);
            if (Aadl2Package.eINSTANCE.getDataPrototype() == reference) {
                if (res instanceof DataPrototype) {
                    searchResult = res;
                }
            } else if (res instanceof ComponentPrototype) {
                searchResult = res;
            }
        }
    } else if (Aadl2Package.eINSTANCE.getModelUnit() == requiredType) {
        AadlPackage pack = findAadlPackage(context, name, reference);
        if (pack != null) {
            searchResult = pack;
        } else {
            PropertySet ps = findPropertySet(context, name, reference);
            if (ps != null) {
                searchResult = ps;
            }
        }
    } else if (Aadl2Package.eINSTANCE.getAadlPackage() == requiredType) {
        AadlPackage pack = findAadlPackage(context, name, reference);
        if (pack != null) {
            searchResult = pack;
        }
    } else if (Aadl2Package.eINSTANCE.getPropertySet() == requiredType) {
        PropertySet ps = findPropertySet(context, name, reference);
        if (ps != null) {
            searchResult = ps;
        }
    } else if (Aadl2Package.eINSTANCE.getFeature().isSuperTypeOf(requiredType)) {
        if (context instanceof Feature) {
            // Feature referenced in feature refinement
            Classifier ns = AadlUtil.getContainingClassifier(context);
            // we need to resolve a refinement
            if (ns.getExtended() != null) {
                EObject res = ns.getExtended().findNamedElement(name);
                if (res != null && res instanceof Feature) {
                    searchResult = res;
                }
            } else {
                return Collections.emptyList();
            }
        } else if (context instanceof FlowEnd) {
            FlowEnd flowEnd = (FlowEnd) context;
            searchResult = findElementInContext(flowEnd, flowEnd.getContext(), name, Feature.class);
        }
    } else if (Aadl2Package.eINSTANCE.getSubcomponent().isSuperTypeOf(requiredType)) {
        // if context Subcomponent then find in extension source (refined
        // to)
        // prototype binding as context
        Classifier ns = AadlUtil.getContainingClassifier(context);
        if (context instanceof Subcomponent) {
            // we need to resolve a refinement
            if (ns.getExtended() != null) {
                ns = ns.getExtended();
            } else {
                return Collections.emptyList();
            }
        }
        EObject res = ns.findNamedElement(name);
        if (res instanceof Subcomponent) {
            searchResult = res;
        }
    } else if (Aadl2Package.eINSTANCE.getProperty() == requiredType) {
        // look for property definition in property set
        return findPropertyDefinitionAsList(context, reference, name);
    } else if (Aadl2Package.eINSTANCE.getAbstractNamedValue() == requiredType) {
        // AbstractNamedValue: constant reference, property definition reference, unit literal, enumeration literal
        if (context instanceof NamedValue) {
            List<EObject> res = Collections.EMPTY_LIST;
            if (name.indexOf("::") == -1) {
                // names without qualifier. Must be enum/unit literal
                res = findEnumLiteralAsList(context, reference, name);
                if (res.isEmpty()) {
                    res = findUnitLiteralAsList(context, reference, name);
                }
            }
            if (res.isEmpty()) {
                res = findPropertyConstant(context, reference, name);
            }
            if (res.isEmpty()) {
                res = findPropertyDefinitionAsList(context, reference, name);
            }
            return res;
        }
    } else if (Aadl2Package.eINSTANCE.getBasicProperty() == requiredType) {
        // look for record field definition
        if (context instanceof BasicPropertyAssociation) {
            BasicPropertyAssociation bpa = (BasicPropertyAssociation) context;
            // TODO: Need to check that the type of the record field is
            // correct for the value.
            Element parent = bpa.getOwner();
            while (parent != null && !(parent instanceof BasicPropertyAssociation || parent instanceof PropertyAssociation || parent instanceof Property || parent instanceof PropertyConstant)) {
                parent = parent.getOwner();
            }
            PropertyType propertyType = null;
            if (parent instanceof BasicPropertyAssociation) {
                BasicProperty bp = ((BasicPropertyAssociation) parent).getProperty();
                if (bp != null) {
                    propertyType = bp.getPropertyType();
                }
            } else if (parent instanceof PropertyAssociation) {
                Property pd = ((PropertyAssociation) parent).getProperty();
                if (pd != null) {
                    propertyType = pd.getPropertyType();
                }
            } else if (parent instanceof Property) {
                propertyType = ((Property) parent).getPropertyType();
            } else if (parent instanceof PropertyConstant) {
                propertyType = ((PropertyConstant) parent).getPropertyType();
            }
            propertyType = AadlUtil.getBasePropertyType(propertyType);
            if (propertyType != null && propertyType instanceof RecordType) {
                BasicProperty rf = (BasicProperty) ((RecordType) propertyType).findNamedElement(name);
                if (rf != null) {
                    searchResult = rf;
                }
            }
        }
    } else if (pt.isSuperTypeOf(requiredType)) {
        // look for property type in property set
        return findPropertyType(context, reference, name);
    } else if (Aadl2Package.eINSTANCE.getPropertyConstant() == requiredType) {
        // look for property constant in property set
        return findPropertyConstant(context, reference, name);
    } else if (Aadl2Package.eINSTANCE.getUnitLiteral() == requiredType) {
        // look for unit literal pointed to by baseUnit
        return findUnitLiteralAsList(context, reference, name);
    } else if (Aadl2Package.eINSTANCE.getEnumerationLiteral() == requiredType) {
        // look for enumeration literal
        return findEnumLiteralAsList(context, reference, name);
    } else if (Aadl2Package.eINSTANCE.getMode() == requiredType) {
        // referenced by mode transition, inmodes, ModeBinding
        EObject res = null;
        if (context instanceof ModeBinding) {
            if (reference == Aadl2Package.eINSTANCE.getModeBinding_ParentMode()) {
                res = AadlUtil.getContainingClassifier(context).findNamedElement(name);
            } else if (reference == Aadl2Package.eINSTANCE.getModeBinding_DerivedMode()) {
                Subcomponent subcomponent = AadlUtil.getContainingSubcomponent(context);
                while (subcomponent.getSubcomponentType() == null && subcomponent.getRefined() != null) {
                    subcomponent = subcomponent.getRefined();
                }
                ComponentClassifier subcomponentClassifier = null;
                if (subcomponent.getSubcomponentType() instanceof ComponentClassifier) {
                    subcomponentClassifier = ((ComponentClassifier) subcomponent.getSubcomponentType());
                } else if (subcomponent.getSubcomponentType() instanceof ComponentPrototype) {
                    subcomponentClassifier = findClassifierForComponentPrototype(AadlUtil.getContainingClassifier(context), ((ComponentPrototype) subcomponent.getSubcomponentType()));
                }
                if (subcomponentClassifier != null) {
                    res = subcomponentClassifier.findNamedElement(name);
                }
            }
        } else {
            // check about in modes in a contained property association
            PropertyAssociation pa = AadlUtil.getContainingPropertyAssociation(context);
            if (pa != null && !pa.getAppliesTos().isEmpty()) {
                ContainedNamedElement path = pa.getAppliesTos().get(0);
                EList<ContainmentPathElement> cpelist = path.getContainmentPathElements();
                Subcomponent cpesub = null;
                for (ContainmentPathElement containmentPathElement : cpelist) {
                    if (containmentPathElement.getNamedElement() instanceof Subcomponent) {
                        cpesub = (Subcomponent) containmentPathElement.getNamedElement();
                    } else {
                        break;
                    }
                }
                if (cpesub != null) {
                    if (cpesub.getAllClassifier() != null) {
                        res = cpesub.getAllClassifier().findNamedElement(name);
                    }
                } else {
                    res = AadlUtil.getContainingClassifier(context).findNamedElement(name);
                }
            } else {
                if ((pa != null) && (pa.getOwner() instanceof Subcomponent)) {
                    Subcomponent subco = (Subcomponent) pa.getOwner();
                    if (subco.getAllClassifier() != null) {
                        res = subco.getAllClassifier().findNamedElement(name);
                    }
                } else {
                    res = AadlUtil.getContainingClassifier(context).findNamedElement(name);
                }
            }
        }
        if (res != null && res instanceof Mode) {
            searchResult = res;
        }
    } else if (Aadl2Package.eINSTANCE.getNamedElement() == requiredType) {
        // containment path element
        if (context instanceof ContainmentPathElement) {
            EObject res = null;
            if (((ContainmentPathElement) context).getOwner() instanceof ContainmentPathElement) {
                // find next element in namespace of previous element
                ContainmentPathElement el = (ContainmentPathElement) ((ContainmentPathElement) context).getOwner();
                NamedElement ne = el.getNamedElement();
                if (ne instanceof Subcomponent) {
                    Subcomponent subcomponent = (Subcomponent) ne;
                    while (subcomponent.getSubcomponentType() == null && subcomponent.getRefined() != null) {
                        subcomponent = subcomponent.getRefined();
                    }
                    ComponentClassifier ns = null;
                    if (subcomponent.getSubcomponentType() instanceof ComponentClassifier) {
                        ns = (ComponentClassifier) subcomponent.getSubcomponentType();
                    } else if (subcomponent.getSubcomponentType() instanceof ComponentPrototype) {
                        ns = ResolvePrototypeUtil.resolveComponentPrototype((ComponentPrototype) subcomponent.getSubcomponentType(), el);
                    }
                    if (ns != null) {
                        res = ns.findNamedElement(name);
                        if (res == null && (ne instanceof ThreadSubcomponent || ne instanceof SubprogramSubcomponent || ne instanceof AbstractSubcomponent) && ns instanceof BehavioredImplementation) {
                            res = AadlUtil.findNamedElementInList(((BehavioredImplementation) ns).subprogramCalls(), name);
                        }
                    }
                } else if (ne instanceof FeatureGroup) {
                    FeatureGroup featureGroup = (FeatureGroup) ne;
                    while (featureGroup.getFeatureType() == null && featureGroup.getRefined() instanceof FeatureGroup) {
                        featureGroup = (FeatureGroup) featureGroup.getRefined();
                    }
                    FeatureGroupType ns = null;
                    if (featureGroup.getFeatureType() instanceof FeatureGroupType) {
                        ns = (FeatureGroupType) featureGroup.getFeatureType();
                    } else if (featureGroup.getFeatureType() instanceof FeatureGroupPrototype) {
                        ns = ResolvePrototypeUtil.resolveFeatureGroupPrototype((FeatureGroupPrototype) featureGroup.getFeatureType(), el);
                    }
                    if (ns != null) {
                        res = ns.findNamedElement(name);
                    }
                }
            } else {
                // the first containment path element
                Classifier ns = null;
                PropertyAssociation containingPropertyAssociation = AadlUtil.getContainingPropertyAssociation(context);
                if (containingPropertyAssociation != null) {
                    // need to make sure we look in the correct name space
                    if (containingPropertyAssociation.getOwner() instanceof Subcomponent) {
                        Subcomponent subcomponent = (Subcomponent) containingPropertyAssociation.getOwner();
                        while (subcomponent.getSubcomponentType() == null && subcomponent.getRefined() != null) {
                            subcomponent = subcomponent.getRefined();
                        }
                        if (subcomponent.getSubcomponentType() instanceof ComponentClassifier) {
                            ns = (ComponentClassifier) subcomponent.getSubcomponentType();
                        } else if (subcomponent.getSubcomponentType() instanceof ComponentPrototype) {
                            ns = ResolvePrototypeUtil.resolveComponentPrototype((ComponentPrototype) subcomponent.getSubcomponentType(), AadlUtil.getContainingClassifier(context));
                        }
                    } else if (containingPropertyAssociation.getOwner() instanceof FeatureGroup) {
                        FeatureGroup fg = (FeatureGroup) containingPropertyAssociation.getOwner();
                        while (fg.getFeatureType() == null && fg.getRefined() instanceof FeatureGroup) {
                            fg = (FeatureGroup) fg.getRefined();
                        }
                        if (fg.getFeatureType() instanceof FeatureGroupType) {
                            ns = (FeatureGroupType) fg.getFeatureType();
                        } else if (fg.getFeatureType() instanceof FeatureGroupPrototype) {
                            ns = ResolvePrototypeUtil.resolveFeatureGroupPrototype((FeatureGroupPrototype) fg.getFeatureType(), AadlUtil.getContainingClassifier(context));
                        }
                    } else {
                        ns = containingPropertyAssociation.getContainingClassifier();
                    }
                }
                if (ns != null) {
                    res = ns.findNamedElement(name);
                }
            }
            if (res != null && res instanceof NamedElement) {
                searchResult = res;
            }
        }
    } else {
        List<EObject> superes = super.getLinkedObjects(context, reference, node);
        return superes;
    }
    if (searchResult != null) {
        return Collections.singletonList(searchResult);
    }
    return Collections.<EObject>emptyList();
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) FeatureGroup(org.osate.aadl2.FeatureGroup) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) Element(org.osate.aadl2.Element) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) AbstractSubcomponent(org.osate.aadl2.AbstractSubcomponent) FeatureGroupType(org.osate.aadl2.FeatureGroupType) NamedValue(org.osate.aadl2.NamedValue) Classifier(org.osate.aadl2.Classifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) PropertyType(org.osate.aadl2.PropertyType) Generalization(org.osate.aadl2.Generalization) Feature(org.osate.aadl2.Feature) ComponentPrototype(org.osate.aadl2.ComponentPrototype) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) BasicProperty(org.osate.aadl2.BasicProperty) EClass(org.eclipse.emf.ecore.EClass) RecordType(org.osate.aadl2.RecordType) EObject(org.eclipse.emf.ecore.EObject) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) ThreadSubcomponent(org.osate.aadl2.ThreadSubcomponent) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) AbstractSubcomponent(org.osate.aadl2.AbstractSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) List(java.util.List) EList(org.eclipse.emf.common.util.EList) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) AadlPackage(org.osate.aadl2.AadlPackage) BehavioredImplementation(org.osate.aadl2.BehavioredImplementation) Mode(org.osate.aadl2.Mode) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) DataPrototype(org.osate.aadl2.DataPrototype) PropertyConstant(org.osate.aadl2.PropertyConstant) ThreadSubcomponent(org.osate.aadl2.ThreadSubcomponent) EList(org.eclipse.emf.common.util.EList) PropertySet(org.osate.aadl2.PropertySet) ModeBinding(org.osate.aadl2.ModeBinding) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) FlowEnd(org.osate.aadl2.FlowEnd)

Example 15 with ComponentPrototype

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

the class PropertiesLinkingService method findElementInContext.

protected static <T> T findElementInContext(Element referencingObject, Context context, String name, Class<T> validSearchResultType) {
    NamedElement searchResult = null;
    if (context == null) {
        searchResult = AadlUtil.getContainingClassifier(referencingObject).findNamedElement(name);
    } else if (context instanceof FeatureGroup) {
        FeatureGroup featureGroup = (FeatureGroup) context;
        while (featureGroup.getFeatureGroupType() == null && featureGroup.getFeatureGroupPrototype() == null && featureGroup.getRefined() instanceof FeatureGroup) {
            featureGroup = (FeatureGroup) featureGroup.getRefined();
        }
        FeatureGroupType featureGroupType = null;
        if (featureGroup.getFeatureGroupType() != null) {
            featureGroupType = featureGroup.getFeatureGroupType();
        } else if (featureGroup.getFeatureGroupPrototype() != null) {
            featureGroupType = findFeatureGroupTypeForFeatureGroupPrototype(AadlUtil.getContainingClassifier(referencingObject), featureGroup.getFeatureGroupPrototype());
        }
        if (featureGroupType != null) {
            searchResult = featureGroupType.findNamedElement(name);
        }
    } else if (context instanceof Feature) {
        Feature feature = (Feature) context;
        while (feature.getClassifier() == null && feature.getPrototype() == null && feature.getRefined() != null) {
            feature = feature.getRefined();
        }
        Classifier featureClassifier = null;
        if (feature.getClassifier() != null) {
            featureClassifier = feature.getClassifier();
        } else if (feature.getPrototype() != null) {
            featureClassifier = findClassifierForComponentPrototype(AadlUtil.getContainingClassifier(referencingObject), feature.getPrototype());
        }
        if (featureClassifier != null) {
            searchResult = featureClassifier.findNamedElement(name);
        }
    } else if (context instanceof Subcomponent) {
        Subcomponent subcomponent = (Subcomponent) context;
        while (subcomponent.getSubcomponentType() == null && subcomponent.getRefined() != null) {
            subcomponent = subcomponent.getRefined();
        }
        ComponentClassifier subcomponentClassifier = null;
        if (subcomponent.getSubcomponentType() instanceof ComponentClassifier) {
            subcomponentClassifier = (ComponentClassifier) subcomponent.getSubcomponentType();
        } else if (subcomponent.getSubcomponentType() instanceof ComponentPrototype) {
            subcomponentClassifier = findClassifierForComponentPrototype(AadlUtil.getContainingClassifier(referencingObject), (ComponentPrototype) subcomponent.getSubcomponentType());
        }
        if (subcomponentClassifier != null) {
            searchResult = subcomponentClassifier.findNamedElement(name);
        }
    } else if (context instanceof SubprogramCall) {
        SubprogramCall subprogramCall = (SubprogramCall) context;
        if (subprogramCall.getCalledSubprogram() instanceof ComponentClassifier) {
            searchResult = ((ComponentClassifier) subprogramCall.getCalledSubprogram()).findNamedElement(name);
        } else if (subprogramCall.getCalledSubprogram() instanceof SubprogramSubcomponent) {
            Subcomponent subcomponent = (SubprogramSubcomponent) subprogramCall.getCalledSubprogram();
            while (subcomponent.getSubcomponentType() == null && subcomponent.getRefined() != null) {
                subcomponent = subcomponent.getRefined();
            }
            ComponentClassifier subcomponentClassifier = null;
            if (subcomponent.getSubcomponentType() instanceof ComponentClassifier) {
                subcomponentClassifier = (ComponentClassifier) subcomponent.getSubcomponentType();
            } else if (subcomponent.getSubcomponentType() instanceof ComponentPrototype) {
                subcomponentClassifier = findClassifierForComponentPrototype(AadlUtil.getContainingClassifier(referencingObject), (ComponentPrototype) subcomponent.getSubcomponentType());
            }
            if (subcomponentClassifier != null) {
                searchResult = subcomponentClassifier.findNamedElement(name);
            }
        } else if (subprogramCall.getCalledSubprogram() instanceof SubprogramAccess) {
            Feature access = (SubprogramAccess) subprogramCall.getCalledSubprogram();
            while (access.getClassifier() == null && access.getPrototype() == null && access.getRefined() != null) {
                access = access.getRefined();
            }
            Classifier accessClassifier = null;
            if (access.getClassifier() != null) {
                accessClassifier = access.getClassifier();
            } else if (access.getPrototype() != null) {
                CallContext callContext = subprogramCall.getContext();
                if (callContext instanceof ComponentType) {
                    accessClassifier = findClassifierForComponentPrototype((ComponentType) callContext, access.getPrototype());
                } else if (callContext instanceof FeatureGroup) {
                    FeatureGroup callContextFeatureGroup = (FeatureGroup) callContext;
                    FeatureGroupType prototypeContext = null;
                    while (callContextFeatureGroup.getFeatureGroupType() == null && callContextFeatureGroup.getFeatureGroupPrototype() == null && callContextFeatureGroup.getRefined() instanceof FeatureGroup) {
                        callContextFeatureGroup = (FeatureGroup) callContextFeatureGroup.getRefined();
                    }
                    if (callContextFeatureGroup.getFeatureGroupType() != null) {
                        prototypeContext = callContextFeatureGroup.getFeatureGroupType();
                    } else if (callContextFeatureGroup.getFeatureGroupPrototype() != null) {
                        prototypeContext = findFeatureGroupTypeForFeatureGroupPrototype(AadlUtil.getContainingClassifier(referencingObject), callContextFeatureGroup.getFeatureGroupPrototype());
                    }
                    if (prototypeContext != null) {
                        accessClassifier = findClassifierForComponentPrototype(prototypeContext, access.getPrototype());
                    }
                } else if (callContext instanceof SubprogramGroupAccess) {
                    Feature callContextAccess = (SubprogramGroupAccess) callContext;
                    Classifier prototypeContext = null;
                    while (callContextAccess.getClassifier() == null && callContextAccess.getPrototype() == null && callContextAccess.getRefined() != null) {
                        callContextAccess = callContextAccess.getRefined();
                    }
                    if (callContextAccess.getClassifier() != null) {
                        prototypeContext = callContextAccess.getClassifier();
                    } else if (callContextAccess.getPrototype() != null) {
                        prototypeContext = findClassifierForComponentPrototype(AadlUtil.getContainingClassifier(referencingObject), callContextAccess.getPrototype());
                    }
                    if (prototypeContext != null) {
                        accessClassifier = findClassifierForComponentPrototype(prototypeContext, access.getPrototype());
                    }
                } else if (callContext instanceof SubprogramGroupSubcomponent) {
                    Subcomponent callContextSubcomponent = (SubprogramGroupSubcomponent) callContext;
                    while (callContextSubcomponent.getSubcomponentType() == null && callContextSubcomponent.getRefined() != null) {
                        callContextSubcomponent = callContextSubcomponent.getRefined();
                    }
                    if (callContextSubcomponent.getSubcomponentType() instanceof ComponentClassifier) {
                        if (callContextSubcomponent.getOwnedPrototypeBindings().isEmpty()) {
                            accessClassifier = findClassifierForComponentPrototype(callContextSubcomponent.getClassifier(), access.getPrototype());
                        } else {
                            accessClassifier = findClassifierForComponentPrototype(callContextSubcomponent.getClassifier(), callContextSubcomponent, access.getPrototype());
                        }
                    } else if (callContextSubcomponent.getSubcomponentType() instanceof ComponentPrototype) {
                        ComponentClassifier prototypeContext = findClassifierForComponentPrototype(AadlUtil.getContainingClassifier(referencingObject), callContextSubcomponent.getPrototype());
                        if (prototypeContext != null) {
                            accessClassifier = findClassifierForComponentPrototype(prototypeContext, access.getPrototype());
                        }
                    }
                } else // callContext is null.
                {
                    accessClassifier = findClassifierForComponentPrototype(AadlUtil.getContainingClassifier(referencingObject), access.getPrototype());
                }
            }
            if (accessClassifier != null) {
                searchResult = accessClassifier.findNamedElement(name);
            }
        } else if (subprogramCall.getCalledSubprogram() instanceof ComponentPrototype) {
            ComponentClassifier classifier = findClassifierForComponentPrototype(AadlUtil.getContainingClassifier(referencingObject), (ComponentPrototype) subprogramCall.getCalledSubprogram());
            if (classifier != null) {
                searchResult = classifier.findNamedElement(name);
            }
        }
    }
    if (validSearchResultType.isInstance(searchResult)) {
        return validSearchResultType.cast(searchResult);
    } else {
        return null;
    }
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) FeatureGroup(org.osate.aadl2.FeatureGroup) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) ComponentType(org.osate.aadl2.ComponentType) FeatureGroupType(org.osate.aadl2.FeatureGroupType) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) Classifier(org.osate.aadl2.Classifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Feature(org.osate.aadl2.Feature) CallContext(org.osate.aadl2.CallContext) SubprogramGroupAccess(org.osate.aadl2.SubprogramGroupAccess) ComponentPrototype(org.osate.aadl2.ComponentPrototype) SubprogramAccess(org.osate.aadl2.SubprogramAccess) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) ThreadSubcomponent(org.osate.aadl2.ThreadSubcomponent) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) AbstractSubcomponent(org.osate.aadl2.AbstractSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) SubprogramCall(org.osate.aadl2.SubprogramCall)

Aggregations

ComponentPrototype (org.osate.aadl2.ComponentPrototype)21 ComponentClassifier (org.osate.aadl2.ComponentClassifier)14 FeatureGroupPrototype (org.osate.aadl2.FeatureGroupPrototype)13 Classifier (org.osate.aadl2.Classifier)10 FeaturePrototype (org.osate.aadl2.FeaturePrototype)9 ComponentPrototypeBinding (org.osate.aadl2.ComponentPrototypeBinding)8 Prototype (org.osate.aadl2.Prototype)7 EObject (org.eclipse.emf.ecore.EObject)6 ComponentPrototypeActual (org.osate.aadl2.ComponentPrototypeActual)6 DataPrototype (org.osate.aadl2.DataPrototype)6 FeatureGroupType (org.osate.aadl2.FeatureGroupType)6 NamedElement (org.osate.aadl2.NamedElement)6 Subcomponent (org.osate.aadl2.Subcomponent)6 EClass (org.eclipse.emf.ecore.EClass)5 FeatureGroup (org.osate.aadl2.FeatureGroup)5 FeatureGroupPrototypeBinding (org.osate.aadl2.FeatureGroupPrototypeBinding)5 Feature (org.osate.aadl2.Feature)4 SubprogramPrototype (org.osate.aadl2.SubprogramPrototype)4 EditablePrototype (org.osate.ge.aadl2.ui.internal.viewmodels.PrototypesModel.EditablePrototype)4 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)3