Block refactoring - uses same method.

Use a bit of line information to put commands on same line when needed.
This commit is contained in:
Jindra Petřík
2015-07-10 06:15:11 +02:00
parent 0ebfec640c
commit 9646a6e848
10 changed files with 49 additions and 103 deletions

View File

@@ -345,4 +345,26 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
public GraphTargetItem invert(GraphSourceItem src) {
return new NotItem(src, this);
}
public GraphTextWriter appendBlock(GraphTargetItem prevLineItem, GraphTextWriter writer, LocalData localData, List<GraphTargetItem> commands) throws InterruptedException {
int prevLine = prevLineItem == null ? 0 : prevLineItem.getLine();
writer.startBlock();
boolean first = true;
for (GraphTargetItem ti : commands) {
if (!ti.isEmpty()) {
//Use stored line information if available to place commands on same line
if (!first && (ti.getLine() < 1 || prevLine < 1 || (prevLine >= 1 && prevLine != ti.getLine()))) {
writer.newLine();
}
prevLine = ti.getLine();
first = false;
ti.toStringSemicoloned(writer, localData);
}
}
if (!first) {
writer.newLine();
}
writer.endBlock();
return writer;
}
}