17

Using Eclipse IDE, I'd like to get a list of all "things" annotated with a specific Java annotation.

For instance, I would like to get a list of all methods annotated with @Bean in Spring Framework's source code or JARs.

I'm aware that it's possible to look up annotation usage programmatically, as pointed out in this question. Instead I would like to look up annotation usage at development time within my Eclipse IDE.

Community
  • 1
  • 1
Abdull
  • 26,371
  • 26
  • 130
  • 172

3 Answers3

11

You can search for references in Eclipse. Click the annotation name, then right-click, select "References" and pick a scope for your search.

Rob
  • 1,143
  • 7
  • 14
  • Thank you for this hint. There are problems with this approach, though: ... it may list false-positive results, e.g. classes that work with the annotation name reflectively (... AnnotationUtils.findAnnotation(method, Bean.class) != null; )... Additionally, this approach is limited to source code in my workspace. It doesn't check usage of an annotation inside libraries or my Maven repository. Any ideas here? – Abdull Apr 12 '12 at 13:26
  • I agree that the false positives are ugly, but they are hard - if not impossible - to avoid because this search runs on a "semantic" level. About libs and/or Maven repos: I used to believe that Eclipse would search those as well, need to verify this on my work machine next week ;) – Rob Apr 12 '12 at 13:33
  • Cool! I'm curiously waiting for your results :) – Abdull Apr 12 '12 at 13:59
  • @Abdull: There is a solution for the "false positive" problem. In the Eclipse search dialog there is "Limit to" option. This can be set to "Match Locations" `->` "Annotations". That seems to limit the search results to only the use of the type as an annotation. – Lii Aug 26 '15 at 07:15
4

You can Control-click on the annotation which will open the annotation definition class and then right-click and choose References -> Workspace.

EDIT: I just checked it, and it is enough to right-click on the mentioned annotation and choosing References -> Workspace without even going into its definition.

adranale
  • 2,835
  • 1
  • 21
  • 39
2

In STS, there is an option in search:

STS Pointcut Matches

in which you can specify for example: @target(org.springframework.stereotype.Service) which will find all the classes marked with @Service

Betlista
  • 10,327
  • 13
  • 69
  • 110