From 11da7d8c689ef588298bda8ea2bf6822e8cd8779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Tue, 2 Apr 2013 22:23:40 +0200 Subject: [PATCH] Issue #38 Indentation in const/var initial value for newobject --- .../abc/avm2/treemodel/NewObjectTreeItem.java | 3 +- .../abc/types/traits/TraitSlotConst.java | 69 ++++++++++++++++--- 2 files changed, 62 insertions(+), 10 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/NewObjectTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/NewObjectTreeItem.java index c7c2b8d64..cc73a980e 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/NewObjectTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/NewObjectTreeItem.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel; import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.graph.Graph; import java.util.HashMap; import java.util.List; @@ -39,6 +40,6 @@ public class NewObjectTreeItem extends TreeItem { } params += pairs.get(n).toString(constants, localRegNames, fullyQualifiedNames); } - return hilight("{") + params + hilight("}"); + return "\r\n" +Graph.INDENTOPEN + "\r\n" + hilight("{") + "\r\n" + params + "\r\n" + hilight("}")+"\r\n"+Graph.INDENTCLOSE + "\r\n"; } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java index e5cfc1c75..355c69d44 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java @@ -21,6 +21,9 @@ import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.types.Multiname; import com.jpexs.decompiler.flash.abc.types.Namespace; import com.jpexs.decompiler.flash.abc.types.ValueKind; +import static com.jpexs.decompiler.flash.abc.types.traits.Trait.TRAIT_CONST; +import com.jpexs.decompiler.flash.graph.Graph; +import static com.jpexs.decompiler.flash.graph.Graph.INDENTOPEN; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import com.jpexs.decompiler.flash.helpers.Helper; import com.jpexs.decompiler.flash.helpers.Highlighting; @@ -53,24 +56,18 @@ public class TraitSlotConst extends Trait { return typeStr; } - public String getNameValueStr(ABC abc, List fullyQualifiedNames) { - + public String getNameStr(ABC abc, List fullyQualifiedNames) { String typeStr = getType(abc.constants, fullyQualifiedNames); if (typeStr.equals("*")) { typeStr = ""; } else { typeStr = ":" + typeStr; } - String valueStr = ""; ValueKind val = null; if (value_kind != 0) { val = new ValueKind(value_index, value_kind); - valueStr = " = " + val.toString(abc.constants); } - if (assignedValue != null) { - valueStr = " = " + Highlighting.stripHilights(assignedValue.toString(abc.constants, new HashMap(), fullyQualifiedNames)); - } String slotconst = "var"; if (kindType == TRAIT_CONST) { slotconst = "const"; @@ -78,7 +75,27 @@ public class TraitSlotConst extends Trait { if (val != null && val.isNamespace()) { slotconst = "namespace"; } - return slotconst + " " + getName(abc).getName(abc.constants, fullyQualifiedNames) + typeStr + valueStr + ";"; + return slotconst + " " + getName(abc).getName(abc.constants, fullyQualifiedNames) + typeStr; + + } + + public String getValueStr(ABC abc, List fullyQualifiedNames) { + String valueStr = null; + ValueKind val = null; + if (value_kind != 0) { + val = new ValueKind(value_index, value_kind); + valueStr = val.toString(abc.constants); + } + + if (assignedValue != null) { + valueStr = Highlighting.stripHilights(assignedValue.toString(abc.constants, new HashMap(), fullyQualifiedNames)); + } + return valueStr; + } + + public String getNameValueStr(ABC abc, List fullyQualifiedNames) { + String valueStr = getValueStr(abc, fullyQualifiedNames); + return getNameStr(abc, fullyQualifiedNames) + (valueStr == null ? "" : " = " + valueStr) + ";"; } public boolean isNamespace() { @@ -110,7 +127,41 @@ public class TraitSlotConst extends Trait { if (!showModifier) { modifier = ""; } - return ABC.IDENT_STRING + ABC.IDENT_STRING + modifier + getNameValueStr(abc, fullyQualifiedNames); + String ret = modifier + getNameStr(abc, fullyQualifiedNames); + String valueStr = getValueStr(abc, fullyQualifiedNames); + if (valueStr != null) { + ret+=" = "; + int befLen=ret.length(); + ret = ABC.IDENT_STRING + ABC.IDENT_STRING + ret; + String valueStrParts[] = valueStr.split("\r\n"); + boolean first=true; + for (int i = 0; i < valueStrParts.length; i++) { + if(valueStrParts[i].equals("")){ + continue; + } + if(Highlighting.stripHilights(valueStrParts[i]).equals(Graph.INDENTOPEN)){ + //befLen+=ABC.IDENT_STRING.length(); + continue; + } + if(Highlighting.stripHilights(valueStrParts[i]).equals(Graph.INDENTCLOSE)){ + //befLen-=ABC.IDENT_STRING.length(); + continue; + } + if(!first){ + ret+=ABC.IDENT_STRING + ABC.IDENT_STRING; + for(int j=0;j