private Element createDuplicationElement(Document doc, Match match) { Element duplication = doc.createElement("duplication"); duplication.setAttribute("lines", String.valueOf(match.getLineCount())); duplication.setAttribute("tokens", String.valueOf(match.getTokenCount())); return duplication; } }
@Override public int compareTo(Match other) { int diff = other.getTokenCount() - getTokenCount(); if (diff != 0) { return diff; } return getFirstMark().compareTo(other.getFirstMark()); }
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(match.getLineCount())).append(separator); writer.append(String.valueOf(match.getTokenCount())).append(separator) .append(String.valueOf(match.getMarkCount())).append(separator); for (Iterator<Mark> marks = match.iterator(); marks.hasNext();) {
public int getLineCount(TokenEntry mark, Match match) { TokenEntry endTok = get(mark.getIndex() + match.getTokenCount() - 1); if (endTok == TokenEntry.EOF) { endTok = get(mark.getIndex() + match.getTokenCount() - 2); } return endTok.getBeginLine() - mark.getBeginLine() + 1; }
public int getEndIndex() { return getMark(0).getToken().getIndex() + getTokenCount() - 1; }
private Element createDuplicationElement(Document doc, Match match) { Element duplication = doc.createElement("duplication"); duplication.setAttribute("lines", String.valueOf(match.getLineCount())); duplication.setAttribute("tokens", String.valueOf(match.getTokenCount())); return duplication; } }
@Override public int compareTo(Match other) { int diff = other.getTokenCount() - getTokenCount(); if (diff != 0) { return diff; } return getFirstMark().compareTo(other.getFirstMark()); }
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 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); }
writer.append(String.valueOf(match.getLineCount())).append(separator); writer.append(String.valueOf(match.getTokenCount())).append(separator) .append(String.valueOf(match.getMarkCount())).append(separator); for (Iterator<Mark> marks = match.iterator(); marks.hasNext();) {
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); }
public int getLineCount(TokenEntry mark, Match match) { TokenEntry endTok = get(mark.getIndex() + match.getTokenCount() - 1); if (endTok == TokenEntry.EOF) { endTok = get(mark.getIndex() + match.getTokenCount() - 2); } return endTok.getBeginLine() - mark.getBeginLine() + 1; }
public int getEndIndex() { return getMark(0).getToken().getIndex() + getTokenCount() - 1; }