diff --git a/trunk/src/com/jpexs/asdec/Main.java b/trunk/src/com/jpexs/asdec/Main.java index dde049acc..27c7aedd9 100644 --- a/trunk/src/com/jpexs/asdec/Main.java +++ b/trunk/src/com/jpexs/asdec/Main.java @@ -458,8 +458,6 @@ public class Main { * @param args the command line arguments */ public static void main(String[] args) throws IOException { - //updateLicenseInDir(new File("src/")); System.exit(0); //For automatic update of lincense in source files - View.setWinLookAndFeel(); loadReplacements(); if (args.length < 1) { diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/construction/NewFunctionIns.java b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/construction/NewFunctionIns.java index 99a518e9a..b1ba45b36 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/construction/NewFunctionIns.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/construction/NewFunctionIns.java @@ -26,6 +26,7 @@ import com.jpexs.asdec.abc.avm2.treemodel.NewFunctionTreeItem; import com.jpexs.asdec.abc.avm2.treemodel.TreeItem; import com.jpexs.asdec.abc.types.MethodBody; import com.jpexs.asdec.abc.types.MethodInfo; +import com.jpexs.asdec.helpers.Highlighting; import java.util.List; import java.util.Stack; @@ -42,10 +43,12 @@ public class NewFunctionIns extends InstructionDefinition { int methodIndex = ins.operands[0]; MethodBody mybody = abc.findBody(methodIndex); String bodyStr = ""; + String paramStr = ""; if (mybody != null) { - bodyStr = mybody.toString(false,isStatic, classIndex, abc, constants, method_info, false); + bodyStr = Highlighting.hilighMethodEnd()+mybody.toString(false,isStatic, classIndex, abc, constants, method_info, true)+Highlighting.hilighMethodBegin(body.method_info); + paramStr = method_info[methodIndex].getParamStr(constants,mybody,abc); } - stack.push(new NewFunctionTreeItem(ins, method_info[methodIndex].getParamStr(constants,body,abc), method_info[methodIndex].getReturnTypeStr(constants), bodyStr)); + stack.push(new NewFunctionTreeItem(ins, paramStr, method_info[methodIndex].getReturnTypeStr(constants), bodyStr)); } @Override diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/NewFunctionTreeItem.java b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/NewFunctionTreeItem.java index bcd975e2a..6e66e2b80 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/NewFunctionTreeItem.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/NewFunctionTreeItem.java @@ -35,7 +35,7 @@ public class NewFunctionTreeItem extends TreeItem { @Override public String toString(ConstantPool constants) { - return hilight("new function(" + paramStr + "):" + returnStr + "\r\n{\r\n" + functionBody + "}\r\n"); + return hilight("new function(" + paramStr + "):" + returnStr + "\r\n{\r\n") + functionBody + hilight("}\r\n"); } diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/TreeItem.java b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/TreeItem.java index 8bda35315..ac28b712c 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/TreeItem.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/TreeItem.java @@ -60,7 +60,7 @@ public abstract class TreeItem { return str; return Highlighting.hilighOffset(str, instruction.offset); } - + public boolean isFalse() { return false; } diff --git a/trunk/src/com/jpexs/asdec/abc/gui/DecompiledEditorPane.java b/trunk/src/com/jpexs/asdec/abc/gui/DecompiledEditorPane.java index 3b42b8bd8..a156ab4e3 100644 --- a/trunk/src/com/jpexs/asdec/abc/gui/DecompiledEditorPane.java +++ b/trunk/src/com/jpexs/asdec/abc/gui/DecompiledEditorPane.java @@ -36,6 +36,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL private List highlights = new ArrayList(); private List traitHighlights = new ArrayList(); + private List methodHighlights = new ArrayList(); private ABC abc; private int classIndex; public int lastTraitIndex = 0; @@ -45,9 +46,42 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL Main.abcMainFrame.detailPanel.showCard(DetailPanel.UNSUPPORTED_TRAIT_CARD); } + private boolean displayMethod(int pos,int methodIndex) + { + int bi = abc.findBodyIndex(methodIndex); + if (bi == -1) { + return false; + } + Main.abcMainFrame.detailPanel.showCard(DetailPanel.METHOD_TRAIT_CARD); + if (Main.abcMainFrame.detailPanel.methodTraitPanel.methodCodePanel.sourceTextArea.bodyIndex != bi) { + Main.abcMainFrame.detailPanel.methodTraitPanel.methodCodePanel.sourceTextArea.setBodyIndex(bi, abc); + Main.abcMainFrame.detailPanel.methodTraitPanel.methodBodyParamsPanel.loadFromBody(abc.bodies[bi]); + Main.abcMainFrame.detailPanel.methodTraitPanel.methodInfoPanel.load(abc.bodies[bi].method_info, abc); + } + boolean success=false; + for (Highlighting h : highlights) { + if ((pos >= h.startPos) && (pos < h.startPos + h.len)) { + try { + Main.abcMainFrame.detailPanel.methodTraitPanel.methodCodePanel.sourceTextArea.selectInstruction(abc.bodies[bi].code.adr2pos(h.offset)); + + } catch (ConvertException ex) { + } + success=true; + //return true; + } + } + return success; + } + public void caretUpdate(CaretEvent e) { getCaret().setVisible(true); int pos = getCaretPosition(); + for (Highlighting tm : methodHighlights) { + if ((pos >= tm.startPos) && (pos < tm.startPos + tm.len)) { + displayMethod(pos,(int)tm.offset); + return; + } + } for (Highlighting th : traitHighlights) { if ((pos >= th.startPos) && (pos < th.startPos + th.len)) { lastTraitIndex = (int) th.offset; @@ -59,26 +93,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL return; } } - int bi = abc.findBodyIndex(abc.findMethodIdByTraitId(classIndex, (int) th.offset)); - if (bi == -1) { - break; - } - Main.abcMainFrame.detailPanel.showCard(DetailPanel.METHOD_TRAIT_CARD); - if (Main.abcMainFrame.detailPanel.methodTraitPanel.methodCodePanel.sourceTextArea.bodyIndex != bi) { - Main.abcMainFrame.detailPanel.methodTraitPanel.methodCodePanel.sourceTextArea.setBodyIndex(bi, abc); - Main.abcMainFrame.detailPanel.methodTraitPanel.methodBodyParamsPanel.loadFromBody(abc.bodies[bi]); - Main.abcMainFrame.detailPanel.methodTraitPanel.methodInfoPanel.load(abc.bodies[bi].method_info, abc); - } - for (Highlighting h : highlights) { - if ((pos >= h.startPos) && (pos < h.startPos + h.len)) { - try { - Main.abcMainFrame.detailPanel.methodTraitPanel.methodCodePanel.sourceTextArea.selectInstruction(abc.bodies[bi].code.adr2pos(h.offset)); - - } catch (ConvertException ex) { - } - break; - } - } + displayMethod(pos,abc.findMethodIdByTraitId(classIndex, (int) th.offset)); return; } } @@ -90,11 +105,13 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL public String text; public List highlights; public List traitHighlights; + public List methodHighlights; - public BufferedClass(String text, List highlights, List traitHighlights) { + public BufferedClass(String text, List highlights, List traitHighlights,List methodHighlights) { this.text = text; this.highlights = highlights; this.traitHighlights = traitHighlights; + this.methodHighlights = methodHighlights; } } private HashMap bufferedClasses = new HashMap(); @@ -138,13 +155,15 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL hilightedCode = abc.classToString(index, true, false); highlights = Highlighting.getInstrHighlights(hilightedCode); traitHighlights = Highlighting.getTraitHighlights(hilightedCode); + methodHighlights = Highlighting.getMethodHighlights(hilightedCode); hilightedCode = Highlighting.stripHilights(hilightedCode); - bufferedClasses.put(index, new BufferedClass(hilightedCode, highlights, traitHighlights)); + bufferedClasses.put(index, new BufferedClass(hilightedCode, highlights, traitHighlights,methodHighlights)); } else { BufferedClass bc = bufferedClasses.get(index); hilightedCode = bc.text; highlights = bc.highlights; traitHighlights = bc.traitHighlights; + methodHighlights=bc.methodHighlights; } setText(hilightedCode); this.abc = abc; diff --git a/trunk/src/com/jpexs/asdec/abc/types/MethodBody.java b/trunk/src/com/jpexs/asdec/abc/types/MethodBody.java index 1e90d3491..cda86fe53 100644 --- a/trunk/src/com/jpexs/asdec/abc/types/MethodBody.java +++ b/trunk/src/com/jpexs/asdec/abc/types/MethodBody.java @@ -24,6 +24,7 @@ import com.jpexs.asdec.abc.avm2.CodeStats; import com.jpexs.asdec.abc.avm2.ConstantPool; import com.jpexs.asdec.abc.avm2.instructions.InstructionDefinition; import com.jpexs.asdec.abc.types.traits.Traits; +import com.jpexs.asdec.helpers.Highlighting; import java.util.HashMap; @@ -85,6 +86,10 @@ public class MethodBody implements Cloneable { try { HashMap localRegNames=code.getLocalRegNamesFromDebug(abc); s += code.toSource(isStatic, classIndex, abc, constants, method_info, this, hilight); + if(hilight) + { + s=Highlighting.hilighMethod(s, this.method_info); + } if(!localRegNames.isEmpty()) { s=replaceDebugRegNames(s,localRegNames); diff --git a/trunk/src/com/jpexs/asdec/helpers/Highlighting.java b/trunk/src/com/jpexs/asdec/helpers/Highlighting.java index e4dc44b41..832d4ffb6 100644 --- a/trunk/src/com/jpexs/asdec/helpers/Highlighting.java +++ b/trunk/src/com/jpexs/asdec/helpers/Highlighting.java @@ -71,6 +71,10 @@ public class Highlighting { private static final String TRAITOPEN = "[TRAIT"; private static final String TRAITCLOSE = "]"; private static final String TRAITEND = "[/TRAIT]"; + + private static final String METHODOPEN = "[METHOD"; + private static final String METHODCLOSE = "]"; + private static final String METHODEND = "[/METHOD]"; /** @@ -83,7 +87,34 @@ public class Highlighting { public static String hilighOffset(String text, long offset) { return OFSOPEN + offset + OFSCLOSE + text + OFSEND; } + + /** + * Highlights specified text as method by adding special tags + * + * @param text Text to highlight + * @param index Methodinfo index + * @return Highlighted text + */ + public static String hilighMethod(String text, long index) { + return hilighMethodBegin(index) + text + hilighMethodEnd(); + } + /** + * Beggining of hilight of method + * @param index + * @return + */ + public static String hilighMethodBegin(long index) { + return METHODOPEN + index + METHODCLOSE; + } + + /** + * Ending of hilight of method + * @return + */ + public static String hilighMethodEnd() { + return METHODEND; + } /** * Highlights specified text as trait by adding special tags * @@ -104,6 +135,7 @@ public class Highlighting { public static String stripHilights(String text) { text = stripInstrHilights(text); text = stripTraitHilights(text); + text = stripMethodHilights(text); return text; } @@ -119,6 +151,18 @@ public class Highlighting { return text; } + /** + * Strips method highlights from the text + * + * @param text Text to strip method highlights in + * @return Text with no method highlights + */ + public static String stripMethodHilights(String text) { + text = text.replaceAll(Pattern.quote(METHODOPEN) + "[0-9]+" + Pattern.quote(METHODCLOSE), ""); + text = text.replace(METHODEND, ""); + return text; + } + /** * Strips trait highlights from the text * @@ -139,7 +183,8 @@ public class Highlighting { */ public static List getTraitHighlights(String text) { text = text.replace("\r\n", "\n"); - text = stripInstrHilights(text); + text = stripInstrHilights(text); + text = stripMethodHilights(text); List ret = new ArrayList(); int pos = 0; while (true) { @@ -151,7 +196,7 @@ public class Highlighting { int nextopenpos = text.indexOf(TRAITOPEN, openpos + 1); if (nextopenpos != -1) { - if (nextopenpos < closepos) { + if (nextopenpos < enpos) { System.err.println(text); throw new RuntimeException("Crossed highlight"); } @@ -165,6 +210,41 @@ public class Highlighting { return ret; } + /** + * Gets all method highlight objects from specified text + * + * @param text Text to get highlights from + * @return List of method highlights + */ + public static List getMethodHighlights(String text) { + text = text.replace("\r\n", "\n"); + text = stripInstrHilights(text); + text = stripTraitHilights(text); + List ret = new ArrayList(); + int pos = 0; + while (true) { + int openpos = text.indexOf(METHODOPEN); + if (openpos == -1) break; + int closepos = text.indexOf(METHODCLOSE, openpos); + int enpos = text.indexOf(METHODEND, openpos); + int textlen = enpos - closepos - METHODCLOSE.length(); + + int nextopenpos = text.indexOf(METHODOPEN, openpos + 1); + if (nextopenpos != -1) { + if (nextopenpos < enpos) { + System.err.println(text); + throw new RuntimeException("Crossed highlight"); + } + } + long offset = Long.parseLong(text.substring(openpos + METHODOPEN.length(), closepos)); + Highlighting hl = new Highlighting(pos + openpos, textlen, offset); + pos += openpos + textlen; + text = text.substring(enpos + METHODEND.length()); + ret.add(hl); + } + return ret; + } + /** * Gets all instruction highlight objects from specified text * @@ -174,6 +254,7 @@ public class Highlighting { public static List getInstrHighlights(String text) { text = text.replace("\r\n", "\n"); text = stripTraitHilights(text); + text = stripMethodHilights(text); List ret = new ArrayList(); int pos = 0; while (true) { @@ -185,7 +266,7 @@ public class Highlighting { int nextopenpos = text.indexOf(OFSOPEN, openpos + 1); if (nextopenpos != -1) { - if (nextopenpos < closepos) { + if (nextopenpos < enpos) { System.err.println(text); throw new RuntimeException("Crossed highlight"); }