Java Code Examples for edu.umd.cs.findbugs.BugInstance#getAnnotations()

The following examples show how to use edu.umd.cs.findbugs.BugInstance#getAnnotations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MethodMatcher.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public boolean match(BugInstance bugInstance) {

    MethodAnnotation methodAnnotation = null;
    if (role == null || "".equals(role)) {
        methodAnnotation = bugInstance.getPrimaryMethod();
    } else {
        for (BugAnnotation a : bugInstance.getAnnotations()) {
            if (a instanceof MethodAnnotation && role.equals(a.getDescription())) {
                methodAnnotation = (MethodAnnotation) a;
                break;
            }
        }
    }
    return methodAnnotation != null
            && name.match(methodAnnotation.getMethodName())
            && (signature == null || signature.match(methodAnnotation.getMethodSignature()));
}
 
Example 2
Source File: TypeMatcher.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public boolean match(BugInstance bugInstance) {
    TypeAnnotation typeAnnotation = bugInstance.getPrimaryType();
    if (role != null && !"".equals(role)) {
        for (BugAnnotation a : bugInstance.getAnnotations()) {
            if (a instanceof TypeAnnotation && role.equals(a.getDescription())) {
                typeAnnotation = (TypeAnnotation) a;
                break;
            }
        }
    }
    if (typeAnnotation == null) {
        return false;
    }
    String typeDescriptor = typeAnnotation.getTypeDescriptor();
    return descriptor.match(typeDescriptor)
            && (typeParameters == null || typeParameters.equals(typeAnnotation.getTypeParameters()));
}
 
Example 3
Source File: ClassMatcher.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public boolean match(BugInstance bugInstance) {
    ClassAnnotation classAnnotation = bugInstance.getPrimaryClass();
    if (role != null && !"".equals(role)) {
        for (BugAnnotation a : bugInstance.getAnnotations()) {
            if (a instanceof ClassAnnotation && role.equals(a.getDescription())) {
                classAnnotation = (ClassAnnotation) a;
                break;
            }
        }
    }
    String bugClassName = classAnnotation.getClassName();
    boolean result = className.match(bugClassName);
    LOG.debug("Matching {} with {}, result = {}", bugClassName, className, result);
    return result;
}
 
Example 4
Source File: FieldMatcher.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public boolean match(BugInstance bugInstance) {
    FieldAnnotation fieldAnnotation = null;
    if (role == null || "".equals(role)) {
        fieldAnnotation = bugInstance.getPrimaryField();
    } else {
        for (BugAnnotation a : bugInstance.getAnnotations()) {
            if (a instanceof FieldAnnotation && role.equals(a.getDescription())) {
                fieldAnnotation = (FieldAnnotation) a;
                break;
            }
        }
    }
    return fieldAnnotation != null
            && name.match(fieldAnnotation.getFieldName())
            && (signature == null || signature.match(fieldAnnotation.getFieldSignature()));
}
 
Example 5
Source File: BugInstanceMatcher.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static <T> T extractBugAnnotation(BugInstance bugInstance, Class<T> annotationType) {
    for (BugAnnotation annotation : bugInstance.getAnnotations()) {
        if (annotation.getClass().equals(annotationType)) {
            return annotationType.cast(annotation);
        }
    }
    return null;
}
 
Example 6
Source File: MovedClassMap.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Find set of classes referenced in given BugCollection.
 *
 * @param bugCollection
 * @return set of classes referenced in the BugCollection
 */
private Set<String> buildClassSet(BugCollection bugCollection) {
    Set<String> classSet = new HashSet<>();

    for (BugInstance warning : bugCollection) {
        for (BugAnnotation annotation : warning.getAnnotations()) {
            if (!(annotation instanceof ClassAnnotation)) {
                continue;
            }
            classSet.add(((ClassAnnotation) annotation).getClassName());
        }
    }

    return classSet;
}