Aadl2ScopeProvider.java

/**
 * Copyright (c) 2004-2025 Carnegie Mellon University and others. (see Contributors file).
 * All Rights Reserved.
 * 
 * NO WARRANTY. ALL MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE
 * OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT
 * MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.
 * 
 * This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Created, in part, with funding and support from the United States Government. (see Acknowledgments file).
 * 
 * This program includes and/or can make use of certain third party source code, object code, documentation and other
 * files ("Third Party Software"). The Third Party Software that is used by this program is dependent upon your system
 * configuration. By using this program, You agree to comply with any and all relevant Third Party Software terms and
 * conditions contained in any such Third Party Software or separate license file distributed with such Third Party
 * Software. The parties who own the Third Party Software ("Third Party Licensors") are intended third party benefici-
 * aries to this license with respect to the terms applicable to their Third Party Software. Third Party Software li-
 * censes only apply to the Third Party Software and not any other portion of this program or this program as a whole.
 */
package org.osate.xtext.aadl2.scoping;

import com.google.common.base.Objects;
import com.google.common.collect.Iterables;
import java.util.ArrayList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.xtext.scoping.impl.SimpleScope;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ListExtensions;
import org.osate.aadl2.AadlPackage;
import org.osate.aadl2.AbstractSubcomponentType;
import org.osate.aadl2.AccessType;
import org.osate.aadl2.BehavioredImplementation;
import org.osate.aadl2.BusFeatureClassifier;
import org.osate.aadl2.BusSubcomponentType;
import org.osate.aadl2.CallContext;
import org.osate.aadl2.CalledSubprogram;
import org.osate.aadl2.Classifier;
import org.osate.aadl2.ComponentClassifier;
import org.osate.aadl2.ComponentImplementation;
import org.osate.aadl2.ComponentImplementationReference;
import org.osate.aadl2.ComponentPrototype;
import org.osate.aadl2.ComponentPrototypeActual;
import org.osate.aadl2.ComponentType;
import org.osate.aadl2.ConnectedElement;
import org.osate.aadl2.Connection;
import org.osate.aadl2.ConnectionEnd;
import org.osate.aadl2.Context;
import org.osate.aadl2.DataAccess;
import org.osate.aadl2.DataSubcomponentType;
import org.osate.aadl2.DeviceSubcomponentType;
import org.osate.aadl2.Element;
import org.osate.aadl2.EndToEndFlow;
import org.osate.aadl2.EndToEndFlowElement;
import org.osate.aadl2.EndToEndFlowSegment;
import org.osate.aadl2.Feature;
import org.osate.aadl2.FeatureClassifier;
import org.osate.aadl2.FeatureGroup;
import org.osate.aadl2.FeatureGroupPrototype;
import org.osate.aadl2.FeatureGroupPrototypeActual;
import org.osate.aadl2.FeatureGroupType;
import org.osate.aadl2.FeaturePrototype;
import org.osate.aadl2.FeatureType;
import org.osate.aadl2.Flow;
import org.osate.aadl2.FlowElement;
import org.osate.aadl2.FlowEnd;
import org.osate.aadl2.FlowImplementation;
import org.osate.aadl2.FlowSegment;
import org.osate.aadl2.FlowSpecification;
import org.osate.aadl2.MemorySubcomponentType;
import org.osate.aadl2.Mode;
import org.osate.aadl2.ModeFeature;
import org.osate.aadl2.ModeTransition;
import org.osate.aadl2.ModeTransitionTrigger;
import org.osate.aadl2.NamedElement;
import org.osate.aadl2.PackageSection;
import org.osate.aadl2.Port;
import org.osate.aadl2.PrivatePackageSection;
import org.osate.aadl2.ProcessSubcomponentType;
import org.osate.aadl2.ProcessorSubcomponentType;
import org.osate.aadl2.Prototype;
import org.osate.aadl2.Subcomponent;
import org.osate.aadl2.SubcomponentType;
import org.osate.aadl2.SubprogramAccess;
import org.osate.aadl2.SubprogramCall;
import org.osate.aadl2.SubprogramGroupAccess;
import org.osate.aadl2.SubprogramGroupSubcomponent;
import org.osate.aadl2.SubprogramGroupSubcomponentType;
import org.osate.aadl2.SubprogramSubcomponent;
import org.osate.aadl2.SubprogramSubcomponentType;
import org.osate.aadl2.SystemSubcomponentType;
import org.osate.aadl2.ThreadGroupSubcomponentType;
import org.osate.aadl2.ThreadSubcomponentType;
import org.osate.aadl2.TriggerPort;
import org.osate.aadl2.UnitsType;
import org.osate.aadl2.VirtualBusSubcomponentType;
import org.osate.aadl2.VirtualProcessorSubcomponentType;
import org.osate.aadl2.modelsupport.util.AadlUtil;
import org.osate.xtext.aadl2.properties.linking.PropertiesLinkingService;
import org.osate.xtext.aadl2.properties.scoping.PropertiesScopeProvider;

/**
 * This class contains custom scoping description.
 * 
 * see : http://www.eclipse.org/Xtext/documentation/latest/xtext.html#scoping
 * on how and when to use it
 */
@SuppressWarnings("all")
public class Aadl2ScopeProvider extends PropertiesScopeProvider {
  public IScope scope_TypeExtension_extended(final Element context, final EReference reference) {
    return this.scope_Classifier(context, reference);
  }

  public IScope scope_ComponentImplementation(final Element context, final EReference reference) {
    return this.scope_Classifier(context, reference);
  }

  public IScope scope_GroupExtension_extended(final Element context, final EReference reference) {
    return this.scope_Classifier(context, reference);
  }

  public IScope scope_FeatureGroupPrototype_constrainingFeatureGroupType(final Element context, final EReference reference) {
    return this.scope_Classifier(context, reference);
  }

  public IScope scope_FeatureGroupType_inverse(final Element context, final EReference reference) {
    return this.scope_Classifier(context, reference);
  }

  public IScope scope_Realization_implemented(final Element context, final EReference reference) {
    return this.scope_Classifier(context, reference);
  }

  public IScope scope_SubprogramCall_context(final Element context, final EReference reference) {
    IScope _xblockexpression = null;
    {
      IScope scope = this.scope_Classifier(context, reference);
      IScope _elvis = null;
      BehavioredImplementation _containerOfType = EcoreUtil2.<BehavioredImplementation>getContainerOfType(context, BehavioredImplementation.class);
      EList<NamedElement> _members = null;
      if (_containerOfType!=null) {
        _members=_containerOfType.getMembers();
      }
      Iterable<CallContext> _filter = null;
      if (_members!=null) {
        _filter=Iterables.<CallContext>filter(_members, CallContext.class);
      }
      Iterable<CallContext> _filterRefined = null;
      if (_filter!=null) {
        _filterRefined=PropertiesScopeProvider.<CallContext>filterRefined(_filter);
      }
      SimpleScope _scopeFor = null;
      if (_filterRefined!=null) {
        _scopeFor=PropertiesScopeProvider.scopeFor(_filterRefined, scope);
      }
      if (_scopeFor != null) {
        _elvis = _scopeFor;
      } else {
        _elvis = scope;
      }
      _xblockexpression = _elvis;
    }
    return _xblockexpression;
  }

