diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java b/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java index 8d9b70c08..33d95dbd7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java @@ -119,9 +119,9 @@ public class ScriptPack { Multiname name = abc.script_info[scriptIndex].traits.traits[t].getName(abc); Namespace ns = name.getNamespace(abc.constants); if ((ns.kind == Namespace.KIND_PACKAGE) || (ns.kind == Namespace.KIND_PACKAGE_INTERNAL)) { - fos.write(abc.script_info[scriptIndex].traits.traits[t].convertPackaged("", abcList, abc, false, pcode, scriptIndex, -1, false, new ArrayList(), parallel).getBytes("utf-8")); + fos.write(abc.script_info[scriptIndex].traits.traits[t].convertPackaged(null, "", abcList, abc, false, pcode, scriptIndex, -1, false, new ArrayList(), parallel).getBytes("utf-8")); } else { - fos.write(abc.script_info[scriptIndex].traits.traits[t].convert("", abcList, abc, false, pcode, scriptIndex, -1, false, new ArrayList(), parallel).getBytes("utf-8")); + fos.write(abc.script_info[scriptIndex].traits.traits[t].convert(null, "", abcList, abc, false, pcode, scriptIndex, -1, false, new ArrayList(), parallel).getBytes("utf-8")); } } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index ec37161ac..f33d712c5 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -729,10 +729,11 @@ public class AVM2Code implements Serializable { if (trait != null) { if (trait instanceof TraitFunction) { TraitFunction tf = (TraitFunction) trait; - ret.append("trait function "); - ret.append(constants.multinameToString(tf.name_index)); + ret.append("trait "); + ret.append(Highlighting.hilighSpecial(highlight, "function ", "traittype")); + ret.append(Highlighting.hilighSpecial(highlight, constants.multinameToString(tf.name_index), "traitname")); ret.append(" slotid "); - ret.append(tf.slot_index); + ret.append(Highlighting.hilighSpecial(highlight, "" + tf.slot_index, "slotid")); ret.append("\n"); } if (trait instanceof TraitMethodGetterSetter) { @@ -740,53 +741,70 @@ public class AVM2Code implements Serializable { ret.append("trait "); switch (tm.kindType) { case Trait.TRAIT_METHOD: - ret.append("method "); + ret.append(Highlighting.hilighSpecial(highlight, "method ", "traittype")); break; case Trait.TRAIT_GETTER: - ret.append("getter "); + ret.append(Highlighting.hilighSpecial(highlight, "getter ", "traittype")); break; case Trait.TRAIT_SETTER: - ret.append("setter "); + ret.append(Highlighting.hilighSpecial(highlight, "setter ", "traittype")); break; } - ret.append(constants.multinameToString(tm.name_index)); + ret.append(Highlighting.hilighSpecial(highlight, constants.multinameToString(tm.name_index), "traitname")); ret.append(" dispid "); - ret.append(tm.disp_id); + ret.append(Highlighting.hilighSpecial(highlight, "" + tm.disp_id, "dispid")); ret.append("\n"); } } if (info != null) { ret.append("method\n"); ret.append("name "); - ret.append(info.name_index == 0 ? "null" : "\"" + Helper.escapeString(info.getName(constants)) + "\""); + ret.append(Highlighting.hilighSpecial(highlight, info.name_index == 0 ? "null" : "\"" + Helper.escapeString(info.getName(constants)) + "\"", "methodname")); ret.append("\n"); if (info.flagExplicit()) { - ret.append("flag EXPLICIT\n"); + ret.append("flag "); + ret.append(Highlighting.hilighSpecial(highlight, "EXPLICIT", "flag.EXPLICIT")); + ret.append("\n"); } if (info.flagHas_optional()) { + ret.append("flag "); + ret.append(Highlighting.hilighSpecial(highlight, "HAS_OPTIONAL", "flag.HAS_OPTIONAL")); + ret.append("\n"); ret.append("flag HAS_OPTIONAL\n"); } if (info.flagHas_paramnames()) { - ret.append("flag HAS_PARAM_NAMES\n"); + ret.append("flag "); + ret.append(Highlighting.hilighSpecial(highlight, "HAS_PARAM_NAMES", "flag.HAS_PARAM_NAMES")); + ret.append("\n"); } if (info.flagIgnore_rest()) { - ret.append("flag IGNORE_REST\n"); + ret.append("flag "); + ret.append(Highlighting.hilighSpecial(highlight, "EXPLICIT", "flag.IGNORE_REST")); + ret.append("\n"); } if (info.flagNeed_activation()) { - ret.append("flag NEED_ACTIVATION\n"); + ret.append("flag "); + ret.append(Highlighting.hilighSpecial(highlight, "NEED_ACTIVATION", "flag.NEED_ACTIVATION")); + ret.append("\n"); } if (info.flagNeed_arguments()) { - ret.append("flag NEED_ARGUMENTS\n"); + ret.append("flag "); + ret.append(Highlighting.hilighSpecial(highlight, "NEED_ARGUMENTS", "flag.NEED_ARGUMENTS")); + ret.append("\n"); } if (info.flagNeed_rest()) { - ret.append("flag NEED_REST\n"); + ret.append("flag "); + ret.append(Highlighting.hilighSpecial(highlight, "NEED_REST", "flag.NEED_REST")); + ret.append("\n"); } if (info.flagSetsdxns()) { - ret.append("flag SET_DXNS\n"); + ret.append("flag "); + ret.append(Highlighting.hilighSpecial(highlight, "SET_DXNS", "flag.SET_DXNS")); + ret.append("\n"); } - for (int p : info.param_types) { + for (int p = 0; p < info.param_types.length; p++) { ret.append("param "); - ret.append(constants.multinameToString(p)); + ret.append(Highlighting.hilighSpecial(highlight, constants.multinameToString(info.param_types[p]), "param", p)); ret.append("\n"); } if (info.flagHas_paramnames()) { @@ -799,14 +817,15 @@ public class AVM2Code implements Serializable { } } if (info.flagHas_optional()) { - for (ValueKind vk : info.optional) { + for (int i = 0; i < info.optional.length; i++) { + ValueKind vk = info.optional[i]; ret.append("optional "); - ret.append(vk.toString(constants)); + ret.append(Highlighting.hilighSpecial(highlight, vk.toString(constants), "optional", i)); ret.append("\n"); } } ret.append("returns "); - ret.append(constants.multinameToString(info.ret_type)); + ret.append(Highlighting.hilighSpecial(highlight, constants.multinameToString(info.ret_type), "returns")); ret.append("\n"); } ret.append("\n"); @@ -849,10 +868,10 @@ public class AVM2Code implements Serializable { offsets.add((long) body.exceptions[e].target); ret.append(" type "); - ret.append(body.exceptions[e].type_index == 0 ? "null" : constants.constant_multiname[body.exceptions[e].type_index].toString(constants, new ArrayList())); + ret.append(Highlighting.hilighSpecial(highlight, body.exceptions[e].type_index == 0 ? "null" : constants.constant_multiname[body.exceptions[e].type_index].toString(constants, new ArrayList()), "try.type", e)); ret.append(" name "); - ret.append(body.exceptions[e].name_index == 0 ? "null" : constants.constant_multiname[body.exceptions[e].name_index].toString(constants, new ArrayList())); + ret.append(Highlighting.hilighSpecial(highlight, body.exceptions[e].name_index == 0 ? "null" : constants.constant_multiname[body.exceptions[e].name_index].toString(constants, new ArrayList()), "try.name", e)); ret.append("\n"); } @@ -1631,7 +1650,7 @@ public class AVM2Code implements Serializable { List ret = new ArrayList<>(); ret.add(localData.get(0)); //isStatic ret.add(localData.get(1)); //classIndex - ret.add(new HashMap((HashMap) localData.get(2))); + ret.add(new HashMap<>((HashMap) localData.get(2))); ret.add((Stack) ((Stack) localData.get(3)).clone()); ret.add(localData.get(4)); //constants ret.add(localData.get(5)); //method_info diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewFunctionIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewFunctionIns.java index 27479f7e1..e0e16b2f8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewFunctionIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewFunctionIns.java @@ -45,14 +45,14 @@ public class NewFunctionIns extends InstructionDefinition { String paramStr = ""; if (mybody != null) { try { - bodyStr = /*Highlighting.hilighMethodEnd() +*/ mybody.toString(path + "/inner", false, isStatic, scriptIndex, classIndex, abc, null, constants, method_info, new Stack()/*scopeStack*/, false, true, false, fullyQualifiedNames, null);// + Highlighting.hilighMethodBegin(body.method_info); + bodyStr = mybody.toString(path + "/inner", false, isStatic, scriptIndex, classIndex, abc, null, constants, method_info, new Stack()/*scopeStack*/, false, true, false, fullyQualifiedNames, null); } catch (Exception ex) { Logger.getLogger(NewFunctionIns.class.getName()).log(Level.SEVERE, "error during newfunction", ex); } - paramStr = method_info[methodIndex].getParamStr(constants, mybody, abc, fullyQualifiedNames); + paramStr = method_info[methodIndex].getParamStr(true, constants, mybody, abc, fullyQualifiedNames); } - stack.push(new NewFunctionAVM2Item(ins, "", paramStr, method_info[methodIndex].getReturnTypeStr(constants, fullyQualifiedNames), bodyStr)); + stack.push(new NewFunctionAVM2Item(ins, "", paramStr, method_info[methodIndex].getReturnTypeStr(true, constants, fullyQualifiedNames), bodyStr, methodIndex)); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/NewFunctionAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/NewFunctionAVM2Item.java index d24f3be82..a66f82028 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/NewFunctionAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/NewFunctionAVM2Item.java @@ -29,18 +29,22 @@ public class NewFunctionAVM2Item extends AVM2Item { public String returnStr; public String functionBody; public String functionName; + public int methodIndex; - public NewFunctionAVM2Item(AVM2Instruction instruction, String functionName, String paramStr, String returnStr, String functionBody) { + public NewFunctionAVM2Item(AVM2Instruction instruction, String functionName, String paramStr, String returnStr, String functionBody, int methodIndex) { super(instruction, PRECEDENCE_PRIMARY); this.paramStr = paramStr; this.returnStr = returnStr; this.functionBody = functionBody; this.functionName = functionName; + this.methodIndex = methodIndex; } @Override public String toString(boolean highlight, ConstantPool constants, HashMap localRegNames, List fullyQualifiedNames) { - String ret = hilight("function" + (!functionName.equals("") ? " " + functionName : "") + "(" + paramStr + "):" + returnStr, highlight); + String ret = hilight("function" + (!functionName.equals("") ? " " + functionName : ""), highlight); + String mhead = "(" + (highlight ? paramStr : Highlighting.stripHilights(paramStr)) + "):" + (highlight ? returnStr : Highlighting.stripHilights(returnStr)); + ret += highlight ? Highlighting.hilighMethod(mhead, methodIndex) : mhead; ret += "\r\n" + hilight("{", highlight) + "\r\n"; ret += Graph.INDENTOPEN + "\r\n"; ret += (highlight ? functionBody : Highlighting.stripHilights(functionBody)) + "\r\n"; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodInfo.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodInfo.java index 4b50387c1..7c645c933 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodInfo.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodInfo.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.abc.types; import com.jpexs.decompiler.flash.Configuration; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.helpers.Helper; import java.util.HashMap; import java.util.List; @@ -241,7 +242,7 @@ public class MethodInfo { return constants.constant_string[name_index]; } - public String getParamStr(ConstantPool constants, MethodBody body, ABC abc, List fullyQualifiedNames) { + public String getParamStr(boolean highlight, ConstantPool constants, MethodBody body, ABC abc, List fullyQualifiedNames) { HashMap localRegNames = new HashMap<>(); if (body != null) { localRegNames = body.code.getLocalRegNamesFromDebug(abc); @@ -260,36 +261,38 @@ public class MethodInfo { } paramStr += ":"; if (param_types[i] == 0) { - paramStr += "*"; + paramStr += Highlighting.hilighSpecial(highlight, "*", "param", i); } else { - paramStr += constants.constant_multiname[param_types[i]].getName(constants, fullyQualifiedNames); + paramStr += Highlighting.hilighSpecial(highlight, constants.constant_multiname[param_types[i]].getName(constants, fullyQualifiedNames), "param", i); } if (optional != null) { if (i >= param_types.length - optional.length) { - paramStr += "=" + optional[i - (param_types.length - optional.length)].toString(constants); + int optionalIndex = i - (param_types.length - optional.length); + paramStr += "=" + Highlighting.hilighSpecial(highlight, optional[optionalIndex].toString(constants), "optional", optionalIndex); } } } if (flagNeed_rest()) { + String restAdd = ""; if ((param_types != null) && (param_types.length > 0)) { - paramStr += ", "; + restAdd += ", "; } - paramStr += "... "; + restAdd += "... "; if (!localRegNames.isEmpty()) { - paramStr += localRegNames.get(param_types.length + 1); + restAdd += localRegNames.get(param_types.length + 1); } else { - paramStr += "rest"; + restAdd += "rest"; } - + paramStr += Highlighting.hilighSpecial(highlight, restAdd, "flag.NEED_REST"); } return paramStr; } - public String getReturnTypeStr(ConstantPool constants, List fullyQualifiedNames) { + public String getReturnTypeStr(boolean highlight, ConstantPool constants, List fullyQualifiedNames) { if (ret_type == 0) { - return "*"; + return Highlighting.hilighSpecial(highlight, "*", "returns"); } - return constants.constant_multiname[ret_type].getName(constants, fullyQualifiedNames); + return Highlighting.hilighSpecial(highlight, constants.constant_multiname[ret_type].getName(constants, fullyQualifiedNames), "returns"); } public void setBody(MethodBody body) { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java index c6f6189d3..671f7633f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java @@ -80,6 +80,6 @@ public class ScriptInfo { } public String convert(List abcTags, ABC abc, boolean pcode, boolean highlighting, int scriptIndex, boolean parallel) { - return traits.convert("", abcTags, abc, false, pcode, true, scriptIndex, -1, highlighting, new ArrayList(), parallel); + return traits.convert(null, "", abcTags, abc, false, pcode, true, scriptIndex, -1, highlighting, new ArrayList(), parallel); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java index 0a3c3bf57..87ef856cb 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java @@ -113,16 +113,16 @@ public abstract class Trait implements Serializable { return abc.constants.constant_multiname[name_index].toString(abc.constants, fullyQualifiedNames) + " kind=" + kindType + " metadata=" + Helper.intArrToString(metadata); } - public String convert(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean parallel) { + public String convert(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean parallel) { return abc.constants.constant_multiname[name_index].toString(abc.constants, fullyQualifiedNames) + " kind=" + kindType + " metadata=" + Helper.intArrToString(metadata); } - public String convertPackaged(String path, List abcTags, ABC abc, boolean isStatic, boolean pcod, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean parallel) { - return makePackageFromIndex(abc, name_index, convert(path, abcTags, abc, isStatic, pcod, scriptIndex, classIndex, highlight, fullyQualifiedNames, parallel)); + public String convertPackaged(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcod, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean parallel) { + return makePackageFromIndex(abc, name_index, convert(parent, path, abcTags, abc, isStatic, pcod, scriptIndex, classIndex, highlight, fullyQualifiedNames, parallel)); } - public String convertHeader(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean parallel) { - return convert(path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlight, fullyQualifiedNames, parallel).trim(); + public String convertHeader(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean parallel) { + return convert(parent, path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlight, fullyQualifiedNames, parallel).trim(); } protected String makePackageFromIndex(ABC abc, int name_index, String value) { @@ -152,7 +152,7 @@ public abstract class Trait implements Serializable { return packageName + "." + objectName; } - public void export(String directory, ABC abc, List abcList, boolean pcode, int scriptIndex, int classIndex, boolean isStatic, boolean parallel) throws IOException { + public void export(Trait parent, String directory, ABC abc, List abcList, boolean pcode, int scriptIndex, int classIndex, boolean isStatic, boolean parallel) throws IOException { Multiname name = getName(abc); Namespace ns = name.getNamespace(abc.constants); String packageName = ns.getName(abc.constants); @@ -167,7 +167,7 @@ public abstract class Trait implements Serializable { } String fileName = outDir.toString() + File.separator + objectName + ".as"; try (FileOutputStream fos = new FileOutputStream(fileName)) { - fos.write(convertPackaged("", abcList, abc, isStatic, pcode, scriptIndex, classIndex, false, new ArrayList(), parallel).getBytes()); + fos.write(convertPackaged(parent, "", abcList, abc, isStatic, pcode, scriptIndex, classIndex, false, new ArrayList(), parallel).getBytes()); } } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java index 4f691dd0c..9567770e6 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java @@ -329,13 +329,13 @@ public class TraitClass extends Trait implements TraitWithSlot { } @Override - public String convertHeader(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean parallel) { + public String convertHeader(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean parallel) { String classHeader = abc.instance_info[class_info].getClassHeaderStr(abc, fullyQualifiedNames); return classHeader; } @Override - public String convert(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean parallel) { + public String convert(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean parallel) { if (!highlight) { //Highlighting.doHighlight = false; @@ -480,9 +480,9 @@ public class TraitClass extends Trait implements TraitWithSlot { bodyIndex = abc.findBodyIndex(abc.instance_info[class_info].iinit_index); if (bodyIndex != -1) { bodyStr = ABC.addTabs(abc.bodies[bodyIndex].toString(path +/*packageName +*/ "/" + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames) + ".initializer", pcode, false, scriptIndex, class_info, abc, this, abc.constants, abc.method_info, new Stack(), false, highlight, true, fullyQualifiedNames, abc.instance_info[class_info].instance_traits), 3); - constructorParams = abc.method_info[abc.instance_info[class_info].iinit_index].getParamStr(abc.constants, abc.bodies[bodyIndex], abc, fullyQualifiedNames); + constructorParams = abc.method_info[abc.instance_info[class_info].iinit_index].getParamStr(highlight, abc.constants, abc.bodies[bodyIndex], abc, fullyQualifiedNames); } else { - constructorParams = abc.method_info[abc.instance_info[class_info].iinit_index].getParamStr(abc.constants, null, abc, fullyQualifiedNames); + constructorParams = abc.method_info[abc.instance_info[class_info].iinit_index].getParamStr(highlight, abc.constants, null, abc, fullyQualifiedNames); } toPrint = Graph.INDENT_STRING + Graph.INDENT_STRING + modifier + "function " + abc.constants.constant_multiname[abc.instance_info[class_info].name_index].getName(abc.constants, new ArrayList()/*do not want full names here*/) + "(" + constructorParams + ") {\r\n" + bodyStr + "\r\n" + Graph.INDENT_STRING + Graph.INDENT_STRING + "}"; if (highlight) { @@ -493,9 +493,9 @@ public class TraitClass extends Trait implements TraitWithSlot { //} //static variables,constants & methods - outTraits.add(abc.class_info[class_info].static_traits.convert(path +/*packageName +*/ "/" + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames), abcTags, abc, true, pcode, false, scriptIndex, class_info, highlight, fullyQualifiedNames, parallel)); + outTraits.add(abc.class_info[class_info].static_traits.convert(this, path +/*packageName +*/ "/" + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames), abcTags, abc, true, pcode, false, scriptIndex, class_info, highlight, fullyQualifiedNames, parallel)); - outTraits.add(abc.instance_info[class_info].instance_traits.convert(path +/*packageName +*/ "/" + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames), abcTags, abc, false, pcode, false, scriptIndex, class_info, highlight, fullyQualifiedNames, parallel)); + outTraits.add(abc.instance_info[class_info].instance_traits.convert(this, path +/*packageName +*/ "/" + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames), abcTags, abc, false, pcode, false, scriptIndex, class_info, highlight, fullyQualifiedNames, parallel)); StringBuilder bui = new StringBuilder(); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java index a02e0ba72..511b3c9f8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.abc.types.traits; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.types.MethodBody; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.decompiler.graph.Graph; import com.jpexs.decompiler.graph.GraphTargetItem; @@ -41,18 +42,18 @@ public class TraitFunction extends Trait implements TraitWithSlot { } @Override - public String convertHeader(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean parallel) { + public String convertHeader(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean parallel) { String modifier = getModifiers(abcTags, abc, isStatic) + " "; if (modifier.equals(" ")) { modifier = ""; } MethodBody body = abc.findBody(method_info); - return modifier + "function " + abc.constants.constant_multiname[name_index].getName(abc.constants, fullyQualifiedNames) + "(" + abc.method_info[method_info].getParamStr(abc.constants, body, abc, fullyQualifiedNames) + ") : " + abc.method_info[method_info].getReturnTypeStr(abc.constants, fullyQualifiedNames); + return modifier + Highlighting.hilighSpecial(highlight, "function ", "traittype") + Highlighting.hilighSpecial(highlight, abc.constants.constant_multiname[name_index].getName(abc.constants, fullyQualifiedNames), "traitname") + "(" + abc.method_info[method_info].getParamStr(highlight, abc.constants, body, abc, fullyQualifiedNames) + ") : " + abc.method_info[method_info].getReturnTypeStr(highlight, abc.constants, fullyQualifiedNames); } @Override - public String convert(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean parallel) { - String header = convertHeader(path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlight, fullyQualifiedNames, parallel); + public String convert(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean parallel) { + String header = convertHeader(parent, path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlight, fullyQualifiedNames, parallel); String bodyStr = ""; int bodyIndex = abc.findBodyIndex(method_info); if (bodyIndex != -1) { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java index f774ea97d..f136a3561 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.abc.types.traits; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.types.MethodBody; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.decompiler.graph.Graph; import com.jpexs.decompiler.graph.GraphTargetItem; @@ -36,7 +37,7 @@ public class TraitMethodGetterSetter extends Trait { } @Override - public String convertHeader(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean parallel) { + public String convertHeader(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean parallel) { String modifier = getModifiers(abcTags, abc, isStatic) + " "; if (modifier.equals(" ")) { modifier = ""; @@ -49,14 +50,13 @@ public class TraitMethodGetterSetter extends Trait { addKind = "set "; } MethodBody body = abc.findBody(method_info); - return modifier + "function " + addKind + getName(abc).getName(abc.constants, fullyQualifiedNames) + "(" + abc.method_info[method_info].getParamStr(abc.constants, body, abc, fullyQualifiedNames) + ") : " + abc.method_info[method_info].getReturnTypeStr(abc.constants, fullyQualifiedNames); + return modifier + Highlighting.hilighSpecial(highlight, "function " + addKind, "traittype") + Highlighting.hilighSpecial(highlight, getName(abc).getName(abc.constants, fullyQualifiedNames), "traitname") + "(" + abc.method_info[method_info].getParamStr(highlight, abc.constants, body, abc, fullyQualifiedNames) + ") : " + abc.method_info[method_info].getReturnTypeStr(highlight, abc.constants, fullyQualifiedNames); } @Override - public String convert(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean parallel) { - String header = convertHeader(path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlight, fullyQualifiedNames, parallel); - + public String convert(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean parallel) { + String header = convertHeader(parent, path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlight, fullyQualifiedNames, parallel); String bodyStr = ""; int bodyIndex = abc.findBodyIndex(method_info); if (bodyIndex != -1) { 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 d1a59ec78..c3f97d9b8 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 @@ -59,7 +59,7 @@ public class TraitSlotConst extends Trait implements TraitWithSlot { return typeStr; } - public String getNameStr(ABC abc, List fullyQualifiedNames) { + public String getNameStr(boolean highlight, ABC abc, List fullyQualifiedNames) { String typeStr = getType(abc.constants, fullyQualifiedNames); if (typeStr.equals("*")) { typeStr = ""; @@ -78,27 +78,36 @@ public class TraitSlotConst extends Trait implements TraitWithSlot { if (val != null && val.isNamespace()) { slotconst = "namespace"; } - return slotconst + " " + getName(abc).getName(abc.constants, fullyQualifiedNames) + typeStr; + return Highlighting.hilighSpecial(highlight, slotconst, "traittype") + " " + Highlighting.hilighSpecial(highlight, getName(abc).getName(abc.constants, fullyQualifiedNames), "traitname") + Highlighting.hilighSpecial(highlight, typeStr, "traittypename"); } - public String getValueStr(ABC abc, List fullyQualifiedNames) { + public String getValueStr(Trait parent, boolean highlight, 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); + valueStr = Highlighting.hilighSpecial(highlight, valueStr, "traitvalue"); } if (assignedValue != null) { - valueStr = assignedValue.toString(false, abc.constants, new HashMap(), fullyQualifiedNames); + valueStr = Highlighting.trim(assignedValue.toString(true, abc.constants, new HashMap(), fullyQualifiedNames)); + if (highlight && (parent instanceof TraitClass)) { + TraitClass tc = (TraitClass) parent; + int traitInitId = abc.class_info[tc.class_info].static_traits.traits.length + + abc.instance_info[tc.class_info].instance_traits.traits.length + 1; + int initMethod = abc.class_info[tc.class_info].cinit_index; + valueStr = Highlighting.hilighMethod(valueStr, initMethod); + valueStr = Highlighting.hilighTrait(valueStr, traitInitId); + } } return valueStr; } - public String getNameValueStr(ABC abc, List fullyQualifiedNames) { - String valueStr = getValueStr(abc, fullyQualifiedNames); - return getNameStr(abc, fullyQualifiedNames) + (valueStr == null ? "" : " = " + valueStr) + ";"; + public String getNameValueStr(Trait parent, boolean highlight, ABC abc, List fullyQualifiedNames) { + String valueStr = getValueStr(parent, highlight, abc, fullyQualifiedNames); + return getNameStr(highlight, abc, fullyQualifiedNames) + (valueStr == null ? "" : " = " + valueStr) + ";"; } public boolean isNamespace() { @@ -110,7 +119,7 @@ public class TraitSlotConst extends Trait implements TraitWithSlot { } @Override - public String convert(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean parallel) { + public String convert(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean parallel) { String modifier = getModifiers(abcTags, abc, isStatic) + " "; if (modifier.equals(" ")) { modifier = ""; @@ -130,11 +139,12 @@ public class TraitSlotConst extends Trait implements TraitWithSlot { if (!showModifier) { modifier = ""; } - String ret = Graph.INDENT_STRING + Graph.INDENT_STRING + modifier + getNameStr(abc, fullyQualifiedNames); - String valueStr = getValueStr(abc, fullyQualifiedNames); + String ret = modifier + getNameStr(highlight, abc, fullyQualifiedNames); + String valueStr = getValueStr(parent, highlight, abc, fullyQualifiedNames); + if (valueStr != null) { ret += " = "; - int befLen = ret.length(); + int befLen = Highlighting.stripHilights(Graph.INDENT_STRING + Graph.INDENT_STRING + ret).length(); String[] valueStrParts = valueStr.split("\r\n"); boolean first = true; for (int i = 0; i < valueStrParts.length; i++) { @@ -145,12 +155,14 @@ public class TraitSlotConst extends Trait implements TraitWithSlot { if (!first) { befLen += Graph.INDENT_STRING.length(); } + ret += valueStrParts[i].replace(Graph.INDENTOPEN, ""); //there can be highlights! continue; } if (Highlighting.stripHilights(valueStrParts[i]).equals(Graph.INDENTCLOSE)) { if (!first) { befLen -= Graph.INDENT_STRING.length(); } + ret += valueStrParts[i].replace(Graph.INDENTCLOSE, ""); //there can be highlights! continue; } if (!first) { @@ -163,10 +175,7 @@ public class TraitSlotConst extends Trait implements TraitWithSlot { first = false; } } - if (ret.endsWith("\r\n")) { - ret = ret.substring(0, ret.length() - 2); - } - ret += ";"; + ret = Graph.INDENT_STRING + Graph.INDENT_STRING + Highlighting.trim(ret) + ";"; return ret; } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java index fd926a44f..bd7c4a783 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java @@ -80,9 +80,11 @@ public class Traits implements Serializable { List fullyQualifiedNames; int traitIndex; boolean parallel; + Trait parent; - public TraitConvertTask(Trait trait, boolean makePackages, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlighting, List fullyQualifiedNames, int traitIndex, boolean parallel) { + public TraitConvertTask(Trait trait, Trait parent, boolean makePackages, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlighting, List fullyQualifiedNames, int traitIndex, boolean parallel) { this.trait = trait; + this.parent = parent; this.makePackages = makePackages; this.path = path; this.abcTags = abcTags; @@ -101,9 +103,9 @@ public class Traits implements Serializable { public String call() { String plus; if (makePackages) { - plus = trait.convertPackaged(path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlighting, fullyQualifiedNames, parallel); + plus = trait.convertPackaged(parent, path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlighting, fullyQualifiedNames, parallel); } else { - plus = trait.convert(path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlighting, fullyQualifiedNames, parallel); + plus = trait.convert(parent, path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlighting, fullyQualifiedNames, parallel); } if (highlighting) { int h = traitIndex; @@ -122,7 +124,7 @@ public class Traits implements Serializable { } } - public String convert(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, boolean makePackages, int scriptIndex, int classIndex, boolean highlighting, List fullyQualifiedNames, boolean parallel) { + public String convert(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, boolean makePackages, int scriptIndex, int classIndex, boolean highlighting, List fullyQualifiedNames, boolean parallel) { StringBuilder sb = new StringBuilder(); ExecutorService executor = null; List> futureResults = null; @@ -135,7 +137,7 @@ public class Traits implements Serializable { traitConvertTasks = new ArrayList<>(); } for (int t = 0; t < traits.length; t++) { - TraitConvertTask task = new TraitConvertTask(traits[t], makePackages, path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlighting, fullyQualifiedNames, t, parallel); + TraitConvertTask task = new TraitConvertTask(traits[t], parent, makePackages, path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlighting, fullyQualifiedNames, t, parallel); if (parallel) { Future future = executor.submit(task); futureResults.add(future); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/usages/ConstVarMultinameUsage.java b/trunk/src/com/jpexs/decompiler/flash/abc/usages/ConstVarMultinameUsage.java index 5678492c5..7c2a36f70 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/usages/ConstVarMultinameUsage.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/usages/ConstVarMultinameUsage.java @@ -39,10 +39,10 @@ public abstract class ConstVarMultinameUsage extends TraitMultinameUsage { return super.toString(abcTags, abc) + " " + (parentTraitIndex > -1 ? (isStatic - ? (((TraitMethodGetterSetter) abc.class_info[classIndex].static_traits.traits[parentTraitIndex]).convertHeader("", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList(), false)) - : (((TraitMethodGetterSetter) abc.instance_info[classIndex].instance_traits.traits[parentTraitIndex]).convertHeader("", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList(), false))) + ? (((TraitMethodGetterSetter) abc.class_info[classIndex].static_traits.traits[parentTraitIndex]).convertHeader(null, "", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList(), false)) + : (((TraitMethodGetterSetter) abc.instance_info[classIndex].instance_traits.traits[parentTraitIndex]).convertHeader(null, "", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList(), false))) : "") - + ((TraitSlotConst) traits.traits[traitIndex]).convertHeader("", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList(), false); + + ((TraitSlotConst) traits.traits[traitIndex]).convertHeader(null, "", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList(), false); } public int getTraitIndex() { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/usages/MethodMultinameUsage.java b/trunk/src/com/jpexs/decompiler/flash/abc/usages/MethodMultinameUsage.java index e8c8ee0f6..1eb5ddab0 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/usages/MethodMultinameUsage.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/usages/MethodMultinameUsage.java @@ -48,10 +48,10 @@ public abstract class MethodMultinameUsage extends TraitMultinameUsage { : "instance initializer") : ((parentTraitIndex > -1 ? (isStatic - ? (((TraitMethodGetterSetter) abc.class_info[classIndex].static_traits.traits[parentTraitIndex]).convertHeader("", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList(), false)) - : (((TraitMethodGetterSetter) abc.instance_info[classIndex].instance_traits.traits[parentTraitIndex]).convertHeader("", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList(), false))) + " " + ? (((TraitMethodGetterSetter) abc.class_info[classIndex].static_traits.traits[parentTraitIndex]).convertHeader(null, "", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList(), false)) + : (((TraitMethodGetterSetter) abc.instance_info[classIndex].instance_traits.traits[parentTraitIndex]).convertHeader(null, "", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList(), false))) + " " : "") - + (((TraitMethodGetterSetter) traits.traits[traitIndex]).convertHeader("", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList(), false)))); + + (((TraitMethodGetterSetter) traits.traits[traitIndex]).convertHeader(null, "", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList(), false)))); } public int getTraitIndex() { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java index 4b5f2ac7b..fdaa64445 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java @@ -43,6 +43,7 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi public ABC abc; public int bodyIndex = -1; private List disassembledHilights = new ArrayList<>(); + private List specialHilights = new ArrayList<>(); private DecompiledEditorPane decompiledEditor; private boolean ignoreCarret = false; private String name; @@ -82,6 +83,27 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi addCaretListener(this); } + public void hilighSpecial(String type, int index) { + Highlighting h2 = null; + for (Highlighting sh : specialHilights) { + if (type.equals(sh.getPropertyString("subtype"))) { + if (sh.getPropertyString("index").equals("" + index)) { + h2 = sh; + break; + } + } + } + if (h2 != null) { + ignoreCarret = true; + try { + setCaretPosition(h2.startPos); + } catch (IllegalArgumentException iex) { + } + getCaret().setVisible(true); + ignoreCarret = false; + } + } + public void hilighOffset(long offset) { if (isEditable()) { return; @@ -168,6 +190,7 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi @Override public void setText(String t) { disassembledHilights = Highlighting.getInstrHighlights(t); + specialHilights = Highlighting.getSpecialHighlights(t); t = Highlighting.stripHilights(t); super.setText(t); setCaretPosition(0); @@ -228,6 +251,10 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi requestFocus(); } + public Highlighting getSelectedSpecial() { + return Highlighting.search(specialHilights, getCaretPosition()); + } + public long getSelectedOffset() { int pos = getCaretPosition(); Highlighting lastH = null; @@ -251,5 +278,9 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi getCaret().setVisible(true); decompiledEditor.hilightOffset(getSelectedOffset()); + Highlighting spec = getSelectedSpecial(); + if (spec != null) { + decompiledEditor.hilightSpecial(spec.getPropertyString("subtype"), (int) (long) spec.getPropertyLong("index")); + } } } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/CachedDecompilation.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/CachedDecompilation.java index 04f55bcee..a207bf97d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/CachedDecompilation.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/CachedDecompilation.java @@ -45,6 +45,10 @@ public class CachedDecompilation implements Serializable { return Highlighting.getClassHighlights(hilightedText); } + public List getSpecialHighligths() { + return Highlighting.getSpecialHighlights(hilightedText); + } + public CachedDecompilation(String hilightedText) { this.hilightedText = hilightedText; this.text = Highlighting.stripHilights(hilightedText); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java index 75cee31c1..946089428 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java @@ -42,10 +42,12 @@ import javax.swing.event.CaretListener; public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretListener { private List highlights = new ArrayList<>(); + private List specialHighlights = new ArrayList<>(); private List traitHighlights = new ArrayList<>(); private List methodHighlights = new ArrayList<>(); private List classHighlights = new ArrayList<>(); private Highlighting currentMethodHighlight; + private Highlighting currentTraitHighlight; private ABC abc; private ScriptPack script; public int lastTraitIndex = 0; @@ -73,20 +75,72 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL abcPanel.detailPanel.showCard(DetailPanel.UNSUPPORTED_TRAIT_CARD, null); } + public void hilightSpecial(String type, int index) { + int startPos; + int endPos; + if (currentMethodHighlight == null) { + if (currentTraitHighlight == null) { + return; + } + startPos = currentTraitHighlight.startPos; + endPos = currentTraitHighlight.startPos + currentTraitHighlight.len; + } else { + startPos = currentMethodHighlight.startPos; + endPos = currentMethodHighlight.startPos + currentMethodHighlight.len; + } + + List allh = new ArrayList<>(); + for (Highlighting h : traitHighlights) { + if (h.getPropertyString("index").equals("" + lastTraitIndex)) { + for (Highlighting sh : specialHighlights) { + if (sh.startPos >= h.startPos && (sh.startPos + sh.len < h.startPos + h.len)) { + allh.add(h); + } + } + } + } + if (currentMethodHighlight != null) { + for (Highlighting h : specialHighlights) { + if (h.startPos >= startPos && (h.startPos + h.len < endPos)) { + allh.add(h); + } + } + } + for (Highlighting h : allh) { + if (h.getPropertyString("subtype").equals(type) && ((long) h.getPropertyLong("index") == index)) { + ignoreCarret = true; + try { + setCaretPosition(h.startPos); + } catch (IllegalArgumentException ie) { + //ignored + } + getCaret().setVisible(true); + ignoreCarret = false; + break; + } + } + } + public void hilightOffset(long offset) { if (currentMethodHighlight == null) { return; } - Highlighting h2 = Highlighting.search(highlights, "offset", "" + offset, currentMethodHighlight.startPos, currentMethodHighlight.startPos + currentMethodHighlight.len); - if (h2 != null) { - ignoreCarret = true; - try { - setCaretPosition(h2.startPos); - } catch (IllegalArgumentException ie) { - //ignored + List allh = new ArrayList<>(); + for (Highlighting h : traitHighlights) { + if (h.getPropertyString("index").equals("" + lastTraitIndex)) { + Highlighting h2 = Highlighting.search(highlights, "offset", "" + offset, h.startPos, h.startPos + h.len); + if (h2 != null) { + ignoreCarret = true; + try { + setCaretPosition(h2.startPos); + } catch (IllegalArgumentException ie) { + //ignored + } + getCaret().setVisible(true); + ignoreCarret = false; + } + } - getCaret().setVisible(true); - ignoreCarret = false; } } @@ -132,6 +186,11 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL abcPanel.detailPanel.methodTraitPanel.methodCodePanel.hilighOffset(h.getPropertyLong("offset")); success = true; } + Highlighting sh = Highlighting.search(specialHighlights, pos); + if (sh != null) { + abcPanel.detailPanel.methodTraitPanel.methodCodePanel.hilighSpecial(sh.getPropertyString("subtype"), (int) (long) sh.getPropertyLong("index")); + success = true; + } return success; } @@ -215,9 +274,9 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL } } currentTrait = null; - Highlighting th = Highlighting.search(traitHighlights, pos); - if (th != null) { - lastTraitIndex = (int) (long) th.getPropertyLong("index"); + currentTraitHighlight = Highlighting.search(traitHighlights, pos); + if (currentTraitHighlight != null) { + lastTraitIndex = (int) (long) currentTraitHighlight.getPropertyLong("index"); if ((abc != null) && (classIndex != -1)) { currentTrait = abc.findTraitByTraitId(classIndex, lastTraitIndex); isStatic = abc.isStaticTraitId(classIndex, lastTraitIndex); @@ -237,20 +296,26 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL return; } currentTrait = null; - Highlighting th = Highlighting.search(traitHighlights, pos); - if (th != null) { - lastTraitIndex = (int) (long) th.getPropertyLong("index"); - currentTrait = abc.findTraitByTraitId(classIndex, (int) (long) th.getPropertyLong("index")); + currentTraitHighlight = Highlighting.search(traitHighlights, pos); + if (currentTraitHighlight != null) { + lastTraitIndex = (int) (long) currentTraitHighlight.getPropertyLong("index"); + currentTrait = abc.findTraitByTraitId(classIndex, (int) (long) currentTraitHighlight.getPropertyLong("index")); if (currentTrait != null) { if (currentTrait instanceof TraitSlotConst) { abcPanel.detailPanel.slotConstTraitPanel.load((TraitSlotConst) currentTrait, abc, abc.isStaticTraitId(classIndex, lastTraitIndex)); abcPanel.detailPanel.showCard(DetailPanel.SLOT_CONST_TRAIT_CARD, currentTrait); abcPanel.detailPanel.setEditMode(false); + currentMethodHighlight = null; + Highlighting spec = Highlighting.search(specialHighlights, pos, "type", "special", currentTraitHighlight.startPos, currentTraitHighlight.startPos + currentTraitHighlight.len); + if (spec != null) { + abcPanel.detailPanel.slotConstTraitPanel.hilightSpecial(spec); + } + return; } } - currentMethodHighlight = th; + currentMethodHighlight = currentTraitHighlight; String name = ""; currentTrait = null; if (abc != null) { @@ -262,7 +327,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL } } - displayMethod(pos, abc.findMethodIdByTraitId(classIndex, (int) (long) th.getPropertyLong("index")), name, currentTrait, isStatic); + displayMethod(pos, abc.findMethodIdByTraitId(classIndex, (int) (long) currentTraitHighlight.getPropertyLong("index")), name, currentTrait, isStatic); return; } setNoTrait(); @@ -353,7 +418,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL } if (!cache.contains(scriptLeaf)) { for (int scriptTraitIndex : scriptLeaf.traitIndices) { - hilightedCodeBuf.append(script.traits.traits[scriptTraitIndex].convertPackaged(scriptLeaf.getPath().toString(), abcList, abc, false, false, scriptIndex, -1, true, new ArrayList(), Configuration.getConfig("parallelSpeedUp", true))); + hilightedCodeBuf.append(script.traits.traits[scriptTraitIndex].convertPackaged(null, scriptLeaf.getPath().toString(), abcList, abc, false, false, scriptIndex, -1, true, new ArrayList(), Configuration.getConfig("parallelSpeedUp", true))); } hilightedCode = hilightedCodeBuf.toString(); @@ -370,6 +435,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL } if (script == null) { highlights = new ArrayList<>(); + specialHighlights = new ArrayList<>(); traitHighlights = new ArrayList<>(); methodHighlights = new ArrayList<>(); this.script = scriptLeaf; @@ -385,6 +451,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL CachedDecompilation cd = getCached(scriptLeaf); final String hilightedCode = cd.text; highlights = cd.getHighlights(); + specialHighlights = cd.getSpecialHighligths(); traitHighlights = cd.getTraitHighlights(); methodHighlights = cd.getMethodHighlights(); classHighlights = cd.getClassHighlights(); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/DetailPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/DetailPanel.java index bf0580db1..84f0fed31 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/DetailPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/DetailPanel.java @@ -69,7 +69,7 @@ public class DetailPanel extends JPanel implements ActionListener { cardMap.put(UNSUPPORTED_TRAIT_CARD, unsupportedTraitPanel); - slotConstTraitPanel = new SlotConstTraitDetailPanel(); + slotConstTraitPanel = new SlotConstTraitDetailPanel(abcPanel.decompiledTextArea); cardMap.put(SLOT_CONST_TRAIT_CARD, slotConstTraitPanel); for (String key : cardMap.keySet()) { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/MethodCodePanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/MethodCodePanel.java index de8068f9d..b45b0ba57 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/MethodCodePanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/MethodCodePanel.java @@ -59,6 +59,10 @@ public class MethodCodePanel extends JPanel implements ActionListener { sourceTextArea.hilighOffset(offset); } + public void hilighSpecial(String type, int index) { + sourceTextArea.hilighSpecial(type, index); + } + public void setBodyIndex(int bodyIndex, ABC abc, Trait trait) { sourceTextArea.setBodyIndex(bodyIndex, abc, sourceTextArea.getName(), trait); } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/SlotConstTraitDetailPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/SlotConstTraitDetailPanel.java index 47c0966ea..b27a4e97e 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/SlotConstTraitDetailPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/SlotConstTraitDetailPanel.java @@ -23,13 +23,17 @@ import com.jpexs.decompiler.flash.abc.types.ValueKind; import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; import static com.jpexs.decompiler.flash.gui.AppStrings.translate; import com.jpexs.decompiler.flash.gui.View; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import java.awt.BorderLayout; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*; +import javax.swing.event.CaretEvent; +import javax.swing.event.CaretListener; /** * @@ -41,50 +45,55 @@ public class SlotConstTraitDetailPanel extends JPanel implements TraitDetail { private ABC abc; private TraitSlotConst trait; private boolean showWarning = false; + private List specialHilights; + private boolean ignoreCaret = false; - public SlotConstTraitDetailPanel() { + public SlotConstTraitDetailPanel(final DecompiledEditorPane editor) { slotConstEditor = new LineMarkedEditorPane(); setLayout(new BorderLayout()); - //add(new JLabel(translate("abc.detail.slotconst.typevalue")), BorderLayout.NORTH); add(new JScrollPane(slotConstEditor), BorderLayout.CENTER); - /*StyledDocument doc = warnLabel.getStyledDocument(); - SimpleAttributeSet center = new SimpleAttributeSet(); - StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER); - doc.setParagraphAttributes(0, doc.getLength(), center, false); - warnLabel.setOpaque(false); - warnLabel.setFocusable(false); - //warnLabel.setWrapStyleWord(true); - //warnLabel.setLineWrap(true); - warnLabel.setFont(new JLabel().getFont().deriveFont(Font.BOLD)); - add(warnLabel, BorderLayout.SOUTH);*/ slotConstEditor.setContentType("text/flasm3"); - //Flasm3SyntaxKit sk = (Flasm3SyntaxKit) slotConstEditor.getEditorKit(); - //sk.deinstallComponent(slotConstEditor, "jsyntaxpane.components.LineNumbersRuler"); + slotConstEditor.addCaretListener(new CaretListener() { + @Override + public void caretUpdate(CaretEvent e) { + if (ignoreCaret) { + return; + } + Highlighting spec = Highlighting.search(specialHilights, slotConstEditor.getCaretPosition()); + if (spec != null) { + editor.hilightSpecial(spec.getPropertyString("subtype"), (int) (long) spec.getPropertyLong("index")); + slotConstEditor.getCaret().setVisible(true); + } + } + }); + } + + public void hilightSpecial(Highlighting special) { + Highlighting sel = null; + for (Highlighting h : specialHilights) { + if (h.getPropertyString("subtype").equals(special.getPropertyString("subtype"))) { + if (h.getPropertyString("index").equals(special.getPropertyString("index"))) { + sel = h; + break; + } + } + } + if (sel != null) { + ignoreCaret = true; + slotConstEditor.setCaretPosition(sel.startPos); + slotConstEditor.getCaret().setVisible(true); + ignoreCaret = false; + } } public void load(TraitSlotConst trait, ABC abc, boolean isStatic) { this.abc = abc; this.trait = trait; - /*String s; - String typeStr; - if (trait.type_index > 0) { - typeStr = "m[" + trait.type_index + "]\"" + Helper.escapeString(abc.constants.constant_multiname[trait.type_index].toString(abc.constants, new ArrayList())) + "\""; - } else { - typeStr = "*"; - } - String valueStr = ""; - if (trait.value_kind != 0) { - valueStr = " = " + (new ValueKind(trait.value_index, trait.value_kind)).toString(abc.constants); - } - - s = typeStr + valueStr; - - * */ - String s = "trait " + abc.constants.multinameToString(trait.name_index) + " " + (trait.isConst() ? "const" : "slot") + " slotid " + trait.slot_id + " type " + abc.constants.multinameToString(trait.type_index) + " value " + (new ValueKind(trait.value_index, trait.value_kind).toASMString(abc.constants)); - + boolean highlight = true; + String s = "trait " + Highlighting.hilighSpecial(highlight, abc.constants.multinameToString(trait.name_index), "traitname") + " " + Highlighting.hilighSpecial(highlight, (trait.isConst() ? "const" : "slot"), "traittype") + " slotid " + Highlighting.hilighSpecial(highlight, "" + trait.slot_id, "slotid") + " type " + Highlighting.hilighSpecial(highlight, abc.constants.multinameToString(trait.type_index), "traittypename") + " value " + Highlighting.hilighSpecial(highlight, (new ValueKind(trait.value_index, trait.value_kind).toASMString(abc.constants)), "traitvalue"); + specialHilights = Highlighting.getSpecialHighlights(s); showWarning = trait.isConst() || isStatic; - //warnLabel.setVisible(trait.isConst() || isStatic); - slotConstEditor.setText(s); + slotConstEditor.setText(Highlighting.stripHilights(s)); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/TraitsListItem.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/TraitsListItem.java index c3f7e247d..abbd71f15 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/TraitsListItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/TraitsListItem.java @@ -65,9 +65,9 @@ public class TraitsListItem { @Override public String toString() { if ((type != Type.INITIALIZER) && isStatic) { - return abc.class_info[classIndex].static_traits.traits[index].convertHeader("", abcTags, abc, true, false, scriptIndex, classIndex, false, new ArrayList(), false); + return abc.class_info[classIndex].static_traits.traits[index].convertHeader(null, "", abcTags, abc, true, false, scriptIndex, classIndex, false, new ArrayList(), false); } else if ((type != Type.INITIALIZER) && (!isStatic)) { - return abc.instance_info[classIndex].instance_traits.traits[index].convertHeader("", abcTags, abc, false, false, scriptIndex, classIndex, false, new ArrayList(), false); + return abc.instance_info[classIndex].instance_traits.traits[index].convertHeader(null, "", abcTags, abc, false, false, scriptIndex, classIndex, false, new ArrayList(), false); } else if (!isStatic) { return STR_INSTANCE_INITIALIZER; } else { diff --git a/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/Highlighting.java b/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/Highlighting.java index 9a35c4be9..eb31b178c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/Highlighting.java +++ b/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/Highlighting.java @@ -231,6 +231,17 @@ public class Highlighting implements Serializable { return hilight(text, "type=instruction;offset=" + offset); } + public static String hilighSpecial(boolean higlight, String text, String type) { + return hilighSpecial(higlight, text, type, 0); + } + + public static String hilighSpecial(boolean higlight, String text, String type, long index) { + if (!higlight) { + return text; + } + return hilight(text, "type=special;subtype=" + type + ";index=" + index); + } + /** * Highlights specified text as method by adding special tags * @@ -273,7 +284,6 @@ public class Highlighting implements Serializable { * @return Text with no highlights */ public static String stripHilights(String text) { - //text = text.replace("\r\n", "\n"); List tokens = getHilightTokens(text); StringBuilder ret = new StringBuilder(); for (HilightToken token : tokens) { @@ -284,6 +294,48 @@ public class Highlighting implements Serializable { return ret.toString(); } + public static String trim(String highlighted) { + + List tokens = getHilightTokens(highlighted); + boolean first = true; + StringBuilder str = new StringBuilder(); + int lastPos = 0; + int lastLen = 0; + for (HilightToken t : tokens) { + switch (t.type) { + case TEXT: + String s = t.value; + if (first) { + while ((!s.equals("")) && "\r\n ".contains("" + s.charAt(0))) { + s = s.substring(1); + } + first = false; + } + String s2 = s; + lastLen = 0; + while ((!s2.equals("")) && "\r\n ".contains("" + s2.charAt(s2.length() - 1))) { + s2 = s2.substring(0, s2.length() - 1); + lastLen++; + } + str.append(s); + lastPos = str.length(); + break; + case HILIGHTEND: + str.append(HLCLOSE); + break; + case HILIGHTSTART: + str.append(HLOPEN); + str.append(Helper.escapeString(t.value)); + str.append(HLEND); + break; + } + } + if (lastLen > 0) { + str.replace(lastPos - lastLen, lastPos, ""); + } + return str.toString(); + } + /** * Gets all trait highlight objects from specified text * @@ -304,6 +356,16 @@ public class Highlighting implements Serializable { return getHilights(text, "type=method;"); } + /** + * Gets all special highlight objects from specified text + * + * @param text Text to get highlights from + * @return List of special highlights + */ + public static List getSpecialHighlights(String text) { + return getHilights(text, "type=special;"); + } + /** * Gets all instruction highlight objects from specified text *