We need to write a checkstyle custom check that verifies a specific condition for classes that inherit—directly or indirectly—from a certain class A. Is it possible to identify the indirect inheritance using the checkstyle API? For example, suppose we have:
- Class C ---extends---> class B
- Class B ---extends---> class A
In this case, it’s easy to check that C is a subclass of B by looking for the “extends” token (TokenTypes.EXTENDS_CLAUSE
) and looking for B in the extends clause AST. But how can we know that C is also a subclass of A?
Is Java reflection plus instanceof the only way out? (Not desirable in our case as we have to run the check over thousands of files.)
Would PMD or another static analysis tool allow me to write a custom check with that (indirect inheritance) condition?