Thanks to everyone for their feedback. Looking into the compiler API, it's definitely doable (but not so simple). This article provided a good start for the compiler API. I think in the future I will look into writing an extensible rule checker. Attempting to hijack the @Deprecated
annotation, by the way, will not work, as inside of the compiler it is removed along with the other "platform annotations".
For now, I'm going with the rather coarse solution of bludgeoning the programmer with a verbose checked exception. While it does clutter the code, it also avoids the complexity of actually analyzing their intent. Something like:
try {
doWork(workUnit, 15, Style.STRICT);
} catch (MakeSureYouOverrodeEverythingYouWantedToFirst warning) {
; // will never actually reach here, but you have been warned!
}
If the programmer fails to do as instructed, the output of their program can be pseudorandomly buggy, and hence rather tedious to debug. And while this solution is certainly a frowned upon hack of exception handling (including by me), it rather simply fullfils my needs.
Besides, the extra effort just might encourage the programmer to actually do what they're supposed to!
I'm still interested in hearing other ideas, if you have one.