private Element addFilesToDuplicationElement(Document doc, Element duplication, Match match) { Mark mark; for (Iterator<Mark> iterator = match.iterator(); iterator.hasNext();) { mark = iterator.next(); Element file = doc.createElement("file"); file.setAttribute("line", String.valueOf(mark.getBeginLine())); file.setAttribute("path", mark.getFilename()); duplication.appendChild(file); } return duplication; }
private String setLabelFor(Match match) { Set<String> sourceIDs = new HashSet<>(match.getMarkCount()); for (Iterator<Mark> occurrences = match.iterator(); occurrences.hasNext();) { sourceIDs.add(occurrences.next().getFilename()); } String label; if (sourceIDs.size() == 1) { String sourceId = sourceIDs.iterator().next(); int separatorPos = sourceId.lastIndexOf(File.separatorChar); label = "..." + sourceId.substring(separatorPos); } else { label = String.format("(%d separate files)", sourceIDs.size()); } match.setLabel(label); return label; }
@Override public void render(Iterator<Match> matches, Writer writer) throws IOException { for (Match match; matches.hasNext();) { match = matches.next(); Mark mark; for (Iterator<Mark> iterator = match.iterator(); iterator.hasNext();) { mark = iterator.next(); writer.append(mark.getFilename()) .append('(').append(String.valueOf(mark.getBeginLine())).append("):") .append(" Between lines " + mark.getBeginLine() + " and " + (mark.getBeginLine() + match.getLineCount()) + PMD.EOL); } } writer.flush(); } }
private void renderOn(Writer writer, Match match) throws IOException { writer.append("Found a ").append(String.valueOf(match.getLineCount())).append(" line (").append(String.valueOf(match.getTokenCount())) .append(" tokens) duplication in the following files: ").append(PMD.EOL); for (Iterator<Mark> occurrences = match.iterator(); occurrences.hasNext();) { Mark mark = occurrences.next(); writer.append("Starting at line ").append(String.valueOf(mark.getBeginLine())).append(" of ").append(mark.getFilename()) .append(PMD.EOL); } writer.append(PMD.EOL); // add a line to separate the source from the desc above String source = match.getSourceCodeSlice(); if (trimLeadingWhitespace) { String[] lines = source.split('[' + PMD.EOL + ']'); int trimDepth = StringUtil.maxCommonLeadingWhitespaceForAll(lines); if (trimDepth > 0) { lines = StringUtil.trimStartOn(lines, trimDepth); } for (int i = 0; i < lines.length; i++) { writer.append(lines[i]).append(PMD.EOL); } return; } writer.append(source).append(PMD.EOL); }
writer.append(String.valueOf(mark.getLineCount())).append(separator); writer.append(StringEscapeUtils.escapeCsv(mark.getFilename())); if (marks.hasNext()) { writer.append(separator);
public static String className(Mark mark) { return className(null, mark.getFilename()); }
public static String className(Mark mark) { return className(null, mark.getFilename()); }
private Element addFilesToDuplicationElement(Document doc, Element duplication, Match match) { Mark mark; for (Iterator<Mark> iterator = match.iterator(); iterator.hasNext();) { mark = iterator.next(); Element file = doc.createElement("file"); file.setAttribute("line", String.valueOf(mark.getBeginLine())); file.setAttribute("path", mark.getFilename()); duplication.appendChild(file); } return duplication; }
private String printMatch(Match match) { final StringBuilder s = new StringBuilder(); boolean first = true; for (final Mark mark : getMarks(match)) { s.append(first ? String.format("%-4d ", match.getTokenCount()) : " "); first = false; s.append(String.format("%s:%d-%d%n", mark.getFilename(), mark.getBeginLine(), mark.getEndLine())); } return s.substring(0, s.length() - 1); }
private String setLabelFor(Match match) { Set<String> sourceIDs = new HashSet<>(match.getMarkCount()); for (Iterator<Mark> occurrences = match.iterator(); occurrences.hasNext();) { sourceIDs.add(occurrences.next().getFilename()); } String label; if (sourceIDs.size() == 1) { String sourceId = sourceIDs.iterator().next(); int separatorPos = sourceId.lastIndexOf(File.separatorChar); label = "..." + sourceId.substring(separatorPos); } else { label = String.format("(%d separate files)", sourceIDs.size()); } match.setLabel(label); return label; }
private String printMatch(Match match) { final StringBuilder s = new StringBuilder(); boolean first = true; for (final Mark mark : getMarks(match)) { s.append(first ? String.format("%-4d ", match.getTokenCount()) : " "); first = false; s.append(String.format("%s:%d-%d%n", mark.getFilename(), mark.getBeginLine(), mark.getEndLine())); } return s.substring(0, s.length() - 1); }
@Override public void render(Iterator<Match> matches, Writer writer) throws IOException { for (Match match; matches.hasNext();) { match = matches.next(); Mark mark; for (Iterator<Mark> iterator = match.iterator(); iterator.hasNext();) { mark = iterator.next(); writer.append(mark.getFilename()) .append('(').append(String.valueOf(mark.getBeginLine())).append("):") .append(" Between lines " + mark.getBeginLine() + " and " + (mark.getBeginLine() + match.getLineCount()) + PMD.EOL); } } writer.flush(); } }
/** * Checks whether the given {@link Match} is excluded. * Note: The exclusion must have been loaded before via {@link #loadExcludeFromFailuresData(String)}. * * @param errorDetail the duplication to check * @return <code>true</code> if the given duplication should be excluded, <code>false</code> otherwise. */ public boolean isExcludedFromFailure( final Match errorDetail ) { final Set<String> uniquePaths = new HashSet<>(); for ( Mark mark : errorDetail.getMarkSet() ) { uniquePaths.add( mark.getFilename() ); } return isExcludedFromFailure( uniquePaths ); }
private void renderOn(Writer writer, Match match) throws IOException { writer.append("Found a ").append(String.valueOf(match.getLineCount())).append(" line (").append(String.valueOf(match.getTokenCount())) .append(" tokens) duplication in the following files: ").append(PMD.EOL); for (Iterator<Mark> occurrences = match.iterator(); occurrences.hasNext();) { Mark mark = occurrences.next(); writer.append("Starting at line ").append(String.valueOf(mark.getBeginLine())).append(" of ").append(mark.getFilename()) .append(PMD.EOL); } writer.append(PMD.EOL); // add a line to separate the source from the desc above String source = match.getSourceCodeSlice(); if (trimLeadingWhitespace) { String[] lines = source.split('[' + PMD.EOL + ']'); int trimDepth = StringUtil.maxCommonLeadingWhitespaceForAll(lines); if (trimDepth > 0) { lines = StringUtil.trimStartOn(lines, trimDepth); } for (int i = 0; i < lines.length; i++) { writer.append(lines[i]).append(PMD.EOL); } return; } writer.append(source).append(PMD.EOL); }
writer.append(String.valueOf(mark.getLineCount())).append(separator); writer.append(StringEscapeUtils.escapeCsv(mark.getFilename())); if (marks.hasNext()) { writer.append(separator);
@Override protected ActionResult doAccept(Match issue, Ignore action) { ActionResult res = ActionResult.undecided(null); final Iterator<Mark> it = issue.iterator(); while (it.hasNext()) { final Mark mark = it.next(); final Language language = Language.byFilename(mark.getFilename()); res = res.orMoreQuality(action.accept( new NamedLocation(mark.getSourceCodeSlice(), language, PmdUtils.className(mark), "", false))); } return res; }
@Override protected ActionResult doAccept(Match issue, Ignore action) { ActionResult res = ActionResult.undecided(null); final Iterator<Mark> it = issue.iterator(); while (it.hasNext()) { final Mark mark = it.next(); final Language language = Language.byFilename(mark.getFilename()); res = res.orMoreQuality(action.accept( new NamedLocation(mark.getSourceCodeSlice(), language, PmdUtils.className(mark), "", false))); } return res; }