protected IFile searchLocallyForIFile(final IBinding binding) {
    if (_astRoot == null) {
      return null;
    }

    ASTNode node = _astRoot.findDeclaringNode(binding);
    if (node != null) return _file;
    return null;
  }
  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;
  }
  /**
   * @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;
  }
 /**
  * @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());
 }