Package org.eclipse.xtext.scoping

Examples of org.eclipse.xtext.scoping.IScope


  // message Person {
  //   optional boolean active = 1 [(code) = 68];
  // }
  @Test public void should_provide_sources_for_custom_field_option() {
    CustomFieldOption option = xtext.find("code", ")", CustomFieldOption.class);
    IScope scope = scopeProvider.scope_OptionSource_target(option.getSource(), reference);
    assertThat(descriptionsIn(scope), containAll("code", "proto.code", "google.proto.code", "com.google.proto.code",
                                                 ".com.google.proto.code",
                                                 "info", "proto.info", "google.proto.info", "com.google.proto.info",
                                                 ".com.google.proto.info"));
  }
View Full Code Here


    Pair<EObject, EClass> clave = new Pair<EObject, EClass>(context, type);
    if (scopecache.containsKey(clave))
      return scopecache.get(clave);

    // Compute the outer scope
    IScope outer = IScope.NULLSCOPE;

    EObject ct = context.eContainer();
    if (ct instanceof Container)
      outer = getScope((Container) ct, type);
    else if (ct instanceof TranslationUnit)
      outer = getFullScope((TranslationUnit) ct, type);

    IScope result = new SimpleScope(outer, getScopedElements(context, type));
    scopecache.put(clave, result);
    return result;
  }
View Full Code Here

   * @return
   * @throws IOException
   */
  public static IScope getFullScope(TranslationUnit trunit, EClass type) throws Exception {

    IScope outer = IScope.NULLSCOPE;

    Collection<TranslationUnit> loaded = new LinkedList<TranslationUnit>();

    // Tambien es visible lo ya cargado
    Resource resource = trunit.eResource();
    ResourceSet resourceSet = resource.getResourceSet();
    EList<Resource> resources = resourceSet.getResources();
    int index = resources.indexOf(resource);

    for (int i = 0; i < index; i++) {
      loaded.add((TranslationUnit) resources.get(i).getContents().get(0));
    }

    if (!loaded.isEmpty())
      outer = depthTraverse(type, loaded.iterator());

    IScope scope = getScope(trunit, type);

    outer = concatenate(outer, scope.getOuterScope());

    return new SimpleScope(outer, scope.getContents());
  }
View Full Code Here

    // try to resolve from cache
    Pair<EObject, EClass> clave = new Pair<EObject, EClass>(trunit, type);
    if (scopecache.containsKey(clave))
      return scopecache.get(clave);

    IScope outer = IScope.NULLSCOPE;

    Collection<TranslationUnit> includes = new LinkedList<TranslationUnit>();

    // y los includes del TranslationUnit actual
    includes.addAll(getIncludes(trunit, false));

    if (!includes.isEmpty())
      outer = depthTraverse(type, includes.iterator());

    IScope result = new SimpleScope(outer, getScopedElements(trunit, type));
    scopecache.put(clave, result);
    return result;
  }
View Full Code Here

   * @param iterator
   * @return
   * @throws IOException
   */
  private static IScope depthTraverse(EClass type, Iterator<TranslationUnit> iterator) throws Exception {
    IScope outer = IScope.NULLSCOPE;

    if (iterator.hasNext()) {
      TranslationUnit trunit = iterator.next();
      // inner scope calculation
      IScope scope = getScope(trunit, type);
      // outer scope calculation
      outer = depthTraverse(type, iterator);
      // concatenation
      outer = concatenate(outer, scope);
    }
View Full Code Here

   * @param outer
   * @param inner
   * @return
   */
  private static IScope concatenate(IScope outer, IScope inner) {
    IScope result = outer;

    if (inner != IScope.NULLSCOPE)
      result = new SimpleScope(concatenate(outer, inner.getOuterScope()), inner.getContents());

    return result;
View Full Code Here

  public IScope scope_Constant(Container context, EReference reference) throws Exception {
    return IDLScopingHelper.getScope(context, reference.getEReferenceType());
  }
 
  public IScope scope_Constant(TranslationUnit context, EReference reference) throws Exception {
    IScope sc = IDLScopingHelper.getScope(context,
          reference.getEReferenceType());
    return sc;
  }
View Full Code Here

        }
        return list;
      }
    });
    //only the prefixes defined within the model are visible
    IScope outer=b.eContainer()==null
        ?IScope.NULLSCOPE
        :getScope(b.eContainer(), ref);
    return Scopes.scopeFor(prefixIds, new Function<PrefixId, QualifiedName>() {
      public QualifiedName apply(PrefixId def){
          return QualifiedName.create("",Optional.fromNullable(def.getId()).or(""));
View Full Code Here

  @Override
  public IScope getScope(EObject context, EReference reference) {
    if (context == null)
      throw new NullPointerException("context");
    IScope result = getResourceScope(context.eResource(), reference);
    return getLocalElementsScope(result, context, reference);
  }
View Full Code Here

    EList<PrequelConstruct> prequels = new BasicEList<PrequelConstruct>();

    Grammar grammar = createMock(Grammar.class);
    ParserRule rule = createMock(ParserRule.class);
    ParserRule ref = createMock(ParserRule.class);
    IScope scope = createMock(IScope.class);

    Antlr4ScopeProvider scopeProvider = PowerMock.createPartialMock(Antlr4ScopeProvider.class,
        "scopeFor", PrequelConstruct.class, List.class, Class.class);

    Class[] prequelTypes = {Imports.class, Options.class, V3Tokens.class, V4Tokens.class,
View Full Code Here

TOP

Related Classes of org.eclipse.xtext.scoping.IScope

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.