Yes, you can use ASTVisitor
and override the methods you need. Since, there are types of annotation: MarkerAnnotation
, NormalAnnotation
, etc.
ASTParser parser = ASTParser.newParser(AST.JLS4);
parser.setSource(charArray);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
final CompilationUnit cu = (CompilationUnit)
parser.createAST(null);
cu.accept(new ASTVisitor(){..methods..});
For example normal annotation:
@Override
public boolean visit(NormalAnnotation node) {
...
}
Btw, be careful about the diff below:
import java.lang.Deprecated;
...
@Deprecated
and
@java.lang.Deprecated