Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check Annotations of Methods using eclipse JDT library

I am building a prototype of a static analysis tool, for which I intend to use eclipse to do the heavy lifting. How can I check what annotations are applied on a method when I visit the declaration using the ASTVisitor. I am interested in only certain methods of the class under analysis, and I am thinking of marking them using annotations

like image 262
Midhat Avatar asked Jun 02 '26 16:06

Midhat


1 Answers

Try ASTView plugin (http://www.eclipse.org/jdt/ui/astview/index.php), this helps to visualize the AST of a source file and also helps to figure out which nodes to visit.

You would probably want to override the following in ASTVisitor

  • visit(MarkerAnnotation annotation)
  • visit(SingleMemberAnnotation annotation)
  • visit(NormalAnnotation annotation)

Or you may visit only method declarations and get the annotations via MethodDeclaration.MODIFIERS2_PROPERTY.

like image 153
Deepak Azad Avatar answered Jun 05 '26 04:06

Deepak Azad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!