Oracle Community Directory
Oracle Community FAQ
My Oracle Support Community (MOSC)
Go Directly To
Oracle Technology Network Community
My Oracle Support Community
OPN Cloud Connection
Oracle Employee Community
Oracle User Group Community
OTN Speaker Bureau
Java Compiler (Developer Tool APIs)
Please enter a title.
You can not post a blank message. Please type your message and try again.
This discussion is archived
: Aug 10, 2011 9:17 AM by
Resolve full qualified type from compiler syntax tree
Aug 10, 2011 9:17 AM
I'm writting a program to perform some analysis on arbitrary Java source code and I need to be able to resolve types that are imported. This is relatively easy if the type is explicitly imported e.g.
List x = null;
then the type of x can be determined to be List.
However if wildcard imports are used e.g.
List x = nulll;
How can I determine what the type of x actually is? I'm using the java compiler API to parse the source code:
CompilationTask task = compiler.getTask(null, null, null, options, null, files);
JavacTask javacTask = (JavacTask) task;
Iterable<? extends CompilationUnitTree> tree = javacTask.parse();
and then scanning the CompilationUnitTree for items of interest.
I suspect I need to execute the analyze phase of the compiler but I can't see that the output of that phase is immediatly useful.
This content has been marked as final.
Show 0 replies