8

I know that it's not possible to extends Java annotations.

I've created an annotation for a private field which means that the field is likely to appear unused in the class in which it is declared. For this reason, I'm getting a lot of "unused field" warnings on my annotated fields.

Is there any way to give my annotation the behaviour of @SuppressWarnings("unused") so I don't have to doubly-annotate every field which has @MyAnnotation?

Community
  • 1
  • 1
Armand
  • 23,463
  • 20
  • 90
  • 119
  • 2
    If you have IntelliJ idea you could set the checker to ignore any field having your annotation. That's not a solution for your problem but might be a workaround. – Thomas Dec 30 '11 at 14:02
  • @Thomas thanks - as you say not a solution, but helpful :) – Armand Dec 30 '11 at 14:08

1 Answers1

1

The quick answer is "no". Java compiler doesn't know anything about your annotation, so it won't process it the way you want.


But the honest answer is "yes". In this article you can find detailed description of how to write compiler plugin. Chances are you can write plugin, which, in case of finding your annotation, will handle it and won't pass field to unused checker.

asm0dey
  • 2,841
  • 2
  • 20
  • 33