Midhat
Midhat

Reputation: 17810

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

Upvotes: 3

Views: 1783

Answers (2)

YouHuazi
YouHuazi

Reputation: 1

I got the annotations successfully by using MethodDeclaration.modifiers() . https://help.eclipse.org/latest/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjdt%2Fcore%2Fdom%2FBodyDeclaration.html&anchor=modifiers()

I hope this will help you.

Upvotes: 0

Deepak Azad
Deepak Azad

Reputation: 7923

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.

Upvotes: 7

Related Questions