Letting a single Java annotation implicitly set multiple annotations

Home / Uncategorized / Letting a single Java annotation implicitly set multiple annotations

I have written a Java library that defines and uses a custom annotation to find methods that are then called via reflection.

See this example
public void setDeviceClass(TestRecord record, String value) {
record.deviceClass = value;

So IDEs like IntelliJ and probably other code analysis tools will report most of the functions annotated this way as "Unused".

What I would like is an automated way to say that anything that has been annotated with @YauaaField is automatically also annotated with @SuppressWarnings("unused").

I’ve done quite a bit of googling, read through several online manuals, tutorials and java documentation. Yet I have not yet been able to find how to do that. The annotations do not seem to support ‘inheritance’ of any kind.

So is what I want even possible?

If not then what other options do I have?

So far I have only found these two ways to suppress these needless warnings:In IntelliJ I found the manual option to Suppress this warning on all methods annotated with YauaaField. But that is a manual option.
Manually set the @SupressWarnings("unused") on all of those methods/classes.

Is there a better way?

Not entirely automated, but a nice workaround. In IntelliJ you can set up your own Live Template to suggest an autocomplete when typing the annotation:
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *