@Override public void writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary) throws IOException { String classname = getClassName(); String sourcePath = getSourcePath();
@Override @SuppressWarnings("boxing") public @CheckForNull URL getSourceLink(BugInstance b) { if (sourceFileLinkPattern == null) { return null; } SourceLineAnnotation src = b.getPrimarySourceLineAnnotation(); String fileName = src.getSourcePath(); int startLine = src.getStartLine(); int endLine = src.getEndLine(); java.util.regex.Matcher m = sourceFileLinkPattern.matcher(fileName); boolean isMatch = m.matches(); if (isMatch) { try { URL link; if (startLine > 0) { link = new URL(String.format(sourceFileLinkFormatWithLine, m.group(1), startLine, startLine - 10, endLine)); } else { link = new URL(String.format(sourceFileLinkFormat, m.group(1))); } return link; } catch (Exception e) { AnalysisContext.logError("Error generating source link for " + src, e); } } return null; }
public ReportedBug(BugInstance bugInstance) { this.type = bugInstance.getType(); this.message = bugInstance.getMessageWithoutPrefix(); this.className = bugInstance.getPrimarySourceLineAnnotation().getClassName(); this.startLine = bugInstance.getPrimarySourceLineAnnotation().getStartLine(); this.sourceFile = bugInstance.getPrimarySourceLineAnnotation().getSourcePath(); Matcher m = SOURCE_FILE_PATTERN.matcher(sourceFile); if (m.find()) { this.classFile = m.group(1).replaceAll("/","."); } else { this.classFile = className; } }
private String printBug(BugInstance bug, List<AnalyzerConfig.Path> sources) { final int rank = BugRanker.findRank(bug); final SourceLineAnnotation line = bug.getPrimarySourceLineAnnotation(); final int startLine = line.getStartLine() <= 0 ? 0 : line.getStartLine(); final String msg = bug.getMessage(); final int pos = msg.indexOf(':'); final String message = msg.substring(pos + 2).replace('\n', ' '); return String.format("%2d %-8s %-45s %s:%d %s", rank, priority(bug), bug.getType(), sourcePath(line.getSourcePath(), sources), startLine, message); }
private String printBug(BugInstance bug, List<AnalyzerConfig.Path> sources) { final int rank = BugRanker.findRank(bug); final SourceLineAnnotation line = bug.getPrimarySourceLineAnnotation(); final int startLine = line.getStartLine() <= 0 ? 0 : line.getStartLine(); final String msg = bug.getMessage(); final int pos = msg.indexOf(':'); final String message = msg.substring(pos + 2).replace('\n', ' '); return String.format("%2d %-8s %-45s %s:%d %s", rank, priority(bug), bug.getType(), sourcePath(line.getSourcePath(), sources), startLine, message); }
/** * @param src * @param sourceAnnotation */ private void highlight(JavaSourceDocument src, SourceLineAnnotation sourceAnnotation, Color color) { int startLine = sourceAnnotation.getStartLine(); if (startLine == -1) { return; } String sourceFile = sourceAnnotation.getSourcePath(); String sourceFile2 = src.getSourceFile().getFullFileName(); if (!java.io.File.separator.equals(String.valueOf(SourceLineAnnotation.CANONICAL_PACKAGE_SEPARATOR))) { sourceFile2 = sourceFile2.replace(java.io.File.separatorChar, SourceLineAnnotation.CANONICAL_PACKAGE_SEPARATOR); } if (!sourceFile2.endsWith(sourceFile)) { return; } src.getHighlightInformation().setHighlight(startLine, sourceAnnotation.getEndLine(), color); }
@Override public void writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary) throws IOException { String classname = getClassName(); String sourcePath = getSourcePath();