Search in sources :

Example 1 with Matcher

use of com.google.errorprone.matchers.Matcher in project error-prone by google.

the class RestrictedApiChecker method anyAnnotation.

private static Matcher<Tree> anyAnnotation(List<? extends TypeMirror> mirrors, VisitorState state) {
    JavacProcessingEnvironment javacEnv = JavacProcessingEnvironment.instance(state.context);
    ArrayList<Matcher<Tree>> matchers = new ArrayList<>(mirrors.size());
    for (TypeMirror mirror : mirrors) {
        TypeElement typeElem = (TypeElement) javacEnv.getTypeUtils().asElement(mirror);
        String name = mirror.toString();
        if (typeElem != null) {
            // Get the binary name if possible ($ to separate nested members). See b/36160747
            name = javacEnv.getElementUtils().getBinaryName(typeElem).toString();
        }
        matchers.add(Matchers.hasAnnotation(name));
    }
    return Matchers.anyOf(matchers);
}
Also used : NewClassTreeMatcher(com.google.errorprone.bugpatterns.BugChecker.NewClassTreeMatcher) Matcher(com.google.errorprone.matchers.Matcher) MethodInvocationTreeMatcher(com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) JavacProcessingEnvironment(com.sun.tools.javac.processing.JavacProcessingEnvironment) ArrayList(java.util.ArrayList)

Aggregations

MethodInvocationTreeMatcher (com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher)1 NewClassTreeMatcher (com.google.errorprone.bugpatterns.BugChecker.NewClassTreeMatcher)1 Matcher (com.google.errorprone.matchers.Matcher)1 JavacProcessingEnvironment (com.sun.tools.javac.processing.JavacProcessingEnvironment)1 ArrayList (java.util.ArrayList)1 TypeElement (javax.lang.model.element.TypeElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1