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

The following examples show how to use edu.umd.cs.findbugs.BugInstance#getPrimaryMethod() . 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
@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
@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 3
/**
 * @param b
 * @return
 */
private String getBugLocation(BugInstance b) {
    String point;
    MethodAnnotation m = b.getPrimaryMethod();
    FieldAnnotation f = b.getPrimaryField();
    if (m != null) {
        point = m.toString();
    } else if (f != null) {
        point = f.toString();
    } else {
        point = null;
    }
    return point;
}
 
Example 4
public Map<String, List<ReportedBug>> execute() throws IOException, InterruptedException, IllegalStateException {
	FindBugs2 findBugs = new FindBugs2();
	Project project = getProject();

	findBugs.setProject(project);

	XMLBugReporter reporter = new XMLBugReporter(project);
	reporter.setPriorityThreshold(bugPriority);
	reporter.setAddMessages(true);
	reporter.setUseLongBugCodes(true);

	findBugs.setBugReporter(reporter);

	UserPreferences userPrefs = UserPreferences.createDefaultUserPreferences();
	userPrefs.setEffort(userPrefsEffort);
	findBugs.setUserPreferences(userPrefs);

	findBugs.setDetectorFactoryCollection(DetectorFactoryCollection.instance());
	findBugs.setAnalysisFeatureSettings(effort);
	findBugs.finishSettings();

	findBugs.execute();

	Map<String, List<ReportedBug>> reportedBugs = new HashMap<String, List<ReportedBug>>();
	for (BugInstance b : reporter.getBugCollection()) {
		String filename = b.getPrimarySourceLineAnnotation().getSourcePath();

		if (!reportedBugs.containsKey(filename)) {
			reportedBugs.put(filename, new ArrayList<ReportedBug>());
		}

		ReportedBug rb = new ReportedBug(b.getBugRank(), b.getBugRankCategory().toString(), b.getPriority(),
				b.getPriorityString(), b.getType(), b.getAbbrev(), b.getBugPattern().getDetailPlainText(),
				b.getBugPattern().getCategory(), b.getPrimaryClass().getClassName(), b.getAbridgedMessage(),
				b.getMessage());

		if (b.getPrimaryMethod() != null) {
			String methodName = b.getPrimaryMethod().getFullMethod(b.getPrimaryClass());
			rb.setMethod(methodName.substring(methodName.lastIndexOf(".") + 1));
		}

		if (b.getPrimaryField() != null) {
			rb.setField(b.getPrimaryField().getFieldName());
		}

		if (b.getPrimaryLocalVariableAnnotation() != null) {
			rb.setLocalVariable(b.getPrimaryLocalVariableAnnotation().getName());
		}

		reportedBugs.get(filename).add(rb);
	}

	findBugs.dispose();
	return reportedBugs;
}