예제 #1
0
  public IBinding[] getDeclarationsInScope(int offset, int flags) {
    org.eclipse.che.ide.ext.java.jdt.core.dom.NodeFinder finder =
        new org.eclipse.che.ide.ext.java.jdt.core.dom.NodeFinder(fRoot, offset, 0);
    ASTNode node = finder.getCoveringNode();
    if (node == null) {
      return NO_BINDING;
    }

    if (node instanceof SimpleName) {
      return getDeclarationsInScope((SimpleName) node, flags);
    }

    try {
      ITypeBinding binding = Bindings.getBindingOfParentType(node);
      DefaultBindingRequestor requestor = new DefaultBindingRequestor(binding, flags);
      addLocalDeclarations(node, offset, flags, requestor);
      if (binding != null) {
        addTypeDeclarations(binding, flags, requestor);
      }
      List<IBinding> result = requestor.getResult();
      return result.toArray(new IBinding[result.size()]);
    } finally {
      clearLists();
    }
  }
예제 #2
0
  public IBinding[] getDeclarationsAfter(int offset, int flags) {
    try {
      org.eclipse.che.ide.ext.java.jdt.core.dom.NodeFinder finder =
          new org.eclipse.che.ide.ext.java.jdt.core.dom.NodeFinder(fRoot, offset, 0);
      ASTNode node = finder.getCoveringNode();
      if (node == null) {
        return null;
      }

      ASTNode declaration = findParentStatement(node);
      while (declaration instanceof Statement && declaration.getNodeType() != ASTNode.BLOCK) {
        declaration = declaration.getParent();
      }

      if (declaration instanceof Block) {
        DefaultBindingRequestor requestor = new DefaultBindingRequestor();
        DeclarationsAfterVisitor visitor =
            new DeclarationsAfterVisitor(node.getStartPosition(), flags, requestor);
        declaration.accept(visitor);
        List<IBinding> result = requestor.getResult();
        return result.toArray(new IBinding[result.size()]);
      }
      return NO_BINDING;
    } finally {
      clearLists();
    }
  }
예제 #3
0
  public IBinding[] getDeclarationsInScope(SimpleName selector, int flags) {
    try {
      // special case for switch on enum
      if (selector.getLocationInParent() == SwitchCase.EXPRESSION_PROPERTY) {
        ITypeBinding binding =
            ((SwitchStatement) selector.getParent().getParent())
                .getExpression()
                .resolveTypeBinding();
        if (binding != null && binding.isEnum()) {
          return getEnumContants(binding);
        }
      }

      ITypeBinding parentTypeBinding = Bindings.getBindingOfParentType(selector);
      if (parentTypeBinding != null) {
        ITypeBinding binding = getQualifier(selector);
        DefaultBindingRequestor requestor = new DefaultBindingRequestor(parentTypeBinding, flags);
        if (binding == null) {
          addLocalDeclarations(selector, flags, requestor);
          addTypeDeclarations(parentTypeBinding, flags, requestor);
        } else {
          addInherited(binding, flags, requestor);
        }

        List<IBinding> result = requestor.getResult();
        return result.toArray(new IBinding[result.size()]);
      }
      return NO_BINDING;
    } finally {
      clearLists();
    }
  }