3

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?

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

yep, we do this as well. I am trying to pre-emptively identify these possible points of confusion before we kickoff a new project. I guess one could say that if I've reached this level or research it's time to call the research spike complete :)
1

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.

1 Comment

Will the first method work in the cases where I have only the deployed classes for the API? I imagine the second one would for sure...
1

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.

Comments

0

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.