return bugParameters;
}
private static MarkerParameter createMarkerParameter(IJavaProject project, BugInstance bug) {
IJavaElement type = null;
WorkItem resource = null;
try {
type = getJavaElement(bug, project);
if (type != null) {
resource = new WorkItem(type);
}
} catch (JavaModelException e1) {
FindbugsPlugin.getDefault().logException(e1, "Could not find Java type for FindBugs warning");
}
if (resource == null) {
if (Reporter.DEBUG) {
reportNoResourceFound(bug);
}
return null;
}
// default - first class line
int primaryLine = bug.getPrimarySourceLineAnnotation().getStartLine();
// FindBugs needs originally generated primary line in order to find the
// bug again.
// Sometimes this primary line is <= 0, which causes Eclipse editor to
// ignore it
// So we check if we can replace the "wrong" primary line with a
// "better" start line
// If not, we just provide two values - one for Eclipse, another for
// FindBugs itself.
int startLine = -1;
if (primaryLine <= 0) {
FieldAnnotation primaryField = bug.getPrimaryField();
if (primaryField != null && primaryField.getSourceLines() != null) {
startLine = primaryField.getSourceLines().getStartLine();
if (startLine < 0) {
// We have to provide line number, otherwise editor wouldn't
// show it
startLine = 1;
}
} else {
// We have to provide line number, otherwise editor wouldn't
// show it
startLine = 1;
}
}
MarkerParameter parameter;
if (startLine > 0) {
parameter = new MarkerParameter(bug, resource, startLine, primaryLine);
} else {
parameter = new MarkerParameter(bug, resource, primaryLine, primaryLine);
}
if (Reporter.DEBUG) {
System.out
.println("Creating marker for " + resource.getPath() + ": line " + parameter.primaryLine + bug.getMessage());
}
return parameter;
}