2

I need a Java source code 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 ?

4 Answers4

0

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.

Ui-Gyun Jeong
  • 143
  • 1
  • 4
  • 14
0

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.

Thomas Jung
  • 32,428
  • 9
  • 84
  • 114
0

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

Tahir Akhtar
  • 11,385
  • 7
  • 42
  • 69
0

JavaCC comes with a 1.5 parser.

user207421
  • 305,947
  • 44
  • 307
  • 483