Java Code Examples for edu.umd.cs.findbugs.SourceLineAnnotation#getSourceFile()

The following examples show how to use edu.umd.cs.findbugs.SourceLineAnnotation#getSourceFile() . 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: SourceFinder.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static String getOrGuessSourceFile(SourceLineAnnotation source) {
    if (source.isSourceFileKnown()) {
        return source.getSourceFile();
    }
    String baseClassName = source.getClassName();
    int i = baseClassName.lastIndexOf('.');
    baseClassName = baseClassName.substring(i + 1);
    int j = baseClassName.indexOf('$');
    if (j >= 0) {
        baseClassName = baseClassName.substring(0, j);
    }
    return baseClassName + ".java";
}
 
Example 2
Source File: FindBugsParser.java    From analysis-model with MIT License 5 votes vote down vote up
private String findSourceFile(final SourceFinder sourceFinder, final SourceLineAnnotation sourceLine) {
    try {
        SourceFile sourceFile = sourceFinder.findSourceFile(sourceLine);
        return sourceFile.getFullFileName();
    }
    catch (IOException ignored) {
        return sourceLine.getPackageName().replace(DOT, SLASH) + SLASH + sourceLine.getSourceFile();
    }
}
 
Example 3
Source File: SetBugDatabaseInfo.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
static String fullPath(SourceLineAnnotation src) {
    return src.getPackageName().replace('.', File.separatorChar) + File.separatorChar + src.getSourceFile();
}
 
Example 4
Source File: FileBugHash.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
FileBugHash(BugCollection bugs) {

        for (PackageStats pStat : bugs.getProjectStats().getPackageStats()) {
            for (ClassStats cStat : pStat.getSortedClassStats()) {
                String path = cStat.getName();
                if (path.indexOf('.') == -1) {
                    path = cStat.getSourceFile();
                } else {
                    path = path.substring(0, path.lastIndexOf('.') + 1).replace('.', '/') + cStat.getSourceFile();
                }
                counts.put(path, 0);
                Integer size = sizes.get(path);
                if (size == null) {
                    size = 0;
                }
                sizes.put(path, size + cStat.size());
            }
        }
        for (BugInstance bug : bugs.getCollection()) {
            SourceLineAnnotation source = bug.getPrimarySourceLineAnnotation();

            String packagePath = source.getPackageName().replace('.', '/');
            String key;
            if (packagePath.length() == 0) {
                key = source.getSourceFile();
            } else {
                key = packagePath + "/" + source.getSourceFile();
            }
            StringBuilder buf = hashes.get(key);
            if (buf == null) {
                buf = new StringBuilder();
                hashes.put(key, buf);
            }
            buf.append(bug.getInstanceKey()).append("-").append(source.getStartLine()).append(".")
                    .append(source.getStartBytecode()).append(" ");
            Integer count = counts.get(key);
            if (count == null) {
                counts.put(key, 1);
            } else {
                counts.put(key, 1 + count);
            }
        }
    }