mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-19 09:18:13 +00:00
Block refactoring - uses same method.
Use a bit of line information to put commands on same line when needed.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,13 +67,8 @@ public class DoWhileItem extends LoopItem implements Block {
|
||||
writer.append("loop").append(loop.id).append(":").newLine();
|
||||
}
|
||||
writer.append("do");
|
||||
writer.startBlock();
|
||||
for (GraphTargetItem ti : commands) {
|
||||
if (!ti.isEmpty()) {
|
||||
ti.toStringSemicoloned(writer, localData).newLine();
|
||||
}
|
||||
}
|
||||
writer.endBlock().newLine();
|
||||
appendBlock(null, writer, localData, commands);
|
||||
writer.newLine();
|
||||
writer.append("while");
|
||||
if (writer.getFormatting().spaceBeforeParenthesesWhileParentheses) {
|
||||
writer.append(" ");
|
||||
|
||||
@@ -104,13 +104,8 @@ public class ForItem extends LoopItem implements Block {
|
||||
finalCommands.get(i).toString(writer, localData);
|
||||
p++;
|
||||
}
|
||||
writer.append(")").startBlock();
|
||||
for (GraphTargetItem ti : commands) {
|
||||
if (!ti.isEmpty()) {
|
||||
ti.toStringSemicoloned(writer, localData).newLine();
|
||||
}
|
||||
}
|
||||
writer.endBlock();
|
||||
writer.append(")");
|
||||
appendBlock(expression, writer, localData, commands);
|
||||
if (writer instanceof NulWriter) {
|
||||
LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id);
|
||||
labelUsed = loopOjb.used;
|
||||
|
||||
@@ -86,13 +86,8 @@ public class IfItem extends GraphTargetItem implements Block {
|
||||
}
|
||||
writer.append("(");
|
||||
expr.toString(writer, localData);
|
||||
writer.append(")").startBlock();
|
||||
for (GraphTargetItem ti : ifBranch) {
|
||||
if (!ti.isEmpty()) {
|
||||
ti.toStringSemicoloned(writer, localData).newLine();
|
||||
}
|
||||
}
|
||||
writer.endBlock();
|
||||
writer.append(")");
|
||||
appendBlock(expr, writer, localData, ifBranch);
|
||||
if (elseBranch.size() > 0) {
|
||||
boolean elseIf = elseBranch.size() == 1 && (elseBranch.get(0) instanceof IfItem);
|
||||
if (writer.getFormatting().beginBlockOnNewLine) {
|
||||
@@ -102,21 +97,12 @@ public class IfItem extends GraphTargetItem implements Block {
|
||||
}
|
||||
writer.append("else");
|
||||
if (!elseIf) {
|
||||
writer.startBlock();
|
||||
appendBlock(expr, writer, localData, elseBranch);
|
||||
} else {
|
||||
writer.append(" ");
|
||||
elseBranch.get(0).toStringSemicoloned(writer, localData);
|
||||
}
|
||||
for (GraphTargetItem ti : elseBranch) {
|
||||
if (!ti.isEmpty()) {
|
||||
ti.toStringSemicoloned(writer, localData);
|
||||
if (!elseIf) {
|
||||
writer.newLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!elseIf) {
|
||||
writer.endBlock();
|
||||
}
|
||||
|
||||
}
|
||||
return writer;
|
||||
}
|
||||
|
||||
@@ -58,13 +58,8 @@ public class UniversalLoopItem extends LoopItem implements Block {
|
||||
if (writer.getFormatting().spaceBeforeParenthesesWhileParentheses) {
|
||||
writer.append(" ");
|
||||
}
|
||||
writer.append("(true)").startBlock();
|
||||
for (GraphTargetItem ti : commands) {
|
||||
if (!ti.isEmpty()) {
|
||||
ti.toStringSemicoloned(writer, localData).newLine();
|
||||
}
|
||||
}
|
||||
writer.endBlock();
|
||||
writer.append("(true)");
|
||||
appendBlock(null, writer, localData, commands);
|
||||
if (writer instanceof NulWriter) {
|
||||
LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id);
|
||||
labelUsed = loopOjb.used;
|
||||
|
||||
@@ -76,13 +76,7 @@ public class WhileItem extends LoopItem implements Block {
|
||||
expression.get(i).toString(writer, localData);
|
||||
}
|
||||
writer.append(")");
|
||||
writer.startBlock();
|
||||
for (GraphTargetItem ti : commands) {
|
||||
if (!ti.isEmpty()) {
|
||||
ti.toStringSemicoloned(writer, localData).newLine();
|
||||
}
|
||||
}
|
||||
writer.endBlock();
|
||||
appendBlock(expression.get(expression.size() - 1), writer, localData, commands);
|
||||
if (writer instanceof NulWriter) {
|
||||
LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id);
|
||||
labelUsed = loopOjb.used;
|
||||
|
||||
Reference in New Issue
Block a user