From 459f8ecb56d559193ac1547366cc45d5cbcb0d7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sat, 30 Jul 2011 10:58:24 +0200 Subject: [PATCH] AS3: Editing return type of methods --- .../asdec/abc/gui/DecompiledEditorPane.java | 2 +- .../jpexs/asdec/abc/gui/MethodInfoPanel.java | 35 +++++++++++++++---- .../methodinfo_parser/MethodInfoParser.java | 31 ++++++++++++++-- 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/trunk/src/com/jpexs/asdec/abc/gui/DecompiledEditorPane.java b/trunk/src/com/jpexs/asdec/abc/gui/DecompiledEditorPane.java index fec84a819..06d67b52d 100644 --- a/trunk/src/com/jpexs/asdec/abc/gui/DecompiledEditorPane.java +++ b/trunk/src/com/jpexs/asdec/abc/gui/DecompiledEditorPane.java @@ -102,7 +102,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL } for (Highlighting th : traitHighlights) { if (th.offset == traitId) { - setCaretPosition(th.startPos + th.len - 1); + //setCaretPosition(th.startPos + th.len - 1); setCaretPosition(th.startPos); return; } diff --git a/trunk/src/com/jpexs/asdec/abc/gui/MethodInfoPanel.java b/trunk/src/com/jpexs/asdec/abc/gui/MethodInfoPanel.java index 779f2411e..2348b61f9 100644 --- a/trunk/src/com/jpexs/asdec/abc/gui/MethodInfoPanel.java +++ b/trunk/src/com/jpexs/asdec/abc/gui/MethodInfoPanel.java @@ -24,11 +24,14 @@ import com.jpexs.asdec.abc.methodinfo_parser.MethodInfoParser; import com.jpexs.asdec.abc.methodinfo_parser.ParseException; import com.jpexs.asdec.abc.types.MethodInfo; import com.jpexs.asdec.helpers.Helper; -import java.awt.BorderLayout; +import java.awt.Dimension; +import javax.swing.BoxLayout; +import javax.swing.JEditorPane; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; +import jsyntaxpane.syntaxkits.Flasm3MethodInfoSyntaxKit; /** * @@ -36,15 +39,24 @@ import javax.swing.JScrollPane; */ public class MethodInfoPanel extends JPanel { public LineMarkedEditorPane paramEditor; + public JEditorPane returnTypeEditor; private MethodInfo methodInfo; private ABC abc; public MethodInfoPanel() { + returnTypeEditor=new JEditorPane(); paramEditor=new LineMarkedEditorPane(); - setLayout(new BorderLayout()); - add(new JLabel("Parameters:"),BorderLayout.NORTH); - add(new JScrollPane(paramEditor), BorderLayout.CENTER); + setLayout(new BoxLayout(this,BoxLayout.PAGE_AXIS)); + add(new JLabel("Parameters:")); + add(new JScrollPane(paramEditor)); + add(new JLabel("Return value type:")); + JScrollPane jsp=new JScrollPane(returnTypeEditor); + add(jsp); paramEditor.setContentType("text/flasm3_methodinfo"); + returnTypeEditor.setContentType("text/flasm3_methodinfo"); + jsp.setMaximumSize(new Dimension(1024,25)); + Flasm3MethodInfoSyntaxKit sk=(Flasm3MethodInfoSyntaxKit)returnTypeEditor.getEditorKit(); + sk.deinstallComponent(returnTypeEditor, "jsyntaxpane.components.LineNumbersRuler"); } public void load(int methodInfoIndex,ABC abc) @@ -92,14 +104,25 @@ public class MethodInfoPanel extends JPanel { ret+=",\n... rest"; } paramEditor.setText(ret); + if(methodInfo.ret_type==0){ + returnTypeEditor.setText("*"); + }else{ + returnTypeEditor.setText("m["+methodInfo.ret_type+"]\""+Helper.escapeString(abc.constants.constant_multiname[methodInfo.ret_type].toString(abc.constants))+"\""); + } } public boolean save() { try { - MethodInfoParser.parse(paramEditor.getText(), methodInfo, abc); + MethodInfoParser.parseParams(paramEditor.getText(), methodInfo, abc); } catch (ParseException ex) { - JOptionPane.showMessageDialog(paramEditor, ex.text, "MethodInfo Error", JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(paramEditor, ex.text, "MethodInfo Params Error", JOptionPane.ERROR_MESSAGE); + return false; + } + try { + MethodInfoParser.parseReturnType(returnTypeEditor.getText(), methodInfo); + } catch (ParseException ex) { + JOptionPane.showMessageDialog(returnTypeEditor, ex.text, "MethodInfo Return type Error", JOptionPane.ERROR_MESSAGE); return false; } return true; diff --git a/trunk/src/com/jpexs/asdec/abc/methodinfo_parser/MethodInfoParser.java b/trunk/src/com/jpexs/asdec/abc/methodinfo_parser/MethodInfoParser.java index 5d5532970..1c678019a 100644 --- a/trunk/src/com/jpexs/asdec/abc/methodinfo_parser/MethodInfoParser.java +++ b/trunk/src/com/jpexs/asdec/abc/methodinfo_parser/MethodInfoParser.java @@ -32,7 +32,33 @@ import java.util.List; */ public class MethodInfoParser { - public static void parse(String text, MethodInfo update,ABC abc) throws ParseException { + public static boolean parseReturnType(String text, MethodInfo update) throws ParseException { + MethodInfoLexer lexer = new MethodInfoLexer(new ByteArrayInputStream(text.getBytes())); + ParsedSymbol symb; + int type=-1; + try { + symb = lexer.yylex(); + if(symb.type==ParsedSymbol.TYPE_STAR) + { + type=0; + }else if(symb.type==ParsedSymbol.TYPE_MULTINAME){ + type=(int)(long)(Long)symb.value; + }else{ + throw new ParseException("Multiname or * expected", lexer.yyline()); + } + symb = lexer.yylex(); + if(symb.type!=ParsedSymbol.TYPE_EOF) + { + throw new ParseException("Only one return type allowed", lexer.yyline()); + } + update.ret_type=type; + return true; + } catch (IOException ex) { + + } + return false; + } + public static boolean parseParams(String text, MethodInfo update,ABC abc) throws ParseException { MethodInfoLexer lexer = new MethodInfoLexer(new ByteArrayInputStream(text.getBytes())); List paramNames=new ArrayList(); List paramTypes=new ArrayList(); @@ -173,6 +199,7 @@ public class MethodInfoParser { symb = lexer.yylex(); } } catch (IOException iex) { + return false; } if(needsRest&&(!optionalValues.isEmpty())){ @@ -213,7 +240,7 @@ public class MethodInfoParser { update.paramNames[p]=abc.constants.forceGetStringId(paramNames.get(p)); } } - + return true; } }