Java: How can you generate special compiler warnings for using methods?

I did some work with annotation processing, and it would be really helpful to warn the user about using certain annotated methods. This basically creates a custom version of the annotation @Deprecated. I thought a good place to start might be the actual annotation handler for @Deprecated, but I can't find it .: _

(Note that this is similar, but not the same as How to deliberately trigger a custom java compiler warning message? )

Thank!

+3
source share
3 answers

. API , ( ). API . , . @Deprecated, , , " ".

, . , . - :

try {
    doWork(workUnit, 15, Style.STRICT);
} catch (MakeSureYouOverrodeEverythingYouWantedToFirst warning) {
    ; // will never actually reach here, but you have been warned!
}

, , , . , , ( ), .

, , !

, .

+1

, null varargs.

Checker Framework (, ) ( ).

https://checkerframework.org/

.

, , , . , . , , , .

+2

javac, OpenJDK. , .

, , FindBugs PMD, .

-1

Source: https://habr.com/ru/post/1779874/


All Articles