Пример #1
0
  protected IFile searchLocallyForIFile(final IBinding binding) {
    if (_astRoot == null) {
      return null;
    }

    ASTNode node = _astRoot.findDeclaringNode(binding);
    if (node != null) return _file;
    return null;
  }
Пример #2
0
  protected CompilationUnit searchLocallyForBinding(final IBinding binding) {
    if (_astRoot == null) {
      throw new IllegalStateException(
          "_astRoot is null. Check that types or environments are not being cached between builds or reconciles by user code"); //$NON-NLS-1$
    }

    final ASTNode node = _astRoot.findDeclaringNode(binding);
    if (node != null) return _astRoot;
    return null;
  }
Пример #3
0
  /**
   * @param key
   * @param unit the unit that contains the definition of type whose type key is <code>key</code> if
   *     <code>key</code> is a wild card, primitive, array type or parameterized type, this should
   *     be null.
   * @return return the type binding for the given key or null if none is found.
   */
  protected IBinding getBindingFromKey(final String key, final ICompilationUnit unit) {

    class BindingRequestor extends ASTRequestor {
      private IBinding _result = null;
      private int _kind;

      public void acceptAST(ICompilationUnit source, CompilationUnit ast) {
        if (source == unit) {
          _modelCompUnit2astCompUnit.put(source, ast);
        }
      }

      public void acceptBinding(String bindingKey, IBinding binding) {
        if (binding != null) {
          _result = binding;
          _kind = binding.getKind();
        }
      }
    }

    final BindingRequestor requestor = new BindingRequestor();
    final ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setResolveBindings(true);
    parser.setBindingsRecovery(true);
    parser.setProject(_javaProject);
    parser.setIgnoreMethodBodies(true);
    ICompilationUnit[] units = unit == null ? NO_UNIT : new ICompilationUnit[] {unit};
    parser.createASTs(units, new String[] {key}, requestor, null);
    final IBinding result = requestor._result;
    if (result != null && unit != null) {
      final CompilationUnit astUnit = _modelCompUnit2astCompUnit.get(unit);
      // make sure everything is lining up properly.  Only cache real types, not package-infos.
      if (requestor._kind == IBinding.TYPE && astUnit.findDeclaringNode(result) != null) {
        ITypeBinding declaringClass = getDeclaringClass(result);
        _typeBinding2ModelCompUnit.put(declaringClass, unit);
      }
    }
    return result;
  }
Пример #4
0
 /** @return the ast current being processed */
 protected AST getCurrentDietAST() {
   return _astRoot.getAST();
 }
Пример #5
0
 /**
  * @param binding must be correspond to a type, method or field declaration.
  * @return the ast node the corresponds to the declaration of the given binding. Return null if
  *     none is found.
  */
 public ASTNode getASTNodeForBinding(final IBinding binding) {
   final CompilationUnit astUnit = getCompilationUnitForBinding(binding);
   if (astUnit == null) return null;
   return astUnit.findDeclaringNode(binding.getKey());
 }
Пример #6
0
 /**
  * Go through the current compilation unit and look for ast nodes that has annotations.
  *
  * @return the map between ast node and
  */
 protected Map<ASTNode, List<Annotation>> getASTNodesWithAnnotations() {
   final Map<ASTNode, List<Annotation>> astNode2Anno = new HashMap<ASTNode, List<Annotation>>();
   final AnnotatedNodeVisitor visitor = new AnnotatedNodeVisitor(astNode2Anno);
   _astRoot.accept(visitor);
   return astNode2Anno;
 }
Пример #7
0
 @SuppressWarnings("unchecked")
 protected List<AbstractTypeDeclaration> searchLocallyForTypeDeclarations() {
   return _astRoot.types();
 }