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

The following examples show how to use edu.umd.cs.findbugs.BugInstance#getPrimaryClass() . These examples are extracted from open source projects. 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
private static void reportNoResourceFound(BugInstance bug) {
    String className = null;
    String packageName = null;
    ClassAnnotation primaryClass = bug.getPrimaryClass();
    if (primaryClass != null) {
        className = primaryClass.getClassName();
        packageName = primaryClass.getPackageName();
    }
    if (Reporter.DEBUG) {
        System.out.println("NOT found resource for a BUG in BUG in class: " //$NON-NLS-1$
                + packageName + "." //$NON-NLS-1$
                + className + ": \n\t" //$NON-NLS-1$
                + bug.getMessage() + " / Annotation: " //$NON-NLS-1$
                + bug.getPrimarySourceLineAnnotation());
    }
}
 
Example 2
@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 3
@Override
public void doReportBug(BugInstance bugInstance) {
    if(includeCategories.size() > 0 && !includeCategories.contains(bugInstance.getCategoryAbbrev())) {
        return;
    }

    StringBuilder bugDetail = new StringBuilder();
    bugDetail
            .append("\n------------------------------------------------------")
            .append("\nNew Bug Instance: [" + ++bugInstanceCount + "]")
            .append("\n  message=" + bugInstance.getMessage())
            .append("\n  bugType=" + bugInstance.getBugPattern().getType())
            .append("  priority=" + bugInstance.getPriorityString())
            .append("  category=" + bugInstance.getCategoryAbbrev());
    if (bugInstance.getPrimaryClass() != null) {
        bugDetail.append("\n  class=" + bugInstance.getPrimaryClass().getClassName());
    }
    if (bugInstance.getPrimaryMethod() != null) {
        bugDetail.append("  method=" + bugInstance.getPrimaryMethod().getMethodName());
    }
    if (bugInstance.getPrimaryField() != null) {
        bugDetail.append("  field=" + bugInstance.getPrimaryField().getFieldName());
    }
    if (bugInstance.getPrimarySourceLineAnnotation() != null) {
        bugDetail.append("  line=" + bugInstance.getPrimarySourceLineAnnotation().getStartLine());
    }
    bugDetail.append("\n------------------------------------------------------");
    log.info(bugDetail.toString());
    //bugCollection.add(bugInstance);
}
 
Example 4
@Override
public void reportBug(@Nonnull BugInstance bugInstance) {

    if (!category.equals(bugInstance.getBugPattern().getCategory())) {
        getDelegate().reportBug(bugInstance);
        return;
    }
    if (check.isEmpty()) {
        return;
    }

    ClassAnnotation c = bugInstance.getPrimaryClass();
    @DottedClassName
    String packageName = c.getPackageName();

    while (true) {
        if (check.contains(packageName)) {
            getDelegate().reportBug(bugInstance);
            return;
        } else if (dontCheck.contains(packageName)) {
            return;
        }
        int i = packageName.lastIndexOf('.');
        if (i < 0) {
            return;
        }
        packageName = packageName.substring(0, i);
    }

}
 
Example 5
@Override
public boolean match(BugInstance bugInstance) {
    // Match on the pure filename first
    ClassAnnotation primaryClassAnnotation = bugInstance.getPrimaryClass();
    if (primaryClassAnnotation == null) {
        return false;
    }

    // Create the variable to store the result. If there is no valid bug file name,
    // the result is false no matter what.
    boolean result = false;
    String bugFileName = primaryClassAnnotation.getSourceFileName();
    if (bugFileName != null && !bugFileName.isEmpty()) {

        // Check if the files are already matching and store the result
        // This is the check which just compares in a simple way and does not obey
        // the full path of the file.
        result = fileName.match(bugFileName);

        // if no result try again to match with the full path as well
        if (!result && bugInstance.getPrimarySourceLineAnnotation().isSourceFileKnown()) {
            bugFileName = bugInstance.getPrimarySourceLineAnnotation().getRealSourcePath();
            result = fileName.match(bugFileName);
        }
    }

    LOG.debug("Matching {} with {}, result = {}", bugFileName, fileName, result);
    return result;
}