poptreeitem fix

This commit is contained in:
Jindra Petk
2013-04-13 18:25:48 +02:00
parent e9d0900908
commit 116bf760f0
12 changed files with 58 additions and 17 deletions

View File

@@ -70,7 +70,9 @@ public class ForEachInTreeItem extends LoopItem implements Block {
ret += "loop" + loop.id + ":\r\n";
ret += hilight("for each (") + expression.toString(localData) + ")\r\n{\r\n";
for (GraphTargetItem ti : commands) {
ret += ti.toStringSemicoloned(localData) + "\r\n";
if (!ti.isEmpty()) {
ret += ti.toStringSemicoloned(localData) + "\r\n";
}
}
ret += hilight("}") + "\r\n";
ret += ":loop" + loop.id;

View File

@@ -70,7 +70,9 @@ public class ForInTreeItem extends LoopItem implements Block {
ret += "loop" + loop.id + ":\r\n";
ret += hilight("for (") + expression.toString(localData) + hilight(")") + "\r\n{\r\n";
for (GraphTargetItem ti : commands) {
ret += ti.toStringSemicoloned(localData) + "\r\n";
if (!ti.isEmpty()) {
ret += ti.toStringSemicoloned(localData) + "\r\n";
}
}
ret += hilight("}") + "\r\n";
ret += ":loop" + loop.id;

View File

@@ -56,21 +56,27 @@ public class TryTreeItem extends TreeItem implements Block {
String ret = "";
ret += "try\r\n{\r\n";
for (GraphTargetItem ti : tryCommands) {
ret += ti.toStringSemicoloned(Helper.toList(constants, localRegNames, fullyQualifiedNames)) + "\r\n";
if (!ti.isEmpty()) {
ret += ti.toStringSemicoloned(Helper.toList(constants, localRegNames, fullyQualifiedNames)) + "\r\n";
}
}
ret += "}";
for (int e = 0; e < catchExceptions.size(); e++) {
ret += "\r\ncatch(" + catchExceptions.get(e).getVarName(constants, fullyQualifiedNames) + ":" + catchExceptions.get(e).getTypeName(constants, fullyQualifiedNames) + ")\r\n{\r\n";
List<GraphTargetItem> commands = catchCommands.get(e);
for (GraphTargetItem ti : commands) {
ret += ti.toStringSemicoloned(Helper.toList(constants, localRegNames, fullyQualifiedNames)) + "\r\n";
if (!ti.isEmpty()) {
ret += ti.toStringSemicoloned(Helper.toList(constants, localRegNames, fullyQualifiedNames)) + "\r\n";
}
}
ret += "}";
}
if (finallyCommands.size() > 0) {
ret += "\r\nfinally\r\n{\r\n";
for (GraphTargetItem ti : finallyCommands) {
ret += ti.toStringSemicoloned(Helper.toList(constants, localRegNames, fullyQualifiedNames)) + "\r\n";
if (!ti.isEmpty()) {
ret += ti.toStringSemicoloned(Helper.toList(constants, localRegNames, fullyQualifiedNames)) + "\r\n";
}
}
ret += "}";
}

View File

@@ -37,4 +37,9 @@ public class PopTreeItem extends TreeItem {
public boolean needsSemicolon() {
return false;
}
@Override
public boolean isEmpty() {
return true;
}
}

View File

@@ -55,21 +55,27 @@ public class TryTreeItem extends TreeItem implements Block {
List localData = new ArrayList();
localData.add(constants);
for (GraphTargetItem ti : tryCommands) {
ret += ti.toStringSemicoloned(localData) + "\r\n";
if (!ti.isEmpty()) {
ret += ti.toStringSemicoloned(localData) + "\r\n";
}
}
ret += "}";
for (int e = 0; e < catchExceptions.size(); e++) {
ret += "\r\ncatch(" + catchExceptions.get(e).toStringNoQuotes(localData) + ")\r\n{\r\n";
List<GraphTargetItem> commands = catchCommands.get(e);
for (GraphTargetItem ti : commands) {
ret += ti.toStringSemicoloned(localData) + "\r\n";
if (!ti.isEmpty()) {
ret += ti.toStringSemicoloned(localData) + "\r\n";
}
}
ret += "}";
}
if (finallyCommands.size() > 0) {
ret += "\r\nfinally\r\n{\r\n";
for (GraphTargetItem ti : finallyCommands) {
ret += ti.toStringSemicoloned(localData) + "\r\n";
if (!ti.isEmpty()) {
ret += ti.toStringSemicoloned(localData) + "\r\n";
}
}
ret += "}";
}

View File

@@ -48,7 +48,9 @@ public class DoWhileItem extends LoopItem implements Block {
ret += "loop" + loop.id + ":\r\n";
ret += hilight("do\r\n{") + "\r\n";
for (GraphTargetItem ti : commands) {
ret += ti.toStringSemicoloned(localData) + "\r\n";
if (!ti.isEmpty()) {
ret += ti.toStringSemicoloned(localData) + "\r\n";
}
}
ret += hilight("}\r\nwhile(") + expression.toString(localData) + hilight(");") + "\r\n";
ret += ":loop" + loop.id;

View File

@@ -72,7 +72,9 @@ public class ForTreeItem extends LoopItem implements Block {
}
ret += hilight(")") + "\r\n{\r\n";
for (GraphTargetItem ti : commands) {
ret += ti.toStringSemicoloned(localData) + "\r\n";
if (!ti.isEmpty()) {
ret += ti.toStringSemicoloned(localData) + "\r\n";
}
}
ret += hilight("}") + "\r\n";
ret += ":loop" + loop.id;

View File

@@ -1423,8 +1423,10 @@ public class Graph {
localDataList.add(o);
}
for (GraphTargetItem ti : tree) {
ret.append(ti.toStringSemicoloned(localDataList));
ret.append("\r\n");
if (!ti.isEmpty()) {
ret.append(ti.toStringSemicoloned(localDataList));
ret.append("\r\n");
}
}
String parts[] = ret.toString().split("\r\n");
ret = new StringBuilder();

View File

@@ -137,4 +137,8 @@ public abstract class GraphTargetItem {
}
return toString(localData2) + (needsNewLine() ? "\r\n" : "");
}
public boolean isEmpty() {
return false;
}
}

View File

@@ -50,13 +50,17 @@ public class IfItem extends GraphTargetItem implements Block {
String ret;
ret = hilight("if(") + expression.toString(localData) + hilight(")") + "\r\n{\r\n";
for (GraphTargetItem ti : onTrue) {
ret += ti.toStringSemicoloned(localData) + "\r\n";
if (!ti.isEmpty()) {
ret += ti.toStringSemicoloned(localData) + "\r\n";
}
}
ret += hilight("}");
if (onFalse.size() > 0) {
ret += "\r\n" + hilight("else") + "\r\n" + hilight("{") + "\r\n";
for (GraphTargetItem ti : onFalse) {
ret += ti.toStringSemicoloned(localData) + "\r\n";
if (!ti.isEmpty()) {
ret += ti.toStringSemicoloned(localData) + "\r\n";
}
}
ret += hilight("}");
}

View File

@@ -57,7 +57,9 @@ public class SwitchItem extends LoopItem implements Block {
}
ret += Graph.INDENTOPEN + "\r\n";
for (int j = 0; j < caseCommands.get(i).size(); j++) {
ret += caseCommands.get(i).get(j).toStringSemicoloned(localData) + "\r\n";
if (!caseCommands.get(i).get(j).isEmpty()) {
ret += caseCommands.get(i).get(j).toStringSemicoloned(localData) + "\r\n";
}
}
ret += Graph.INDENTCLOSE + "\r\n";
}
@@ -66,7 +68,9 @@ public class SwitchItem extends LoopItem implements Block {
ret += hilight("default") + ":\r\n";
ret += Graph.INDENTOPEN + "\r\n";
for (int j = 0; j < defaultCommands.size(); j++) {
ret += defaultCommands.get(j).toStringSemicoloned(localData) + "\r\n";
if (!defaultCommands.get(j).isEmpty()) {
ret += defaultCommands.get(j).toStringSemicoloned(localData) + "\r\n";
}
}
ret += Graph.INDENTCLOSE + "\r\n";
}

View File

@@ -43,7 +43,9 @@ public class WhileItem extends LoopItem implements Block {
ret += "loop" + loop.id + ":\r\n";
ret += hilight("while(") + (expression == null ? "null" : expression.toString(localData)) + hilight(")") + "\r\n{\r\n";
for (GraphTargetItem ti : commands) {
ret += ti.toStringSemicoloned(localData) + "\r\n";
if (!ti.isEmpty()) {
ret += ti.toStringSemicoloned(localData) + "\r\n";
}
}
ret += hilight("}") + "\r\n";
ret += ":loop" + loop.id;