As the title says, I want to analyze some Java source code in Java. I am sure there are other java libraries that already do this, but I could not find them.
Janino can analyze, compile and execute Java code.
Antlr has a grammar file for Java. See this .
Perhaps you are looking for something like ANTLR: http://www.antlr.org/
Eclipse provides a syntax tree for the native Java compiler. You can just access the elements.
See here .
JavaCC has Java 1.5 grammar, including generics.
tokens are probably more fine grained what I want
Your first requirement is to get accurate parsing, and you really only get this from your existing parser. What you do with the result is up to you.