Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » SharedASTProvider.getAST(..) cannot resolve bindings for IClassFile but succeeds on ICompilationUnit(For external JAR with source attachments, the AST has may unresolved bindings, but an AST from the same code in a Java project does not.)
SharedASTProvider.getAST(..) cannot resolve bindings for IClassFile but succeeds on ICompilationUnit [message #1710785] Fri, 09 October 2015 10:34 Go to next message
Andreas Sewe is currently offline Andreas SeweFriend
Messages: 111
Registered: June 2013
Senior Member
Hi,

I am using the following piece of code to obtain an AST with resolved bindings:

 SharedASTProvider.getAST(typeRoot, SharedASTProvider.WAIT_YES, null);

Unfortunately, when my typeRoot is an IClassFile with attached source, many bindings in the resulting AST cannot be resolved, e.g., calls to MethodDeclaration.resolveBinding() return null.

This does not happen if I import the same code as part of a Java project into my workspace, i.e., when my typeRoot is an ICompilationUnit instead.

Do I misunderstand how SharedASTProvider.getAST(..) goes about things? From browsing through its code, I think it always requests bindings to be resolved. (In fact, some bindings in the resulting AST are, but far from all of them.)

FWIW, the (source) JARs I used are for Guava 15: JAR and source attachment. Unzipping the source JAR and dumping it into a Java project causes the bindings to be resolved.

Any help is greatly appreciated.

Andreas
Re: SharedASTProvider.getAST(..) cannot resolve bindings for IClassFile but succeeds on ICompilation [message #1710793 is a reply to message #1710785] Fri, 09 October 2015 10:58 Go to previous message
Andreas Sewe is currently offline Andreas SeweFriend
Messages: 111
Registered: June 2013
Senior Member
I did some more digging: The problem occurs when the classpath is incomplete. In Guava's case, javax.annotation.Nullable and friends where not on the project classpath. As soon as I add them to the classpath, the resulting AST has all bindings.

But there is one thing I don't understand: Why does SharedASTProvider.getAST(..) behave differently for ICompilationUnits and IClassFiles. If I simply unzip the sources JAR into a Java project without javax.annotation.Nullable on the classpath, I nevertheless get an AST with most bindings resolved. Why can't JDT manage the same thing for JARs with attached sources?
Previous Topic:Java formatter changed (Luna to Mars)
Next Topic:Need an explanation of workspace locking
Goto Forum:
  


Current Time: Thu Sep 19 05:40:42 GMT 2024

Powered by FUDForum. Page generated in 0.02724 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top