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.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
You may be looking for something like ANTLR: http://www.antlr.org/
Janino can parse, compile and execute Java code.
Eclipse exposes the Syntax Tree of it's own Java compiler. You can simply access the elements.
See here.
JavaCC has a Java 1.5 grammar including generics.
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.
Antlr has a grammar file for Java. See this.