Anu
Anu

Reputation: 405

How can I get all annotations within a class using ICompilationUnit

I have a class Book which has some annotations like @Override,@Before,@After.

How can I get those annotations using ICompilationUnit?

Upvotes: 0

Views: 412

Answers (1)

katsharp
katsharp

Reputation: 2551

Javadoc for IAnnotation states that:

"Annotations are obtained using IAnnotatable.getAnnotation(String).

Note that annotations are not children of their declaring element. To get a list of the annotations use IAnnotatable.getAnnotations()."

What's an IAnnotatable? IField, ILocalVariable, IMethod, IPackageDeclaration, IType.

There are methods on ICompilationUnit for getting objects of those types.

Upvotes: 1

Related Questions