Closed
Description
This issue will implement a new mechanism to exclude specific classes or (this
is new!) specific methods or parts of methods from being checked with
ForbiddenAPIs.
The idea here is to use an annotation, that must have at least
RetentionPolicy.CLASS or RetentionPolicy.RUNTIME. ForbiddenAPIs will not
provide such an annotation, it can simply configured to look for any annotation
type(s), configured as a list of Class parameters.
This allows to run forbidden-apis with ant like:
<forbiddenapis supressAnnotations="org.foo.bar.SuppressForbidden" .../>
(same in maven as a list of class properties).
You have to define the custom annotation (or multiples) as part of your own
project, so we get no external dependencies. You can also misuse another
annotation (LOL). The annotation must just be of RetentionPolicy.CLASS or
RetentionPolicy.RUNTIME. It does not need to be documented. Just SOURCE-only
annotations won't work (because no longer visible in class files).
You can then annotate classes with this annotation (which does the same like
excluding the class file using the excludes="...." Ant/Maven config settings)
or go down to methods or code lines. In fact depending on the type of your
annotation, you can use it like SuppressWarnings. So annotate any method, code
line, or parameter [not yet decided if this makes sense] you want t exclude
from checking (or in Java 8 also types).
Forbidden-APIs will add an "example/default annotation" in its own JAR file,
but you are not required to use it (especially if you don't want to have a
compile-time dependency to forbiddenapis).
Original issue reported on code.google.com by uwe.h.schindler
on 14 Sep 2014 at 5:08