开发者

Java source code parser which supports annotations

I need a Java source c开发者_Go百科ode parsing library for Java to programmatically extract method definitions and annotations.

Specifically, given code like :

@WebMethod(operationName = "MyOperation")
public String myOperation(String param1,int param2) { ....
}

I have the following requirements:

1. Extract the name, return type and names and types of the method parameters

2. Extract the annotations associated with the method

3. Finally, create a new source file by removing the annotations

I am currently using JaxMeJS http://ws.apache.org/jaxme/js/jparser.html which satisfies 1. but not 2. or 3.

Could you recommended a parsing library that can fulfill all 3 requirements ?


JavaCC comes with a 1.5 parser.


Annotation processing is part of the Annotation processing tool in Java which runs as part of the Java compiler. I'm not sure how you can remove the annotations from the source code. This is not supported by APT. (It might be easier to remove the annotations from the compiler byte code than from the source code.)

I've implemented a source code generator based on annotations using APT in the Quickcheck project.

Another root could be to use ASM (or any other byte code manipulation tool) to read the annotations.


I think APT, as suggested by Thomas Jung is what you need. Still, if you want to look into other options, do check Java 6 grammar for antlr


How about using JDT parser?

JDT means Java Development Tools. Eclipse use this.

I also did my project with it. It is really nice. And there is much info about it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