Best way to parse Java in Java

2019-02-09 15:20发布

As the title says, I want to parse some Java source code in Java. I'm pretty sure there are other java libraries that already perform this, but I couldn't find any.

5条回答
相关推荐>>
2楼-- · 2019-02-09 15:39

You may be looking for something like ANTLR: http://www.antlr.org/

查看更多
Root(大扎)
3楼-- · 2019-02-09 15:41

Janino can parse, compile and execute Java code.

查看更多
Evening l夕情丶
4楼-- · 2019-02-09 15:43

Eclipse exposes the Syntax Tree of it's own Java compiler. You can simply access the elements.

See here.

查看更多
Viruses.
5楼-- · 2019-02-09 15:44

JavaCC has a Java 1.5 grammar including generics.

the tokens are probably more fine-grained then what I want

Your first requirement is to get an accurate parse, and you will realistically only get that from an existing parser. What you do with the result is up to you.

查看更多
太酷不给撩
6楼-- · 2019-02-09 15:53

Antlr has a grammar file for Java. See this.

查看更多
登录 后发表回答