mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-15 22:32:06 +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:
@@ -94,13 +94,8 @@ public class ForEachInAVM2Item extends LoopItem implements Block {
|
||||
}
|
||||
writer.append("(");
|
||||
expression.toString(writer, localData);
|
||||
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;
|
||||
|
||||
@@ -94,13 +94,8 @@ public class ForInAVM2Item extends LoopItem implements Block {
|
||||
}
|
||||
writer.append("(");
|
||||
expression.toString(writer, localData);
|
||||
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;
|
||||
|
||||
@@ -76,13 +76,8 @@ public class TryAVM2Item extends AVM2Item implements Block {
|
||||
|
||||
@Override
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
|
||||
writer.append("try").startBlock();
|
||||
for (GraphTargetItem ti : tryCommands) {
|
||||
if (!ti.isEmpty()) {
|
||||
ti.toStringSemicoloned(writer, localData).newLine();
|
||||
}
|
||||
}
|
||||
writer.endBlock();
|
||||
writer.append("try");
|
||||
appendBlock(null, writer, localData, tryCommands);
|
||||
for (int e = 0; e < catchExceptions.size(); e++) {
|
||||
writer.newLine();
|
||||
writer.append("catch(");
|
||||
@@ -102,24 +97,13 @@ public class TryAVM2Item extends AVM2Item implements Block {
|
||||
writer.append(":");
|
||||
writer.hilightSpecial(catchExceptions.get(e).getTypeName(localData.constantsAvm2, localData.fullyQualifiedNames), HighlightSpecialType.TRY_TYPE, e);
|
||||
writer.append(")");
|
||||
writer.startBlock();
|
||||
List<GraphTargetItem> commands = catchCommands.get(e);
|
||||
for (GraphTargetItem ti : commands) {
|
||||
if (!ti.isEmpty()) {
|
||||
ti.toStringSemicoloned(writer, localData).newLine();
|
||||
}
|
||||
}
|
||||
writer.endBlock();
|
||||
appendBlock(null, writer, localData, commands);
|
||||
}
|
||||
if (finallyCommands.size() > 0) {
|
||||
writer.newLine();
|
||||
writer.append("finally").startBlock();
|
||||
for (GraphTargetItem ti : finallyCommands) {
|
||||
if (!ti.isEmpty()) {
|
||||
ti.toStringSemicoloned(writer, localData).newLine();
|
||||
}
|
||||
}
|
||||
writer.endBlock();
|
||||
writer.append("finally");
|
||||
appendBlock(null, writer, localData, finallyCommands);
|
||||
}
|
||||
return writer;
|
||||
}
|
||||
|
||||
@@ -68,13 +68,8 @@ public class TryActionItem extends ActionItem implements Block {
|
||||
|
||||
@Override
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
|
||||
writer.append("try").startBlock();
|
||||
for (GraphTargetItem ti : tryCommands) {
|
||||
if (!ti.isEmpty()) {
|
||||
ti.toStringSemicoloned(writer, localData).newLine();
|
||||
}
|
||||
}
|
||||
writer.endBlock();
|
||||
writer.append("try");
|
||||
appendBlock(null, writer, localData, tryCommands);
|
||||
for (int e = 0; e < catchExceptions.size(); e++) {
|
||||
writer.newLine();
|
||||
writer.append("catch");
|
||||
@@ -83,24 +78,14 @@ public class TryActionItem extends ActionItem implements Block {
|
||||
}
|
||||
writer.append("(");
|
||||
catchExceptions.get(e).toStringNoQuotes(writer, localData);
|
||||
writer.append(")").startBlock();
|
||||
writer.append(")");
|
||||
List<GraphTargetItem> commands = catchCommands.get(e);
|
||||
for (GraphTargetItem ti : commands) {
|
||||
if (!ti.isEmpty()) {
|
||||
ti.toStringSemicoloned(writer, localData).newLine();
|
||||
}
|
||||
}
|
||||
writer.endBlock();
|
||||
appendBlock(null, writer, localData, commands);
|
||||
}
|
||||
if (finallyCommands.size() > 0) {
|
||||
writer.newLine();
|
||||
writer.append("finally").startBlock();
|
||||
for (GraphTargetItem ti : finallyCommands) {
|
||||
if (!ti.isEmpty()) {
|
||||
ti.toStringSemicoloned(writer, localData).newLine();
|
||||
}
|
||||
}
|
||||
writer.endBlock();
|
||||
writer.append("finally");
|
||||
appendBlock(null, writer, localData, finallyCommands);
|
||||
}
|
||||
return writer;
|
||||
}
|
||||
|
||||
@@ -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