mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-26 14:40:47 +00:00
Configurable code formatting (Indentation + brace position)
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package com.jpexs.decompiler.graph;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.graph.model.BinaryOp;
|
||||
@@ -116,7 +117,7 @@ public abstract class GraphTargetItem implements Serializable {
|
||||
public abstract GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException;
|
||||
|
||||
public String toString(LocalData localData) throws InterruptedException {
|
||||
HilightedTextWriter writer = new HilightedTextWriter(false);
|
||||
HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(),false);
|
||||
toString(writer, localData);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@@ -39,12 +39,9 @@ public class BlockItem extends GraphTargetItem {
|
||||
|
||||
@Override
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
|
||||
writer.append("{").newLine();
|
||||
writer.indent();
|
||||
writer.startBlock();
|
||||
Graph.graphToString(commands, writer, localData);
|
||||
writer.newLine();
|
||||
writer.unindent();
|
||||
return writer.append("}");
|
||||
return writer.endBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -62,16 +62,15 @@ public class DoWhileItem extends LoopItem implements Block {
|
||||
if (labelUsed) {
|
||||
writer.append("loop" + loop.id + ":").newLine();
|
||||
}
|
||||
writer.append("do").newLine();
|
||||
writer.append("{").newLine();
|
||||
writer.append("do");
|
||||
writer.startBlock();
|
||||
writer.indent();
|
||||
for (GraphTargetItem ti : commands) {
|
||||
if (!ti.isEmpty()) {
|
||||
ti.toStringSemicoloned(writer, localData).newLine();
|
||||
}
|
||||
}
|
||||
writer.unindent();
|
||||
writer.append("}").newLine();
|
||||
writer.endBlock();
|
||||
writer.append("while(");
|
||||
|
||||
for (int i = 0; i < expression.size(); i++) {
|
||||
|
||||
@@ -96,16 +96,13 @@ public class ForItem extends LoopItem implements Block {
|
||||
writer.stripSemicolon();
|
||||
p++;
|
||||
}
|
||||
writer.append(")").newLine();
|
||||
writer.append("{").newLine();
|
||||
writer.indent();
|
||||
writer.append(")").startBlock();
|
||||
for (GraphTargetItem ti : commands) {
|
||||
if (!ti.isEmpty()) {
|
||||
ti.toStringSemicoloned(writer, localData).newLine();
|
||||
}
|
||||
}
|
||||
writer.unindent();
|
||||
writer.append("}");
|
||||
writer.endBlock();
|
||||
if (writer instanceof NulWriter) {
|
||||
LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id);
|
||||
labelUsed = loopOjb.used;
|
||||
|
||||
@@ -82,28 +82,26 @@ public class IfItem extends GraphTargetItem implements Block {
|
||||
}
|
||||
writer.append("if(");
|
||||
expr.toString(writer, localData);
|
||||
writer.append(")").newLine();
|
||||
writer.append("{").newLine();
|
||||
writer.indent();
|
||||
writer.append(")").startBlock();
|
||||
for (GraphTargetItem ti : ifBranch) {
|
||||
if (!ti.isEmpty()) {
|
||||
ti.toStringSemicoloned(writer, localData).newLine();
|
||||
}
|
||||
}
|
||||
writer.unindent();
|
||||
writer.append("}");
|
||||
writer.endBlock();
|
||||
if (elseBranch.size() > 0) {
|
||||
writer.newLine();
|
||||
writer.append("else").newLine();
|
||||
writer.append("{").newLine();
|
||||
writer.indent();
|
||||
if(writer.getFormatting().beginBlockOnNewLine){
|
||||
writer.newLine();
|
||||
}else{
|
||||
writer.append(" ");
|
||||
}
|
||||
writer.append("else").startBlock();
|
||||
for (GraphTargetItem ti : elseBranch) {
|
||||
if (!ti.isEmpty()) {
|
||||
ti.toStringSemicoloned(writer, localData).newLine();
|
||||
}
|
||||
}
|
||||
writer.unindent();
|
||||
writer.append("}");
|
||||
writer.endBlock();
|
||||
}
|
||||
return writer;
|
||||
}
|
||||
|
||||
@@ -71,9 +71,7 @@ public class SwitchItem extends LoopItem implements Block {
|
||||
}
|
||||
writer.append("switch(");
|
||||
switchedObject.toString(writer, localData);
|
||||
writer.append(")").newLine();
|
||||
writer.append("{").newLine();
|
||||
writer.indent();
|
||||
writer.append(")").startBlock();
|
||||
for (int i = 0; i < caseCommands.size(); i++) {
|
||||
for (int k = 0; k < valuesMapping.size(); k++) {
|
||||
if (valuesMapping.get(k) == i) {
|
||||
@@ -103,8 +101,7 @@ public class SwitchItem extends LoopItem implements Block {
|
||||
writer.unindent();
|
||||
}
|
||||
}
|
||||
writer.unindent();
|
||||
writer.append("}").newLine();
|
||||
writer.endBlock();
|
||||
if (writer instanceof NulWriter) {
|
||||
LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id);
|
||||
labelUsed = loopOjb.used;
|
||||
|
||||
@@ -52,16 +52,13 @@ public class UniversalLoopItem extends LoopItem implements Block {
|
||||
if (labelUsed) {
|
||||
writer.append("loop" + loop.id + ":").newLine();
|
||||
}
|
||||
writer.append("while(true)").newLine();
|
||||
writer.append("{").newLine();
|
||||
writer.indent();
|
||||
writer.append("while(true)").startBlock();
|
||||
for (GraphTargetItem ti : commands) {
|
||||
if (!ti.isEmpty()) {
|
||||
ti.toStringSemicoloned(writer, localData).newLine();
|
||||
}
|
||||
}
|
||||
writer.unindent();
|
||||
writer.append("}").newLine();
|
||||
writer.endBlock();
|
||||
if (writer instanceof NulWriter) {
|
||||
LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id);
|
||||
labelUsed = loopOjb.used;
|
||||
|
||||
@@ -67,16 +67,14 @@ public class WhileItem extends LoopItem implements Block {
|
||||
}
|
||||
expression.get(i).toString(writer, localData);
|
||||
}
|
||||
writer.append(")").newLine();
|
||||
writer.append("{").newLine();
|
||||
writer.indent();
|
||||
writer.append(")");
|
||||
writer.startBlock();
|
||||
for (GraphTargetItem ti : commands) {
|
||||
if (!ti.isEmpty()) {
|
||||
ti.toStringSemicoloned(writer, localData).newLine();
|
||||
}
|
||||
}
|
||||
writer.unindent();
|
||||
writer.append("}");
|
||||
writer.endBlock();
|
||||
if (writer instanceof NulWriter) {
|
||||
LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id);
|
||||
labelUsed = loopOjb.used;
|
||||
|
||||
Reference in New Issue
Block a user