Niels Basjes
Niels Basjes

Reputation: 10642

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

@YauaaField("DeviceClass")
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:

Is there a better way?

Upvotes: 1

Views: 222

Answers (1)

Luciano van der Veekens
Luciano van der Veekens

Reputation: 6577

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:

enter image description here

Upvotes: 3

Related Questions