mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-11 00:44:44 +00:00
AS3: Editing return type of methods
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<String> paramNames=new ArrayList<String>();
|
||||
List<Long> paramTypes=new ArrayList<Long>();
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user