Best way to parse Java in Java

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.

+7
java parsing abstract-syntax-tree
source share
5 answers

Janino can analyze, compile and execute Java code.

+3
source share

Antlr has a grammar file for Java. See this .

+6
source share

Perhaps you are looking for something like ANTLR: http://www.antlr.org/

+2
source share

Eclipse provides a syntax tree for the native Java compiler. You can just access the elements.

See here .

+2
source share

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.

+1
source share

All Articles