Aadl2SerializerScopeProvider.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 java.util.ArrayList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.xtext.scoping.impl.SimpleScope;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.osate.aadl2.Classifier;
import org.osate.aadl2.ConnectedElement;
import org.osate.aadl2.ConnectionEnd;
import org.osate.aadl2.ContainedNamedElement;
import org.osate.aadl2.ContainmentPathElement;
import org.osate.aadl2.Context;
import org.osate.aadl2.Element;
import org.osate.aadl2.NamedElement;
import org.osate.aadl2.PropertyAssociation;
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
 * @since 2.0
 */
@SuppressWarnings("all")
public class Aadl2SerializerScopeProvider extends Aadl2ScopeProvider {
  @Override
  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 previous = ((ConnectedElement)previousConnectedElement).getConnectionEnd();
          IScope _xifexpression_1 = null;
          if ((previous instanceof Context)) {
            final Function1<Classifier, Iterable<? extends EObject>> _function = (Classifier it) -> {
              return PropertiesScopeProvider.<ConnectionEnd>filterRefined(Aadl2ScopeProvider.allConnectionEnds(it));
            };
            _xifexpression_1 = Aadl2ScopeProvider.scopeForElementsOfContext(((Context)previous), 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 {
          final Function1<Classifier, Iterable<? extends EObject>> _function = (Classifier it) -> {
            return PropertiesScopeProvider.<ConnectionEnd>filterRefined(Aadl2ScopeProvider.allConnectionEnds(it));
          };
          _xifexpression_1 = Aadl2ScopeProvider.scopeForElementsOfContext(context.getContext(), classifier, _function);
        }
        _xifexpression = _xifexpression_1;
      }
      _xblockexpression = _xifexpression;
    }
    return _xblockexpression;
  }

  public IScope scope_ContainmentPathElement_namedElement(final ContainmentPathElement context, final EReference reference) {
    IScope _xblockexpression = null;
    {
      final Element previous = context.getOwner();
      IScope _xifexpression = null;
      if ((previous instanceof ContainmentPathElement)) {
        IScope _xblockexpression_1 = null;
        {
          final Classifier namespace = PropertiesScopeProvider.getClassifierForPreviousContainmentPathElement(((ContainmentPathElement)previous));
          IScope _elvis = null;
          ArrayList<NamedElement> _allMembers = null;
          if (namespace!=null) {
            _allMembers=PropertiesScopeProvider.allMembers(namespace);
          }
          Iterable<NamedElement> _filterRefined = null;
          if (_allMembers!=null) {
            _filterRefined=PropertiesScopeProvider.<NamedElement>filterRefined(_allMembers);
          }
          SimpleScope _scopeFor = null;
          if (_filterRefined!=null) {
            _scopeFor=PropertiesScopeProvider.scopeFor(_filterRefined);
          }
          if (_scopeFor != null) {
            _elvis = _scopeFor;
          } else {
            _elvis = IScope.NULLSCOPE;
          }
          _xblockexpression_1 = _elvis;
        }
        _xifexpression = _xblockexpression_1;
      } else {
        _xifexpression = null;
      }
      _xblockexpression = _xifexpression;
    }
    return _xblockexpression;
  }

  public IScope scope_ContainmentPathElement_namedElement(final ContainedNamedElement context, final EReference reference) {
    IScope _xblockexpression = null;
    {
      final PropertyAssociation propertyAssociation = EcoreUtil2.<PropertyAssociation>getContainerOfType(context, PropertyAssociation.class);
      final Classifier namespace = PropertiesScopeProvider.namespaceForPropertyAssociation(propertyAssociation);
      IScope _elvis = null;
      ArrayList<NamedElement> _allMembers = null;
      if (namespace!=null) {
        _allMembers=PropertiesScopeProvider.allMembers(namespace);
      }
      Iterable<NamedElement> _filterRefined = null;
      if (_allMembers!=null) {
        _filterRefined=PropertiesScopeProvider.<NamedElement>filterRefined(_allMembers);
      }
      SimpleScope _scopeFor = null;
      if (_filterRefined!=null) {
        _scopeFor=PropertiesScopeProvider.scopeFor(_filterRefined);
      }
      if (_scopeFor != null) {
        _elvis = _scopeFor;
      } else {
        _elvis = IScope.NULLSCOPE;
      }
      _xblockexpression = _elvis;
    }
    return _xblockexpression;
  }
}