All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.incava.analysis.DiffContextWriter Maven / Gradle / Ivy
package org.incava.analysis;
import java.util.List;
import org.incava.ijdk.text.LocationRange;
/**
* Writes differences with context. Actually returns the differences as strings.
* Writing is left to the invoker.
*/
public class DiffContextWriter extends DiffWriter {
public DiffContextWriter(List fromContents, List toContents) {
super(fromContents, toContents);
}
public void printFrom(StringBuilder sb, FileDiff fdiff) {
printLines(sb, true, fdiff, fdiff.getFirstLocation(), fromContents);
}
public void printTo(StringBuilder sb, FileDiff fdiff) {
printLines(sb, false, fdiff, fdiff.getSecondLocation(), toContents);
}
protected String getLine(List lines, int lidx, int fromLine, int fromColumn, int toLine, int toColumn, boolean isDelete) {
StringBuilder sb = new StringBuilder();
sb.append("! ").append(lines.get(lidx - 1)).append(EOLN);
return sb.toString();
}
protected void printLines(StringBuilder sb, boolean isDelete, FileDiff fdiff, LocationRange loc, List lines) {
int fromLine = loc.getStart().getLine();
int fromColumn = loc.getStart().getColumn();
int toLine = loc.getEnd().getLine();
int toColumn = loc.getEnd().getColumn();
for (int lnum = Math.max(0, fromLine - 4); lnum < fromLine - 1; ++lnum) {
sb.append(" ").append(lines.get(lnum));
sb.append(EOLN);
}
// PMD reports columns using tabSize == 8, so we replace tabs with
// spaces here.
// ... I loathe tabs.
for (int lidx = fromLine; lidx <= toLine; ++lidx) {
String line = getLine(lines, lidx, fromLine, fromColumn, toLine, toColumn, isDelete);
sb.append(line);
}
for (int lnum = toLine; lnum < Math.min(toLine + 3, lines.size()); ++lnum) {
sb.append(" ").append(lines.get(lnum));
sb.append(EOLN);
}
}
protected void printLines(StringBuilder sb, FileDiff fdiff) {
fdiff.printContext(this, sb);
sb.append(DiffContextWriter.EOLN);
}
}