is it possible to create a custom Alias-Annotation to be used instead of
@SuppressWarnings("unused") // EventBus
public void onEvent(SomeMessage msg) { ... }
like
@EventBusListener
public void onEvent(SomeMessage msg) { ... }
This would be more self-documenting and should include the SuppressWarnings of course... Sorry if this trivial but my googling failed me so far.
Custom annotations can be created in spring framework using Java Aspect Oriented programming and Java Reflection API.
In this way, we can create different custom annotations for validation purposes. You can find the full source code here. It is easy to create and use custom annotations in Java. Java developers will be relieved of redundant code by using custom annotations.
One approach is to write an annotation processor that transforms the AST (the compiler's internal representation of the source code). At each occurrence of @EventBusListener
, your annotation processor would insert an occurrence of @SuppressWarnings("unused")
. Later phases of the compiler would see the annotation.
Annotation processors do not ordinarily change the source code, so this takes a bit of work. The AST is supplied to the annotation processor as an interface type, so your annotation processor would need to cast this to a concrete class and perform side effects on the concrete class. Project Lombok is an example of annotation processing that modifies the AST during compilation.
You might just want to write the @SuppressWarnings("unused")
annotation, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With