  public IScope scope_SubprogramCall_calledSubprogram(final Element context, final EReference reference) {
    IScope _xblockexpression = null;
    {
      IScope scope = this.scope_Classifier(context, reference);
      SubprogramCall _containerOfType = EcoreUtil2.<SubprogramCall>getContainerOfType(context, SubprogramCall.class);
      CallContext _context = null;
      if (_containerOfType!=null) {
        _context=_containerOfType.getContext();
      }
      final CallContext callContext = _context;
      if ((callContext == null)) {
        scope = PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<CalledSubprogram>filterRefined(Iterables.<CalledSubprogram>filter(EcoreUtil2.<Classifier>getContainerOfType(context, Classifier.class).getMembers(), CalledSubprogram.class)), scope);
      } else {
        scope = IScope.NULLSCOPE;
        Classifier callContextNamespace = null;
        boolean _matched = false;
        if (callContext instanceof ComponentType) {
          _matched=true;
          EList<Classifier> _ownedClassifiers = EcoreUtil2.<AadlPackage>getContainerOfType(callContext, AadlPackage.class).getPublicSection().getOwnedClassifiers();
          final ArrayList<Classifier> packageClassifiers = new ArrayList<Classifier>(_ownedClassifiers);
          final PackageSection packageSectionForComponentType = EcoreUtil2.<PackageSection>getContainerOfType(callContext, PackageSection.class);
          if (((packageSectionForComponentType instanceof PrivatePackageSection) && 
            Objects.equal(packageSectionForComponentType, EcoreUtil2.<PrivatePackageSection>getContainerOfType(context, PrivatePackageSection.class)))) {
            packageClassifiers.addAll(packageSectionForComponentType.getOwnedClassifiers());
          }
          final Function1<ComponentImplementation, Boolean> _function = (ComponentImplementation it) -> {
            ComponentType _type = it.getType();
            return Boolean.valueOf(Objects.equal(_type, callContext));
          };
          final Function1<ComponentImplementation, QualifiedName> _function_1 = (ComponentImplementation it) -> {
            String _name = it.getName();
            int _lastIndexOf = it.getName().lastIndexOf(".");
            int _plus = (_lastIndexOf + 1);
            return QualifiedName.create(_name.substring(_plus));
          };
          scope = PropertiesScopeProvider.<ComponentImplementation>scopeFor(IterableExtensions.<ComponentImplementation>filter(Iterables.<ComponentImplementation>filter((Iterables.<CalledSubprogram>filter(packageClassifiers, CalledSubprogram.class)), ComponentImplementation.class), _function), _function_1, 
            IScope.NULLSCOPE);
          callContextNamespace = ((ComponentType)callContext);
        }
        if (!_matched) {
          if (callContext instanceof SubprogramGroupSubcomponent) {
            _matched=true;
            callContextNamespace = ((SubprogramGroupSubcomponent)callContext).getComponentType();
          }
        }
        if (!_matched) {
          if (callContext instanceof SubprogramGroupAccess) {
            _matched=true;
            if ((Objects.equal(((SubprogramGroupAccess)callContext).getKind(), AccessType.REQUIRES) && 
              (((SubprogramGroupAccess)callContext).getSubprogramGroupFeatureClassifier() instanceof Classifier))) {
              SubprogramGroupSubcomponentType _subprogramGroupFeatureClassifier = ((SubprogramGroupAccess)callContext).getSubprogramGroupFeatureClassifier();
              callContextNamespace = ((Classifier) _subprogramGroupFeatureClassifier);
            }
          }
        }
        if (!_matched) {
          if (callContext instanceof FeatureGroup) {
            _matched=true;
            callContextNamespace = ((FeatureGroup)callContext).getFeatureGroupType();
          }
        }
        IScope _elvis = null;
        EList<NamedElement> _members = null;
        if (callContextNamespace!=null) {
          _members=callContextNamespace.getMembers();
        }
        Iterable<CalledSubprogram> _filter = null;
        if (_members!=null) {
          _filter=Iterables.<CalledSubprogram>filter(_members, CalledSubprogram.class);
        }
        Iterable<CalledSubprogram> _filterRefined = null;
        if (_filter!=null) {
          _filterRefined=PropertiesScopeProvider.<CalledSubprogram>filterRefined(_filter);
        }
        SimpleScope _scopeFor = null;
        if (_filterRefined!=null) {
          _scopeFor=PropertiesScopeProvider.scopeFor(_filterRefined, scope);
        }
        if (_scopeFor != null) {
          _elvis = _scopeFor;
        } else {
          _elvis = scope;
        }
        scope = _elvis;
      }
      _xblockexpression = scope;
    }
    return _xblockexpression;
  }

  public IScope scope_ComponentPrototype_constrainingClassifier(final Element context, final EReference reference) {
    return this.scope_Classifier(context, reference);
  }

  /**
   * Reference is from AbstractPrototype, BusPrototype, DataPrototype, DevicePrototype, MemoryPrototype,
   * ProcessPrototype, ProcessorPrototype, SubprogramPrototype, SubprogramGroupPrototype, SystemPrototype,
   * ThreadPrototype, ThreadGroupPrototype, VirtualBusPrototype, VirtualProcessorPrototype,
   * FeatureGroupPrototype and FeaturePrototype in Aadl2.xtext
   */
  public IScope scope_Prototype_refined(final Classifier context, final EReference reference) {
    IScope _elvis = null;
    Classifier _extended = context.getExtended();
    EList<Prototype> _allPrototypes = null;
    if (_extended!=null) {
      _allPrototypes=Aadl2ScopeProvider.allPrototypes(_extended);
    }
    Iterable<Prototype> _filterRefined = null;
    if (_allPrototypes!=null) {
      _filterRefined=PropertiesScopeProvider.<Prototype>filterRefined(_allPrototypes);
    }
    SimpleScope _scopeFor = null;
    if (_filterRefined!=null) {
      _scopeFor=PropertiesScopeProvider.scopeFor(_filterRefined);
    }
    if (_scopeFor != null) {
      _elvis = _scopeFor;
    } else {
      _elvis = IScope.NULLSCOPE;
    }
    return _elvis;
  }

  public IScope scope_FeaturePrototype_constrainingClassifier(final Element context, final EReference reference) {
    return this.scope_Classifier(context, reference);
  }

  public IScope scope_PrototypeBinding_formal(final ComponentPrototypeActual context, final EReference reference) {
    IScope _xblockexpression = null;
    {
      final SubcomponentType subcomponentType = context.getSubcomponentType();
      IScope _xifexpression = null;
      if ((subcomponentType instanceof ComponentClassifier)) {
        _xifexpression = PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<Prototype>filterRefined(((ComponentClassifier)subcomponentType).getAllPrototypes()));
      } else {
        _xifexpression = IScope.NULLSCOPE;
      }
      _xblockexpression = _xifexpression;
    }
    return _xblockexpression;
  }

  public IScope scope_PrototypeBinding_formal(final FeatureGroupPrototypeActual context, final EReference reference) {
    IScope _xblockexpression = null;
    {
      final FeatureType featureType = context.getFeatureType();
      IScope _xifexpression = null;
      if ((featureType instanceof FeatureGroupType)) {
        _xifexpression = PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<Prototype>filterRefined(((FeatureGroupType)featureType).getAllPrototypes()));
      } else {
        _xifexpression = IScope.NULLSCOPE;
      }
      _xblockexpression = _xifexpression;
    }
    return _xblockexpression;
  }

  public IScope scope_PrototypeBinding_formal(final ComponentImplementationReference context, final EReference reference) {
    IScope _elvis = null;
    ComponentImplementation _implementation = context.getImplementation();
    EList<Prototype> _allPrototypes = null;
    if (_implementation!=null) {
      _allPrototypes=_implementation.getAllPrototypes();
    }
    Iterable<Prototype> _filterRefined = null;
    if (_allPrototypes!=null) {
      _filterRefined=PropertiesScopeProvider.<Prototype>filterRefined(_allPrototypes);
    }
    SimpleScope _scopeFor = null;
    if (_filterRefined!=null) {
      _scopeFor=PropertiesScopeProvider.scopeFor(_filterRefined);
    }
    if (_scopeFor != null) {
      _elvis = _scopeFor;
    } else {
      _elvis = IScope.NULLSCOPE;
    }
    return _elvis;
  }

  public IScope scope_PrototypeBinding_formal(final Subcomponent context, final EReference reference) {
    IScope _elvis = null;
    ComponentClassifier _allClassifier = context.getAllClassifier();
    EList<Prototype> _allPrototypes = null;
    if (_allClassifier!=null) {
      _allPrototypes=_allClassifier.getAllPrototypes();
    }
    Iterable<Prototype> _filterRefined = null;
    if (_allPrototypes!=null) {
      _filterRefined=PropertiesScopeProvider.<Prototype>filterRefined(_allPrototypes);
    }
    SimpleScope _scopeFor = null;
    if (_filterRefined!=null) {
      _scopeFor=PropertiesScopeProvider.scopeFor(_filterRefined);
    }
    if (_scopeFor != null) {
      _elvis = _scopeFor;
    } else {
      _elvis = IScope.NULLSCOPE;
    }
    return _elvis;
  }

  public SimpleScope scope_PrototypeBinding_formal(final Classifier context, final EReference reference) {
    final Function1<Classifier, EList<Prototype>> _function = (Classifier it) -> {
      return Aadl2ScopeProvider.allPrototypes(it);
    };
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<Prototype>filterRefined(IterableExtensions.<Prototype>toSet(Iterables.<Prototype>concat(ListExtensions.<Classifier, EList<Prototype>>map(context.getGenerals(), _function)))));
  }

  public SimpleScope scope_FeatureGroupPrototypeActual_featureType(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<FeatureGroupPrototype>filterRefined(Iterables.<FeatureGroupPrototype>filter(Aadl2ScopeProvider.allPrototypes(EcoreUtil2.<Classifier>getContainerOfType(context, Classifier.class)), FeatureGroupPrototype.class)), 
      this.scope_Classifier(context, reference));
  }

  public IScope scope_PortSpecification_classifier(final Element context, final EReference reference) {
    return this.scope_Classifier(context, reference);
  }

  public IScope scope_AccessSpecification_classifier(final Element context, final EReference reference) {
    return this.scope_Classifier(context, reference);
  }

  public SimpleScope scope_FeaturePrototypeReference_prototype(final Classifier context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<FeaturePrototype>filterRefined(Iterables.<FeaturePrototype>filter(Aadl2ScopeProvider.allPrototypes(context), FeaturePrototype.class)));
  }

  public SimpleScope scope_ComponentPrototypeActual_subcomponentType(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<SubcomponentType>filterRefined(Iterables.<SubcomponentType>filter(Aadl2ScopeProvider.allPrototypes(EcoreUtil2.<Classifier>getContainerOfType(context, Classifier.class)), SubcomponentType.class)), 
      this.scope_Classifier(context, reference));
  }

  /**
   * Reference is from AbstractSubcomponent, SystemSubcomponent, ProcessSubcomponent, ThreadGroupSubcomponent,
   * ThreadSubcomponent, SubprogramSubcomponent, SubprogramGroupSubcomponent, ProcessorSubcomponent,
   * VirtualProcessorSubcomponent, DeviceSubcomponent, MemorySubcomponent, BusSubcomponent,
   * VirtualBusSubcomponent, and DataSubcomponent in Aadl2.xtext
   */
  public IScope scope_Subcomponent_refined(final ComponentImplementation context, final EReference reference) {
    IScope _elvis = null;
    ComponentImplementation _extended = context.getExtended();
    EList<Subcomponent> _allSubcomponents = null;
    if (_extended!=null) {
      _allSubcomponents=_extended.getAllSubcomponents();
    }
    Iterable<Subcomponent> _filterRefined = null;
    if (_allSubcomponents!=null) {
      _filterRefined=PropertiesScopeProvider.<Subcomponent>filterRefined(_allSubcomponents);
    }
    SimpleScope _scopeFor = null;
    if (_filterRefined!=null) {
      _scopeFor=PropertiesScopeProvider.scopeFor(_filterRefined);
    }
    if (_scopeFor != null) {
      _elvis = _scopeFor;
    } else {
      _elvis = IScope.NULLSCOPE;
    }
    return _elvis;
  }

  public SimpleScope scope_AbstractSubcomponent_abstractSubcomponentType(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<AbstractSubcomponentType>filterRefined(Iterables.<AbstractSubcomponentType>filter(EcoreUtil2.<ComponentImplementation>getContainerOfType(context, ComponentImplementation.class).getAllPrototypes(), AbstractSubcomponentType.class)), this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_SystemSubcomponent_systemSubcomponentType(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<SystemSubcomponentType>filterRefined(Iterables.<SystemSubcomponentType>filter(EcoreUtil2.<ComponentImplementation>getContainerOfType(context, ComponentImplementation.class).getAllPrototypes(), SystemSubcomponentType.class)), this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_ProcessSubcomponent_processSubcomponentType(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<ProcessSubcomponentType>filterRefined(Iterables.<ProcessSubcomponentType>filter(EcoreUtil2.<ComponentImplementation>getContainerOfType(context, ComponentImplementation.class).getAllPrototypes(), ProcessSubcomponentType.class)), this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_ThreadGroupSubcomponent_threadGroupSubcomponentType(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<ThreadGroupSubcomponentType>filterRefined(Iterables.<ThreadGroupSubcomponentType>filter(EcoreUtil2.<ComponentImplementation>getContainerOfType(context, ComponentImplementation.class).getAllPrototypes(), ThreadGroupSubcomponentType.class)), this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_ThreadSubcomponent_threadSubcomponentType(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<ThreadSubcomponentType>filterRefined(Iterables.<ThreadSubcomponentType>filter(EcoreUtil2.<ComponentImplementation>getContainerOfType(context, ComponentImplementation.class).getAllPrototypes(), ThreadSubcomponentType.class)), this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_SubprogramSubcomponent_subprogramSubcomponentType(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<SubprogramSubcomponentType>filterRefined(Iterables.<SubprogramSubcomponentType>filter(EcoreUtil2.<ComponentImplementation>getContainerOfType(context, ComponentImplementation.class).getAllPrototypes(), SubprogramSubcomponentType.class)), this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_SubprogramGroupSubcomponent_subprogramGroupSubcomponentType(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<SubprogramGroupSubcomponentType>filterRefined(Iterables.<SubprogramGroupSubcomponentType>filter(EcoreUtil2.<ComponentImplementation>getContainerOfType(context, ComponentImplementation.class).getAllPrototypes(), SubprogramGroupSubcomponentType.class)), this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_ProcessorSubcomponent_processorSubcomponentType(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<ProcessorSubcomponentType>filterRefined(Iterables.<ProcessorSubcomponentType>filter(EcoreUtil2.<ComponentImplementation>getContainerOfType(context, ComponentImplementation.class).getAllPrototypes(), ProcessorSubcomponentType.class)), this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_VirtualProcessorSubcomponent_virtualProcessorSubcomponentType(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<VirtualProcessorSubcomponentType>filterRefined(Iterables.<VirtualProcessorSubcomponentType>filter(EcoreUtil2.<ComponentImplementation>getContainerOfType(context, ComponentImplementation.class).getAllPrototypes(), VirtualProcessorSubcomponentType.class)), this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_DeviceSubcomponent_deviceSubcomponentType(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<DeviceSubcomponentType>filterRefined(Iterables.<DeviceSubcomponentType>filter(EcoreUtil2.<ComponentImplementation>getContainerOfType(context, ComponentImplementation.class).getAllPrototypes(), DeviceSubcomponentType.class)), this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_MemorySubcomponent_memorySubcomponentType(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<MemorySubcomponentType>filterRefined(Iterables.<MemorySubcomponentType>filter(EcoreUtil2.<ComponentImplementation>getContainerOfType(context, ComponentImplementation.class).getAllPrototypes(), MemorySubcomponentType.class)), this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_BusSubcomponent_busSubcomponentType(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<BusSubcomponentType>filterRefined(Iterables.<BusSubcomponentType>filter(EcoreUtil2.<ComponentImplementation>getContainerOfType(context, ComponentImplementation.class).getAllPrototypes(), BusSubcomponentType.class)), this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_VirtualBusSubcomponent_virtualBusSubcomponentType(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<VirtualBusSubcomponentType>filterRefined(Iterables.<VirtualBusSubcomponentType>filter(EcoreUtil2.<ComponentImplementation>getContainerOfType(context, ComponentImplementation.class).getAllPrototypes(), VirtualBusSubcomponentType.class)), this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_DataSubcomponent_dataSubcomponentType(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<DataSubcomponentType>filterRefined(Iterables.<DataSubcomponentType>filter(EcoreUtil2.<ComponentImplementation>getContainerOfType(context, ComponentImplementation.class).getAllPrototypes(), DataSubcomponentType.class)), this.scope_Classifier(context, reference));
  }

  public IScope scope_Feature_refined(final Classifier context, final EReference reference) {
    IScope _elvis = null;
    Classifier _extended = context.getExtended();
    EList<Feature> _allFeatures = null;
    if (_extended!=null) {
      _allFeatures=_extended.getAllFeatures();
    }
    Iterable<Feature> _filterRefined = null;
    if (_allFeatures!=null) {
      _filterRefined=PropertiesScopeProvider.<Feature>filterRefined(_allFeatures);
    }
    SimpleScope _scopeFor = null;
    if (_filterRefined!=null) {
      _scopeFor=PropertiesScopeProvider.scopeFor(_filterRefined);
    }
    if (_scopeFor != null) {
      _elvis = _scopeFor;
    } else {
      _elvis = IScope.NULLSCOPE;
    }
    return _elvis;
  }

  public SimpleScope scope_DataPort_dataFeatureClassifier(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<DataSubcomponentType>filterRefined(Iterables.<DataSubcomponentType>filter(Aadl2ScopeProvider.allPrototypes(EcoreUtil2.<Classifier>getContainerOfType(context, Classifier.class)), DataSubcomponentType.class)), 
      this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_EventDataPort_dataFeatureClassifier(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<DataSubcomponentType>filterRefined(Iterables.<DataSubcomponentType>filter(Aadl2ScopeProvider.allPrototypes(EcoreUtil2.<Classifier>getContainerOfType(context, Classifier.class)), DataSubcomponentType.class)), 
      this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_FeatureGroup_featureType(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<FeatureType>filterRefined(Iterables.<FeatureType>filter(Aadl2ScopeProvider.allPrototypes(EcoreUtil2.<Classifier>getContainerOfType(context, Classifier.class)), FeatureType.class)), 
      this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_Parameter_dataFeatureClassifier(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<DataSubcomponentType>filterRefined(Iterables.<DataSubcomponentType>filter(Aadl2ScopeProvider.allPrototypes(EcoreUtil2.<Classifier>getContainerOfType(context, Classifier.class)), DataSubcomponentType.class)), 
      this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_SubprogramAccess_subprogramFeatureClassifier(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<SubprogramSubcomponentType>filterRefined(Iterables.<SubprogramSubcomponentType>filter(Aadl2ScopeProvider.allPrototypes(EcoreUtil2.<Classifier>getContainerOfType(context, Classifier.class)), SubprogramSubcomponentType.class)), 
      this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_SubprogramGroupAccess_subprogramGroupFeatureClassifier(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<SubprogramGroupSubcomponentType>filterRefined(Iterables.<SubprogramGroupSubcomponentType>filter(Aadl2ScopeProvider.allPrototypes(EcoreUtil2.<Classifier>getContainerOfType(context, Classifier.class)), SubprogramGroupSubcomponentType.class)), this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_BusAccess_busFeatureClassifier(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<BusFeatureClassifier>filterRefined(Iterables.<BusFeatureClassifier>filter(Aadl2ScopeProvider.allPrototypes(EcoreUtil2.<Classifier>getContainerOfType(context, Classifier.class)), BusFeatureClassifier.class)), 
      this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_DataAccess_dataFeatureClassifier(final Element context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<DataSubcomponentType>filterRefined(Iterables.<DataSubcomponentType>filter(Aadl2ScopeProvider.allPrototypes(EcoreUtil2.<Classifier>getContainerOfType(context, Classifier.class)), DataSubcomponentType.class)), 
      this.scope_Classifier(context, reference));
  }

  public SimpleScope scope_AbstractFeature_featurePrototype(final Classifier context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<FeaturePrototype>filterRefined(Iterables.<FeaturePrototype>filter(Aadl2ScopeProvider.allPrototypes(context), FeaturePrototype.class)));
  }

  public IScope scope_EventDataSource_dataClassifier(final Element context, final EReference reference) {
    return this.scope_Classifier(context, reference);
  }

  public IScope scope_PortProxy_dataClassifier(final Element context, final EReference reference) {
    return this.scope_Classifier(context, reference);
  }

  public IScope scope_SubprogramProxy_subprogramClassifier(final Element context, final EReference reference) {
    return this.scope_Classifier(context, reference);
  }

  public SimpleScope scope_ConnectedElement_context(final ComponentImplementation context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<Context>filterRefined(Aadl2ScopeProvider.allContexts(context)));
  }

  public IScope scope_ConnectedElement_connectionEnd(final ConnectedElement context, final EReference reference) {
    IScope _xblockexpression = null;
    {
      final Classifier classifier = EcoreUtil2.<Classifier>getContainerOfType(context, Classifier.class);
      final EObject previousConnectedElement = context.eContainer();
      IScope _xifexpression = null;
      if ((previousConnectedElement instanceof ConnectedElement)) {
        IScope _xblockexpression_1 = null;
        {
          final ConnectionEnd current = context.getConnectionEnd();
          IScope _xifexpression_1 = null;
          if ((current instanceof Context)) {
            final Function1<Classifier, Iterable<? extends EObject>> _function = (Classifier it) -> {
              return PropertiesScopeProvider.<ConnectionEnd>filterRefined(Aadl2ScopeProvider.allConnectionEnds(it));
            };
            _xifexpression_1 = Aadl2ScopeProvider.scopeForElementsOfContext(((Context)current), classifier, _function);
          } else {
            _xifexpression_1 = IScope.NULLSCOPE;
          }
          _xblockexpression_1 = _xifexpression_1;
        }
        _xifexpression = _xblockexpression_1;
      } else {
        IScope _xifexpression_1 = null;
        Context _context = context.getContext();
        boolean _tripleEquals = (_context == null);
        if (_tripleEquals) {
          _xifexpression_1 = PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<ConnectionEnd>filterRefined(Aadl2ScopeProvider.allConnectionEnds(classifier)));
        } else {
          IScope _xifexpression_2 = null;
          Context _context_1 = context.getContext();
          boolean _tripleNotEquals = (_context_1 != null);
          if (_tripleNotEquals) {
            final Function1<Classifier, Iterable<? extends EObject>> _function = (Classifier it) -> {
              return PropertiesScopeProvider.<ConnectionEnd>filterRefined(Aadl2ScopeProvider.allConnectionEnds(it));
            };
            _xifexpression_2 = Aadl2ScopeProvider.scopeForElementsOfContext(context.getContext(), classifier, _function);
          } else {
            _xifexpression_2 = IScope.NULLSCOPE;
          }
          _xifexpression_1 = _xifexpression_2;
        }
        _xifexpression = _xifexpression_1;
      }
      _xblockexpression = _xifexpression;
    }
    return _xblockexpression;
  }

  public IScope scope_Connection_refined(final ComponentImplementation context, final EReference reference) {
    IScope _elvis = null;
    ComponentImplementation _extended = context.getExtended();
    EList<Connection> _allConnections = null;
    if (_extended!=null) {
      _allConnections=_extended.getAllConnections();
    }
    Iterable<Connection> _filterRefined = null;
    if (_allConnections!=null) {
      _filterRefined=PropertiesScopeProvider.<Connection>filterRefined(_allConnections);
    }
    SimpleScope _scopeFor = null;
    if (_filterRefined!=null) {
      _scopeFor=PropertiesScopeProvider.scopeFor(_filterRefined);
    }
    if (_scopeFor != null) {
      _elvis = _scopeFor;
    } else {
      _elvis = IScope.NULLSCOPE;
    }
    return _elvis;
  }

  /**
   * Reference is from PortConnection, AccessConnection, FeatureGroupConnection, FeatureConnection, ParameterConnection, FlowSpecification,
   * FlowImplementation, and EndToEndFlow in Aadl2.xtext
   */
  public SimpleScope scope_ModalPath_inModeOrTransition(final ComponentClassifier context, final EReference reference) {
    EList<Mode> _allModes = context.getAllModes();
    EList<ModeTransition> _allModeTransitions = context.getAllModeTransitions();
    return PropertiesScopeProvider.scopeFor(Iterables.<ModeFeature>concat(_allModes, _allModeTransitions));
  }

  public SimpleScope scope_FlowEnd_feature(final Flow context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<Feature>filterRefined(EcoreUtil2.<Classifier>getContainerOfType(context, Classifier.class).getAllFeatures()));
  }

  /**
   * Reference is from FlowEnd in Aadl2.xtext
   */
  public IScope scope_FlowEnd_feature(final FlowEnd end, final EReference reference) {
    IScope _xblockexpression = null;
    {
      final FlowEnd prev = end.getContext();
      IScope _xifexpression = null;
      if ((prev == null)) {
        _xifexpression = PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<Feature>filterRefined(EcoreUtil2.<Classifier>getContainerOfType(end, Classifier.class).getAllFeatures()));
      } else {
        IScope _xblockexpression_1 = null;
        {
          final Feature feature = prev.getFeature();
          Classifier classifier = feature.getAllClassifier();
          if ((classifier == null)) {
            Classifier _switchResult = null;
            boolean _matched = false;
            if (feature instanceof FeatureGroup) {
              _matched=true;
              FeatureGroupType _xifexpression_1 = null;
              FeatureGroupPrototype _featureGroupPrototype = ((FeatureGroup)feature).getFeatureGroupPrototype();
              boolean _tripleNotEquals = (_featureGroupPrototype != null);
              if (_tripleNotEquals) {
                _xifexpression_1 = ((FeatureGroup)feature).getFeatureGroupPrototype().getConstrainingFeatureGroupType();
              }
              _switchResult = _xifexpression_1;
            }
            if (!_matched) {
              if (feature instanceof Port) {
                _matched=true;
                ComponentClassifier _xifexpression_1 = null;
                ComponentPrototype _prototype = ((Port)feature).getPrototype();
                boolean _tripleNotEquals = (_prototype != null);
                if (_tripleNotEquals) {
                  _xifexpression_1 = ((Port)feature).getPrototype().getConstrainingClassifier();
                }
                _switchResult = _xifexpression_1;
              }
            }
            if (!_matched) {
              _switchResult = null;
            }
            classifier = _switchResult;
          }
          IScope _xifexpression_1 = null;
          if ((classifier == null)) {
            _xifexpression_1 = IScope.NULLSCOPE;
          } else {
            _xifexpression_1 = PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<Feature>filterRefined(classifier.getAllFeatures()));
          }
          _xblockexpression_1 = _xifexpression_1;
        }
        _xifexpression = _xblockexpression_1;
      }
      _xblockexpression = _xifexpression;
    }
    return _xblockexpression;
  }

  public IScope scope_FlowSpecification_refined(final ComponentType context, final EReference reference) {
    IScope _elvis = null;
    ComponentType _extended = context.getExtended();
    EList<FlowSpecification> _allFlowSpecifications = null;
    if (_extended!=null) {
      _allFlowSpecifications=_extended.getAllFlowSpecifications();
    }
    Iterable<FlowSpecification> _filterRefined = null;
    if (_allFlowSpecifications!=null) {
      _filterRefined=PropertiesScopeProvider.<FlowSpecification>filterRefined(_allFlowSpecifications);
    }
    SimpleScope _scopeFor = null;
    if (_filterRefined!=null) {
      _scopeFor=PropertiesScopeProvider.scopeFor(_filterRefined);
    }
    if (_scopeFor != null) {
      _elvis = _scopeFor;
    } else {
      _elvis = IScope.NULLSCOPE;
    }
    return _elvis;
  }

  public IScope scope_FlowImplementation_specification(final ComponentImplementation context, final EReference reference) {
    IScope _elvis = null;
    ComponentType _type = context.getType();
    EList<FlowSpecification> _allFlowSpecifications = null;
    if (_type!=null) {
      _allFlowSpecifications=_type.getAllFlowSpecifications();
    }
    Iterable<FlowSpecification> _filterRefined = null;
    if (_allFlowSpecifications!=null) {
      _filterRefined=PropertiesScopeProvider.<FlowSpecification>filterRefined(_allFlowSpecifications);
    }
    SimpleScope _scopeFor = null;
    if (_filterRefined!=null) {
      _scopeFor=PropertiesScopeProvider.scopeFor(_filterRefined);
    }
    if (_scopeFor != null) {
      _elvis = _scopeFor;
    } else {
      _elvis = IScope.NULLSCOPE;
    }
    return _elvis;
  }

  public IScope scope_EndToEndFlow_refined(final ComponentImplementation context, final EReference reference) {
    IScope _elvis = null;
    ComponentImplementation _extended = context.getExtended();
    EList<EndToEndFlow> _allEndToEndFlows = null;
    if (_extended!=null) {
      _allEndToEndFlows=_extended.getAllEndToEndFlows();
    }
    Iterable<EndToEndFlow> _filterRefined = null;
    if (_allEndToEndFlows!=null) {
      _filterRefined=PropertiesScopeProvider.<EndToEndFlow>filterRefined(_allEndToEndFlows);
    }
    SimpleScope _scopeFor = null;
    if (_filterRefined!=null) {
      _scopeFor=PropertiesScopeProvider.scopeFor(_filterRefined);
    }
    if (_scopeFor != null) {
      _elvis = _scopeFor;
    } else {
      _elvis = IScope.NULLSCOPE;
    }
    return _elvis;
  }

  public SimpleScope scope_FlowSegment_context(final ComponentImplementation context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<Context>filterRefined(Aadl2ScopeProvider.allContexts(context)));
  }

  /**
   * Reference is from SubcomponentFlow and ConnectionFlow in Aadl2.xtext
   * There are two methods for this scope because we can be given one of two possible context objects based upon the form of the FlowSegment.  When the
   * FlowSegment is a single identifier, e.g. "conn1", then the passed context is a FlowImplementation.  In this case, we know that the FlowSegment's Context
   * is null even though we can't access it and check it here.  When the FlowSegment is a qualified reference, e.g. "subcomponent1.flowpath1", then the
   * passed context is a FlowSegment, thus calling the other scope method.
   */
  public SimpleScope scope_FlowSegment_flowElement(final FlowImplementation context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<FlowElement>filterRefined(Aadl2ScopeProvider.allFlowElements(EcoreUtil2.<Classifier>getContainerOfType(context, Classifier.class))));
  }

  /**
   * Reference is from SubcomponentFlow in Aadl2.xtext
   * There are two methods for this scope because we can be given one of two possible context objects based upon the form of the FlowSegment.  When the
   * FlowSegment is a qualified reference, e.g. "subcomponent1.flowpath1", then the passed context is a FlowSegment and we can access and check the
   * FlowSegment's Context object.
   */
  public IScope scope_FlowSegment_flowElement(final FlowSegment context, final EReference reference) {
    IScope _elvis = null;
    Context _context = context.getContext();
    IScope _scopeForElementsOfContext = null;
    if (_context!=null) {
      final Function1<Classifier, Iterable<? extends EObject>> _function = (Classifier it) -> {
        return PropertiesScopeProvider.<FlowElement>filterRefined(Aadl2ScopeProvider.allFlowElements(it));
      };
      _scopeForElementsOfContext=Aadl2ScopeProvider.scopeForElementsOfContext(_context, EcoreUtil2.<Classifier>getContainerOfType(context, Classifier.class), _function);
    }
    if (_scopeForElementsOfContext != null) {
      _elvis = _scopeForElementsOfContext;
    } else {
      Element _owner = context.getOwner();
      SimpleScope _scope_FlowSegment_flowElement = this.scope_FlowSegment_flowElement(((FlowImplementation) _owner), reference);
      _elvis = _scope_FlowSegment_flowElement;
    }
    return _elvis;
  }

  public SimpleScope scope_EndToEndFlowSegment_context(final ComponentImplementation context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<Context>filterRefined(Aadl2ScopeProvider.allContexts(context)));
  }

  /**
   * Reference is from ETESubcomponentFlow and ETEConnectionFlow in Aadl2.xtext
   * There are two methods for this scope because we can be given one of two possible context objects based upon the form of the EndToEndFlowSegment.  When
   * the EndToEndFlowSegment is a single identifier, e.g. "conn1", then the passed context is an EndToEndFlow.  In this case, we know that the
   * EndToEndFlowSegment's Context is null even though we can't access it and check it here.  When the EndToEndFlowSegment is a qualified reference, e.g.
   * "subcomponent1.flowpath1", then the passed context is an EndToEndFlowSegment, thus calling the other scope method.
   */
  public SimpleScope scope_EndToEndFlowSegment_flowElement(final EndToEndFlow context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<EndToEndFlowElement>filterRefined(Aadl2ScopeProvider.allEndToEndFlowElements(EcoreUtil2.<Classifier>getContainerOfType(context, Classifier.class))));
  }

  /**
   * Reference is from ETESubcomponentFlow in Aadl2.xtext
   * There are two methods for this scope because we can be given one of two possible context objects based upon the form of the EndToEndFlowSegment.  When
   * the EndToEndFlowSegment is a qualified reference, e.g. "subcomponent1.flowpath1", then the passed context is an EndToEndFlowSegment and we can access
   * and check the EndToEndFlowSegment's Context object.
   */
  public IScope scope_EndToEndFlowSegment_flowElement(final EndToEndFlowSegment context, final EReference reference) {
    IScope _elvis = null;
    Context _context = context.getContext();
    IScope _scopeForElementsOfContext = null;
    if (_context!=null) {
      final Function1<Classifier, Iterable<? extends EObject>> _function = (Classifier it) -> {
        return PropertiesScopeProvider.<EndToEndFlowElement>filterRefined(Aadl2ScopeProvider.allEndToEndFlowElements(it));
      };
      _scopeForElementsOfContext=Aadl2ScopeProvider.scopeForElementsOfContext(_context, EcoreUtil2.<Classifier>getContainerOfType(context, Classifier.class), _function);
    }
    if (_scopeForElementsOfContext != null) {
      _elvis = _scopeForElementsOfContext;
    } else {
      Element _owner = context.getOwner();
      SimpleScope _scope_EndToEndFlowSegment_flowElement = this.scope_EndToEndFlowSegment_flowElement(((EndToEndFlow) _owner), reference);
      _elvis = _scope_EndToEndFlowSegment_flowElement;
    }
    return _elvis;
  }

  public SimpleScope scope_ModeTransition_source(final ComponentClassifier context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(context.getAllModes());
  }

  public SimpleScope scope_ModeTransition_destination(final ComponentClassifier context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(context.getAllModes());
  }

  public SimpleScope scope_ModeTransitionTrigger_context(final ComponentClassifier context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<Context>filterRefined(Aadl2ScopeProvider.allContexts(context)));
  }

  /**
   * Reference is from Trigger in Aadl2.xtext
   * There are two methods for this scope because we can be given one of two possible context objects based upon the form of the ModeTransitionTrigger.  When
   * the ModeTransitionTrigger is a single identifier, e.g. "eventport1", then the passed context is a ModeTransition.  In this case, we know that the
   * ModeTransitionTrigger's Context is null even though we can't access it and check it here.  When the ModeTransitionTrigger is a qualified reference, e.g.
   * "featuregroup1.eventport1", then the passed context is a ModeTransitionTrigger, thus calling the other scope method.
   */
  public SimpleScope scope_ModeTransitionTrigger_triggerPort(final ModeTransition context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(PropertiesScopeProvider.<TriggerPort>filterRefined(Aadl2ScopeProvider.allTriggerPorts(EcoreUtil2.<Classifier>getContainerOfType(context, Classifier.class))));
  }

  /**
   * Reference is from Trigger in Aadl2.xtext
   * There are two methods for this scope because we can be given one of two possible context objects based upon the form of the ModeTransitionTrigger.  When
   * the ModeTransitionTrigger is a qualified reference, e.g. "featuregroup1.eventport1", then the passed context is a ModeTransitionTrigger and we can
   * access and check the ModeTransitionTrigger's Context object.
   */
  public IScope scope_ModeTransitionTrigger_triggerPort(final ModeTransitionTrigger context, final EReference reference) {
    IScope _elvis = null;
    Context _context = context.getContext();
    IScope _scopeForElementsOfContext = null;
    if (_context!=null) {
      final Function1<Classifier, Iterable<? extends EObject>> _function = (Classifier it) -> {
        return PropertiesScopeProvider.<TriggerPort>filterRefined(Aadl2ScopeProvider.allTriggerPorts(it));
      };
      _scopeForElementsOfContext=Aadl2ScopeProvider.scopeForElementsOfContext(_context, EcoreUtil2.<Classifier>getContainerOfType(context, Classifier.class), _function);
    }
    if (_scopeForElementsOfContext != null) {
      _elvis = _scopeForElementsOfContext;
    } else {
      Element _owner = context.getOwner();
      SimpleScope _scope_ModeTransitionTrigger_triggerPort = this.scope_ModeTransitionTrigger_triggerPort(((ModeTransition) _owner), reference);
      _elvis = _scope_ModeTransitionTrigger_triggerPort;
    }
    return _elvis;
  }

  public SimpleScope scope_ModeBinding_parentMode(final ComponentImplementation context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(context.getAllModes());
  }

  public IScope scope_ModeBinding_derivedMode(final Subcomponent context, final EReference reference) {
    IScope _elvis = null;
    ComponentClassifier _switchResult = null;
    SubcomponentType _allSubcomponentType = PropertiesScopeProvider.allSubcomponentType(context);
    final SubcomponentType subcomponentType = _allSubcomponentType;
    boolean _matched = false;
    if (subcomponentType instanceof ComponentClassifier) {
      _matched=true;
      _switchResult = ((ComponentClassifier)subcomponentType);
    }
    if (!_matched) {
      if (subcomponentType instanceof ComponentPrototype) {
        _matched=true;
        _switchResult = Aadl2ScopeProvider.findClassifierForComponentPrototype(((ComponentPrototype)subcomponentType), EcoreUtil2.<Classifier>getContainerOfType(context, Classifier.class));
      }
    }
    EList<Mode> _allModes = null;
    if (_switchResult!=null) {
      _allModes=_switchResult.getAllModes();
    }
    SimpleScope _scopeFor = null;
    if (_allModes!=null) {
      _scopeFor=PropertiesScopeProvider.scopeFor(_allModes);
    }
    if (_scopeFor != null) {
      _elvis = _scopeFor;
    } else {
      _elvis = IScope.NULLSCOPE;
    }
    return _elvis;
  }

  public SimpleScope scope_UnitLiteral_baseUnit(final UnitsType context, final EReference reference) {
    return PropertiesScopeProvider.scopeFor(context.getOwnedLiterals());
  }

  public SimpleScope scope_NumberType_referencedUnitsType(final Element context, final EReference reference) {
    final Function1<IEObjectDescription, Boolean> _function = (IEObjectDescription it) -> {
      return Boolean.valueOf((Objects.equal(it.getName(), it.getQualifiedName()) || AadlUtil.isPredeclaredPropertySet(it.getQualifiedName().getFirstSegment())));
    };
    Iterable<IEObjectDescription> _filter = IterableExtensions.<IEObjectDescription>filter(this.delegateGetScope(context, reference).getAllElements(), _function);
    return new SimpleScope(_filter, true);
  }

  public SimpleScope scope_RangeType_numberType(final Element context, final EReference reference) {
    final Function1<IEObjectDescription, Boolean> _function = (IEObjectDescription it) -> {
      return Boolean.valueOf((Objects.equal(it.getName(), it.getQualifiedName()) || AadlUtil.isPredeclaredPropertySet(it.getQualifiedName().getFirstSegment())));
    };
    Iterable<IEObjectDescription> _filter = IterableExtensions.<IEObjectDescription>filter(this.delegateGetScope(context, reference).getAllElements(), _function);
    return new SimpleScope(_filter, true);
  }

  public SimpleScope scope_BasicProperty_referencedPropertyType(final Element context, final EReference reference) {
    final Function1<IEObjectDescription, Boolean> _function = (IEObjectDescription it) -> {
      return Boolean.valueOf((Objects.equal(it.getName(), it.getQualifiedName()) || AadlUtil.isPredeclaredPropertySet(it.getQualifiedName().getFirstSegment())));
    };
    Iterable<IEObjectDescription> _filter = IterableExtensions.<IEObjectDescription>filter(this.delegateGetScope(context, reference).getAllElements(), _function);
    return new SimpleScope(_filter, true);
  }

  public SimpleScope scope_ListType_referencedElementType(final Element context, final EReference reference) {
    final Function1<IEObjectDescription, Boolean> _function = (IEObjectDescription it) -> {
      return Boolean.valueOf((Objects.equal(it.getName(), it.getQualifiedName()) || AadlUtil.isPredeclaredPropertySet(it.getQualifiedName().getFirstSegment())));
    };
    Iterable<IEObjectDescription> _filter = IterableExtensions.<IEObjectDescription>filter(this.delegateGetScope(context, reference).getAllElements(), _function);
    return new SimpleScope(_filter, true);
  }

  public SimpleScope scope_PropertyConstant_referencedPropertyType(final Element context, final EReference reference) {
    final Function1<IEObjectDescription, Boolean> _function = (IEObjectDescription it) -> {
      return Boolean.valueOf((Objects.equal(it.getName(), it.getQualifiedName()) || AadlUtil.isPredeclaredPropertySet(it.getQualifiedName().getFirstSegment())));
    };
    Iterable<IEObjectDescription> _filter = IterableExtensions.<IEObjectDescription>filter(this.delegateGetScope(context, reference).getAllElements(), _function);
    return new SimpleScope(_filter, true);
  }

  private static EList<Prototype> allPrototypes(final Classifier classifier) {
    EList<Prototype> _switchResult = null;
    boolean _matched = false;
    if (classifier instanceof ComponentClassifier) {
      _matched=true;
      _switchResult = ((ComponentClassifier)classifier).getAllPrototypes();
    }
    if (!_matched) {
      if (classifier instanceof FeatureGroupType) {
        _matched=true;
        _switchResult = ((FeatureGroupType)classifier).getAllPrototypes();
      }
    }
    return _switchResult;
  }

  private static ArrayList<Context> allContexts(final ComponentClassifier classifier) {
    ArrayList<Context> _xblockexpression = null;
    {
      final ArrayList<Context> validElements = CollectionLiterals.<Context>newArrayList();
      Iterables.<Context>addAll(validElements, Iterables.<Context>filter(classifier.getAllFeatures(), Context.class));
      if ((classifier instanceof ComponentImplementation)) {
        validElements.addAll(((ComponentImplementation)classifier).getAllSubcomponents());
        if ((classifier instanceof BehavioredImplementation)) {
          validElements.addAll(PropertiesScopeProvider.allSubprogramCalls(((BehavioredImplementation)classifier)));
        }
      }
      _xblockexpression = validElements;
    }
    return _xblockexpression;
  }

  /**
   * @since 2.0
   */
  protected static ArrayList<ConnectionEnd> allConnectionEnds(final Classifier classifier) {
    ArrayList<ConnectionEnd> _xblockexpression = null;
    {
      final ArrayList<ConnectionEnd> connectionEnds = CollectionLiterals.<ConnectionEnd>newArrayList();
      connectionEnds.addAll(classifier.getAllFeatures());
      if ((classifier instanceof ComponentImplementation)) {
        Iterables.<ConnectionEnd>addAll(connectionEnds, Iterables.<ConnectionEnd>filter(((ComponentImplementation)classifier).getAllSubcomponents(), ConnectionEnd.class));
        connectionEnds.addAll(((ComponentImplementation)classifier).getAllSubprogramProxies());
        connectionEnds.addAll(((ComponentImplementation)classifier).getAllPortProxies());
        connectionEnds.addAll(((ComponentImplementation)classifier).getAllInternalFeatures());
      }
      _xblockexpression = connectionEnds;
    }
    return _xblockexpression;
  }

  private static ArrayList<FlowElement> allFlowElements(final Classifier classifier) {
    ArrayList<FlowElement> _xblockexpression = null;
    {
      final ArrayList<FlowElement> flowElements = CollectionLiterals.<FlowElement>newArrayList();
      Iterables.<FlowElement>addAll(flowElements, Iterables.<DataAccess>filter(classifier.getAllFeatures(), DataAccess.class));
      Iterables.<FlowElement>addAll(flowElements, Iterables.<SubprogramAccess>filter(classifier.getAllFeatures(), SubprogramAccess.class));
      boolean _matched = false;
      if (classifier instanceof ComponentType) {
        _matched=true;
        flowElements.addAll(((ComponentType)classifier).getAllFlowSpecifications());
      }
      if (!_matched) {
        if (classifier instanceof ComponentImplementation) {
          _matched=true;
          flowElements.addAll(((ComponentImplementation)classifier).getType().getAllFlowSpecifications());
          flowElements.addAll(((ComponentImplementation)classifier).getAllConnections());
          flowElements.addAll(((ComponentImplementation)classifier).getAllSubcomponents());
        }
      }
      _xblockexpression = flowElements;
    }
    return _xblockexpression;
  }

  private static ArrayList<EndToEndFlowElement> allEndToEndFlowElements(final Classifier classifier) {
    ArrayList<EndToEndFlowElement> _xblockexpression = null;
    {
      final ArrayList<EndToEndFlowElement> flowElements = CollectionLiterals.<EndToEndFlowElement>newArrayList();
      flowElements.addAll(Aadl2ScopeProvider.allFlowElements(classifier));
      if ((classifier instanceof ComponentImplementation)) {
        flowElements.addAll(((ComponentImplementation)classifier).getAllEndToEndFlows());
      }
      _xblockexpression = flowElements;
    }
    return _xblockexpression;
  }

  private static ArrayList<TriggerPort> allTriggerPorts(final Classifier classifier) {
    ArrayList<TriggerPort> _xblockexpression = null;
    {
      final ArrayList<TriggerPort> triggerPorts = CollectionLiterals.<TriggerPort>newArrayList();
      Iterables.<TriggerPort>addAll(triggerPorts, Iterables.<TriggerPort>filter(classifier.getAllFeatures(), TriggerPort.class));
      if ((classifier instanceof ComponentImplementation)) {
        triggerPorts.addAll(((ComponentImplementation)classifier).getAllInternalFeatures());
        triggerPorts.addAll(((ComponentImplementation)classifier).getAllPortProxies());
      }
      _xblockexpression = triggerPorts;
    }
    return _xblockexpression;
  }

  private static FeatureGroupType findFeatureGroupTypeForFeatureGroupPrototype(final FeatureGroupPrototype prototype, final Classifier containingClassifier) {
    return PropertiesLinkingService.findFeatureGroupTypeForFeatureGroupPrototype(containingClassifier, prototype);
  }

  private static ComponentClassifier findClassifierForComponentPrototype(final ComponentPrototype prototype, final Classifier containingClassifier) {
    return PropertiesLinkingService.findClassifierForComponentPrototype(containingClassifier, prototype);
  }

  private static ComponentClassifier findClassifierForComponentPrototype(final ComponentPrototype prototype, final Classifier classifierPrototypeContext, final Subcomponent subcomponentPrototypeContext) {
    return PropertiesLinkingService.findClassifierForComponentPrototype(classifierPrototypeContext, subcomponentPrototypeContext, prototype);
  }

  /**
   * @since 2.0
   */
  protected static IScope scopeForElementsOfContext(final Context context, final Classifier containingClassifier, @Extension final Function1<? super Classifier, ? extends Iterable<? extends EObject>> validMemberCollector) {
    IScope _xblockexpression = null;
    {
      Classifier _switchResult = null;
      boolean _matched = false;
      if (context instanceof FeatureGroup) {
        _matched=true;
        FeatureGroupType _switchResult_1 = null;
        FeatureType _allFeatureType = PropertiesScopeProvider.allFeatureType(((FeatureGroup)context));
        final FeatureType featureType = _allFeatureType;
        boolean _matched_1 = false;
        if (featureType instanceof FeatureGroupType) {
          _matched_1=true;
          _switchResult_1 = ((FeatureGroupType)featureType);
        }
        if (!_matched_1) {
          if (featureType instanceof FeatureGroupPrototype) {
            _matched_1=true;
            _switchResult_1 = Aadl2ScopeProvider.findFeatureGroupTypeForFeatureGroupPrototype(((FeatureGroupPrototype)featureType), containingClassifier);
          }
        }
        _switchResult = _switchResult_1;
      }
      if (!_matched) {
        if (context instanceof Feature) {
          _matched=true;
          ComponentClassifier _switchResult_1 = null;
          FeatureClassifier _allFeatureClassifier = ((Feature)context).getAllFeatureClassifier();
          final FeatureClassifier featureClassifier = _allFeatureClassifier;
          boolean _matched_1 = false;
          if (featureClassifier instanceof ComponentClassifier) {
            _matched_1=true;
            _switchResult_1 = ((ComponentClassifier)featureClassifier);
          }
          if (!_matched_1) {
            if (featureClassifier instanceof ComponentPrototype) {
              _matched_1=true;
              _switchResult_1 = Aadl2ScopeProvider.findClassifierForComponentPrototype(((ComponentPrototype)featureClassifier), containingClassifier);
            }
          }
          _switchResult = _switchResult_1;
        }
      }
      if (!_matched) {
        if (context instanceof Subcomponent) {
          _matched=true;
          ComponentClassifier _switchResult_1 = null;
          SubcomponentType _allSubcomponentType = PropertiesScopeProvider.allSubcomponentType(((Subcomponent)context));
          final SubcomponentType subcomponentType = _allSubcomponentType;
          boolean _matched_1 = false;
          if (subcomponentType instanceof ComponentClassifier) {
            _matched_1=true;
            _switchResult_1 = ((ComponentClassifier)subcomponentType);
          }
          if (!_matched_1) {
            if (subcomponentType instanceof ComponentPrototype) {
              _matched_1=true;
              _switchResult_1 = Aadl2ScopeProvider.findClassifierForComponentPrototype(((ComponentPrototype)subcomponentType), containingClassifier);
            }
          }
          _switchResult = _switchResult_1;
        }
      }
      if (!_matched) {
        if (context instanceof SubprogramCall) {
          _matched=true;
          ComponentClassifier _switchResult_1 = null;
          CalledSubprogram _calledSubprogram = ((SubprogramCall)context).getCalledSubprogram();
          final CalledSubprogram calledSubprogram = _calledSubprogram;
          boolean _matched_1 = false;
          if (calledSubprogram instanceof ComponentClassifier) {
            _matched_1=true;
            _switchResult_1 = ((ComponentClassifier)calledSubprogram);
          }
          if (!_matched_1) {
            if (calledSubprogram instanceof SubprogramSubcomponent) {
              _matched_1=true;
              ComponentClassifier _switchResult_2 = null;
              SubcomponentType _allSubcomponentType = PropertiesScopeProvider.allSubcomponentType(((Subcomponent)calledSubprogram));
              final SubcomponentType subcomponentType = _allSubcomponentType;
              boolean _matched_2 = false;
              if (subcomponentType instanceof ComponentClassifier) {
                _matched_2=true;
                _switchResult_2 = ((ComponentClassifier)subcomponentType);
              }
              if (!_matched_2) {
                if (subcomponentType instanceof ComponentPrototype) {
                  _matched_2=true;
                  _switchResult_2 = Aadl2ScopeProvider.findClassifierForComponentPrototype(((ComponentPrototype)subcomponentType), containingClassifier);
                }
              }
              _switchResult_1 = _switchResult_2;
            }
          }
          if (!_matched_1) {
            if (calledSubprogram instanceof SubprogramAccess) {
              _matched_1=true;
              ComponentClassifier _switchResult_2 = null;
              FeatureClassifier _allFeatureClassifier = ((SubprogramAccess)calledSubprogram).getAllFeatureClassifier();
              final FeatureClassifier accessFeatureClassifier = _allFeatureClassifier;
              boolean _matched_2 = false;
              if (accessFeatureClassifier instanceof ComponentClassifier) {
                _matched_2=true;
                _switchResult_2 = ((ComponentClassifier)accessFeatureClassifier);
              }
              if (!_matched_2) {
                if (accessFeatureClassifier instanceof ComponentPrototype) {
                  _matched_2=true;
                  ComponentClassifier _switchResult_3 = null;
                  CallContext _context = ((SubprogramCall)context).getContext();
                  final CallContext callContext = _context;
                  boolean _matched_3 = false;
                  if (callContext instanceof ComponentType) {
                    _matched_3=true;
                    _switchResult_3 = Aadl2ScopeProvider.findClassifierForComponentPrototype(((ComponentPrototype)accessFeatureClassifier), ((ComponentType)callContext));
                  }
                  if (!_matched_3) {
                    if (callContext instanceof FeatureGroup) {
                      _matched_3=true;
                      ComponentClassifier _xblockexpression_1 = null;
                      {
                        FeatureGroupType _switchResult_4 = null;
                        FeatureType _allFeatureType = PropertiesScopeProvider.allFeatureType(((FeatureGroup)callContext));
                        final FeatureType callContextFeatureType = _allFeatureType;
                        boolean _matched_4 = false;
                        if (callContextFeatureType instanceof FeatureGroupType) {
                          _matched_4=true;
                          _switchResult_4 = ((FeatureGroupType)callContextFeatureType);
                        }
                        if (!_matched_4) {
                          if (callContextFeatureType instanceof FeatureGroupPrototype) {
                            _matched_4=true;
                            _switchResult_4 = Aadl2ScopeProvider.findFeatureGroupTypeForFeatureGroupPrototype(((FeatureGroupPrototype)callContextFeatureType), containingClassifier);
                          }
                        }
                        final FeatureGroupType prototypeContext = _switchResult_4;
                        ComponentClassifier _xifexpression = null;
                        if ((prototypeContext != null)) {
                          _xifexpression = Aadl2ScopeProvider.findClassifierForComponentPrototype(((ComponentPrototype)accessFeatureClassifier), prototypeContext);
                        }
                        _xblockexpression_1 = _xifexpression;
                      }
                      _switchResult_3 = _xblockexpression_1;
                    }
                  }
                  if (!_matched_3) {
                    if (callContext instanceof SubprogramGroupAccess) {
                      _matched_3=true;
                      ComponentClassifier _xblockexpression_1 = null;
                      {
                        ComponentClassifier _switchResult_4 = null;
                        FeatureClassifier _allFeatureClassifier_1 = ((SubprogramGroupAccess)callContext).getAllFeatureClassifier();
                        final FeatureClassifier callContextFeatureClassifier = _allFeatureClassifier_1;
                        boolean _matched_4 = false;
                        if (callContextFeatureClassifier instanceof ComponentClassifier) {
                          _matched_4=true;
                          _switchResult_4 = ((ComponentClassifier)callContextFeatureClassifier);
                        }
                        if (!_matched_4) {
                          if (callContextFeatureClassifier instanceof ComponentPrototype) {
                            _matched_4=true;
                            _switchResult_4 = Aadl2ScopeProvider.findClassifierForComponentPrototype(((ComponentPrototype)callContextFeatureClassifier), containingClassifier);
                          }
                        }
                        final ComponentClassifier prototypeContext = _switchResult_4;
                        ComponentClassifier _xifexpression = null;
                        if ((prototypeContext != null)) {
                          _xifexpression = Aadl2ScopeProvider.findClassifierForComponentPrototype(((ComponentPrototype)accessFeatureClassifier), prototypeContext);
                        }
                        _xblockexpression_1 = _xifexpression;
                      }
                      _switchResult_3 = _xblockexpression_1;
                    }
                  }
                  if (!_matched_3) {
                    if (callContext instanceof SubprogramGroupSubcomponent) {
                      _matched_3=true;
                      ComponentClassifier _xblockexpression_1 = null;
                      {
                        Subcomponent callContextSubcomponent = ((Subcomponent)callContext);
                        while (((callContextSubcomponent.getSubcomponentType() == null) && 
                          (callContextSubcomponent.getRefined() != null))) {
                          callContextSubcomponent = callContextSubcomponent.getRefined();
                        }
                        ComponentClassifier _switchResult_4 = null;
                        SubcomponentType _subcomponentType = callContextSubcomponent.getSubcomponentType();
                        final SubcomponentType callContextSubcomponentType = _subcomponentType;
                        boolean _matched_4 = false;
                        if (callContextSubcomponentType instanceof ComponentClassifier) {
                          _matched_4=true;
                          ComponentClassifier _xifexpression = null;
                          boolean _isEmpty = callContextSubcomponent.getOwnedPrototypeBindings().isEmpty();
                          if (_isEmpty) {
                            _xifexpression = Aadl2ScopeProvider.findClassifierForComponentPrototype(((ComponentPrototype)accessFeatureClassifier), ((Classifier)callContextSubcomponentType));
                          } else {
                            _xifexpression = Aadl2ScopeProvider.findClassifierForComponentPrototype(((ComponentPrototype)accessFeatureClassifier), ((Classifier)callContextSubcomponentType), callContextSubcomponent);
                          }
                          _switchResult_4 = _xifexpression;
                        }
                        if (!_matched_4) {
                          if (callContextSubcomponentType instanceof ComponentPrototype) {
                            _matched_4=true;
                            ComponentClassifier _xblockexpression_2 = null;
                            {
                              ComponentClassifier prototypeContext = Aadl2ScopeProvider.findClassifierForComponentPrototype(((ComponentPrototype)callContextSubcomponentType), containingClassifier);
                              ComponentClassifier _xifexpression = null;
                              if ((prototypeContext != null)) {
                                _xifexpression = Aadl2ScopeProvider.findClassifierForComponentPrototype(((ComponentPrototype)accessFeatureClassifier), prototypeContext);
                              }
                              _xblockexpression_2 = _xifexpression;
                            }
                            _switchResult_4 = _xblockexpression_2;
                          }
                        }
                        _xblockexpression_1 = _switchResult_4;
                      }
                      _switchResult_3 = _xblockexpression_1;
                    }
                  }
                  if (!_matched_3) {
                    _switchResult_3 = Aadl2ScopeProvider.findClassifierForComponentPrototype(((ComponentPrototype)accessFeatureClassifier), containingClassifier);
                  }
                  _switchResult_2 = _switchResult_3;
                }
              }
              _switchResult_1 = _switchResult_2;
            }
          }
          if (!_matched_1) {
            if (calledSubprogram instanceof ComponentPrototype) {
              _matched_1=true;
              _switchResult_1 = Aadl2ScopeProvider.findClassifierForComponentPrototype(((ComponentPrototype)calledSubprogram), containingClassifier);
            }
          }
          _switchResult = _switchResult_1;
        }
      }
      final Classifier contextClassifier = _switchResult;
      IScope _xifexpression = null;
      if ((contextClassifier != null)) {
        _xifexpression = PropertiesScopeProvider.scopeFor(validMemberCollector.apply(contextClassifier));
      } else {
        _xifexpression = IScope.NULLSCOPE;
      }
      _xblockexpression = _xifexpression;
    }
    return _xblockexpression;
  }
}