Is there some Java library that connects to the compiler that can allow you to add a warning or even failure when using any method and output a text recommending something else?
For instance, if I want a user calling Arrays.asList()
to get a warning or even failure and recommend another method to use?
You asked for something that plugs into the compiler, so you might try Error Prone, which lets you write custom compile errors by plugging into the compiler API.
(Error Prone, and tools built on top of it that aren't open-sourced yet, are exactly what Google uses for exactly this problem. Source: I sit next to the Error Prone team.)
An example check, to flag usages of
Class.getClass()
, is here. (That is, you already had aClass
object, and then you calledgetClass()
on that, which returnsClass.class
, which is just silly.)