user483040
user483040

Reputation:

Tool to identify Java annotations in various Java APIs

I'm trying to identify places where annotation names are the same or similar to compile a list of these things to make sure our team knows where possible points of confusion can be found. For example, Guice @provides and RESTeasy @provider are similar enough in spelling but different enough in semantics as to confuse people so I'd like to call that out explicitly and explain the differences.

What I'm looking for is a tool or even a website that enumerates the annotations associated with packages. This might be a pipe dream, but before I manually start going through and collecting these things I thought I'd check.

I was considering writing one based on Javadoc that simply only pulled in the annotations but I don't have access to Java source files in many cases.

Any thoughts or suggestions?

Upvotes: 3

Views: 222

Answers (4)

MichaelMoser
MichaelMoser

Reputation: 3500

I wrote such a tool: https://github.com/MoserMichael/ls-annotations

it decompiles the byte code and lists declarations (classes, functions, variables) with annotations only. You can also use it to find all classes/interfaces derived from a given class/inerface - and all the classes/interfaces derived from a given class/interface.

The tool uses the asm library to scan class files and to extract annotations. it can detect annotations with retention policy CLASS and RUNTIME. It can't detect annotations with retention policy SOURCE that are not put into bytecode, for example @Override is one of these.

Upvotes: 1

Robe Elckers
Robe Elckers

Reputation: 977

I suggest to scan for annotations yourself and generate a list for that.

You can do that by writing your own implementation of an annotation processer, i.e. extend AbstractProcessor. Within this processor you can write a text file containing all Annotations. You can add this processor to your build procedure, then it will execute the processor when you build the project.

Another way to do this is using the Google Reflections library. This might be a bit more work since you would need to write a small programm to fetch the annotations and write the file.

Upvotes: 1

Robert
Robert

Reputation: 42660

In Eclipse you can use the standard method "Search for references" (context menu of a used annotation References -> Project) and you are getting a list where the annotations is used within your project.

Upvotes: 1

Sebastien Lorber
Sebastien Lorber

Reputation: 92150

Why not scanning your classpath and export all used annotations? Then just use some simple parsing / text compare to see the elements with almost the same name?

Upvotes: 0

Related Questions