Generate compiler warning with custom annotation

Is it possible to force the compiler to generate a warning when it encounters user-defined annotation? Something like @Deprecated annotation?

thanks

+7
source share
3 answers

Based on your original question and comments, I assume that you are trying to do the following:

  • Mark the code as incomplete (with a compiler warning) so that other developers do not use it yet.
  • Identify incomplete code in your IDE at a later point in time.

I do not believe that you can flag the code with a compiler warning. The @Deprecated tag is baked to the compiler. A more common way of specifying a method is incomplete, throwing an exception:

throw new UnsupportedOperationException("Not implemented yet");

The effect is not realized before execution, but other developers should test their code.

Regarding the identification of incomplete code, I will return to my original comment anyway. Use the TODO comment tag and Eclipse will build a to-do list for you. If your list is cluttered with automatically generated code that has not been cleared, you can use FIXME , XXX or define your own. Then you can filter your list.

+3
source

I asked the Lombok people to look at providing this functionality https://github.com/peichhorn/lombok-pg/issues/114 , and now it is implemented ;-) https://github.com/peichhorn/lombok-pg/wiki/ % 40 Warning

+2
source

This is possible through api annotation handlers

Below is a small Javac notification library https://github.com/pushtorefresh/javac-warning-annotation

Using:

 // some code... @Warning("This method should be refactored") public void someCodeWhichYouNeedAtTheMomentButYouWantToRefactorItLater() { // bad stuff going on here... } 
+1
source

All Articles