Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java custom annotation/decorator @Testing

I want to do something like this:

@Testing

private void methodThatGivesWarningIfUserTriesToUseThis() {

}

where @Testing is a custom annotation/decorator in Java. I'd like the behaviour of this @Testing annotation to act ALMOST EXACTLY like the @Deprecated annotation - if i or someone else accidentally tries to use this in other parts of the code, the IDE will give a warning (and the method name also has a strike-through across the font). So for ex

how do i do this?

**note: i do not want to use @Deprecated because the method is not deprecated, i just want only to use it for testing purposes

**this marker should also be checked at compile time, not runTime.

like image 904
David T. Avatar asked Aug 08 '26 04:08

David T.


1 Answers

The problem is that annotations are, as their name states, only for annotating :) Creating such annotation is pretty easy, you need to do something like this:

public @interface Testing

In order for it to be used by your IDE at compile time you have to write a plug-in.

Here is a good start I found in another SO question for starting with the plugin development.

like image 182
Avi Avatar answered Aug 10 '26 17:08

Avi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!