* @return the IResource representing the Java class
*/
private static @CheckForNull
IJavaElement getJavaElement(BugInstance bug, IJavaProject project) throws JavaModelException {
SourceLineAnnotation primarySourceLineAnnotation = bug.getPrimarySourceLineAnnotation();
PackageMemberAnnotation packageAnnotation = null;
String packageName = null;
String qualifiedClassName = null;
if (primarySourceLineAnnotation == null) {
packageAnnotation = bug.getPrimaryClass();
if (packageAnnotation != null) {
packageName = packageAnnotation.getPackageName();
qualifiedClassName = packageAnnotation.getClassName();
}
} else {
packageName = primarySourceLineAnnotation.getPackageName();
qualifiedClassName = primarySourceLineAnnotation.getClassName();
}
if (qualifiedClassName == null) {
return null;
}
if (Reporter.DEBUG) {
System.out.println("Looking up class: " + packageName + ", " + qualifiedClassName);
}
Matcher m = fullName.matcher(qualifiedClassName);
IType type;
String innerName = null;
if (m.matches() && m.group(2).length() > 0) {
String outerQualifiedClassName = m.group(1).replace('$', '.');
innerName = m.group(2).substring(1);
// second argument is required to find also secondary types
type = project.findType(outerQualifiedClassName, (IProgressMonitor) null);
/*
* code below only points to the first line of inner class even if
* this is not a class bug but field bug
*/
if (type != null && !hasLineInfo(primarySourceLineAnnotation)) {
completeInnerClassInfo(qualifiedClassName, innerName, type, bug);
}
} else {
// second argument is required to find also secondary types
type = project.findType(qualifiedClassName.replace('$', '.'), (IProgressMonitor) null);
// for inner classes, some detectors does not properly report source
// lines:
// instead of reporting the first line of inner class, they report
// first line of parent class
// in this case we will try to fix this here and point to the right
// start line
if (type != null && type.isMember()) {
if (!hasLineInfo(primarySourceLineAnnotation)) {
completeInnerClassInfo(qualifiedClassName, type.getElementName(), type, bug);
}
}
}
// reassign it as it may be changed for inner classes
primarySourceLineAnnotation = bug.getPrimarySourceLineAnnotation();
int startLine;
/*
* Eclipse can help us find the line number for fields => we trying to
* add line info for fields here
*/
if (primarySourceLineAnnotation != null) {
startLine = primarySourceLineAnnotation.getStartLine();
if (startLine <= 0 && bug.getPrimaryField() != null) {
completeFieldInfo(qualifiedClassName, innerName, type, bug);
}
} else {
if (bug.getPrimaryField() != null) {