mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-05-23 20:34:44 +00:00
correct marking error position
This commit is contained in:
@@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.DeobfuscatePopIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PushShortIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.parser.AVM2ParseException;
|
||||
import com.jpexs.decompiler.flash.abc.types.ABCException;
|
||||
import com.jpexs.decompiler.flash.abc.types.MethodBody;
|
||||
@@ -869,9 +870,26 @@ public class ASM3Parser {
|
||||
throw new AVM2ParseException("Case count expected", lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case AVM2Code.OPT_BYTE:
|
||||
if (parsedOperand.type == ParsedSymbol.TYPE_INTEGER) {
|
||||
long val = (long) (Long) parsedOperand.value;
|
||||
if (val < Byte.MIN_VALUE || val > Byte.MAX_VALUE) {
|
||||
throw new AVM2ParseException("Byte value expected (" + Byte.MIN_VALUE + " to " + Byte.MAX_VALUE + "). Use pushshort or pushint to push larger values", lexer.yyline());
|
||||
}
|
||||
operandsList.add((int) val);
|
||||
} else {
|
||||
throw new AVM2ParseException("Integer expected", lexer.yyline());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (parsedOperand.type == ParsedSymbol.TYPE_INTEGER) {
|
||||
operandsList.add((int) (long) (Long) parsedOperand.value);
|
||||
long val = (long) (Long) parsedOperand.value;
|
||||
if (def instanceof PushShortIns) {
|
||||
if (val < Short.MIN_VALUE || val > Short.MAX_VALUE) {
|
||||
throw new AVM2ParseException("Short value expected (" + Short.MIN_VALUE + " to " + Short.MAX_VALUE + "). Use pushint to push larger values", lexer.yyline());
|
||||
}
|
||||
}
|
||||
operandsList.add((int) val);
|
||||
} else {
|
||||
throw new AVM2ParseException("Integer expected", lexer.yyline());
|
||||
}
|
||||
|
||||
@@ -774,12 +774,14 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
|
||||
//reload();
|
||||
} catch (AVM2ParseException ex) {
|
||||
abc.script_info.get(oldIndex).delete(abc, false);
|
||||
View.showMessageDialog(this, AppStrings.translate("error.action.save").replace("%error%", ex.text).replace("%line%", "" + ex.line), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE);
|
||||
decompiledTextArea.gotoLine((int) ex.line);
|
||||
decompiledTextArea.markError();
|
||||
View.showMessageDialog(this, AppStrings.translate("error.action.save").replace("%error%", ex.text).replace("%line%", "" + ex.line), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE);
|
||||
} catch (CompilationException ex) {
|
||||
abc.script_info.get(oldIndex).delete(abc, false);
|
||||
View.showMessageDialog(this, AppStrings.translate("error.action.save").replace("%error%", ex.text).replace("%line%", "" + ex.line), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE);
|
||||
decompiledTextArea.gotoLine((int) ex.line);
|
||||
decompiledTextArea.markError();
|
||||
View.showMessageDialog(this, AppStrings.translate("error.action.save").replace("%error%", ex.text).replace("%line%", "" + ex.line), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE);
|
||||
} catch (IOException | InterruptedException ex) {
|
||||
//ignore
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.event.CaretEvent;
|
||||
import javax.swing.event.CaretListener;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.Document;
|
||||
|
||||
public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretListener {
|
||||
|
||||
@@ -221,7 +223,8 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi
|
||||
} catch (InterruptedException ex) {
|
||||
} catch (AVM2ParseException ex) {
|
||||
View.showMessageDialog(this, (ex.text + " on line " + ex.line));
|
||||
selectLine((int) ex.line);
|
||||
gotoLine((int) ex.line);
|
||||
markError();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -279,29 +282,7 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi
|
||||
setCaretPosition(lineStart);
|
||||
//requestFocus();
|
||||
}
|
||||
|
||||
public void selectLine(int line) {
|
||||
String text = getText();
|
||||
int lineCnt = 1;
|
||||
int lineStart = 0;
|
||||
int lineEnd = -1;
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
if (text.charAt(i) == '\n') {
|
||||
lineCnt++;
|
||||
if (lineCnt == line) {
|
||||
lineStart = i;
|
||||
}
|
||||
if (lineCnt == line + 1) {
|
||||
lineEnd = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lineCnt == -1) {
|
||||
lineEnd = text.length() - 1;
|
||||
}
|
||||
select(lineStart, lineEnd);
|
||||
requestFocus();
|
||||
}
|
||||
|
||||
|
||||
public Highlighting getSelectedSpecial() {
|
||||
return Highlighting.search(specialHilights, getCaretPosition());
|
||||
|
||||
@@ -23,6 +23,8 @@ import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import javax.swing.event.CaretEvent;
|
||||
import javax.swing.event.CaretListener;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.Document;
|
||||
import javax.swing.text.Element;
|
||||
import jsyntaxpane.actions.ActionUtils;
|
||||
|
||||
@@ -34,15 +36,53 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane {
|
||||
|
||||
private static final int truncateLimit = 8192;
|
||||
private int lastLine = -1;
|
||||
private boolean error = false;
|
||||
|
||||
public int getLine() {
|
||||
return lastLine;
|
||||
}
|
||||
|
||||
public void markError() {
|
||||
error = true;
|
||||
}
|
||||
|
||||
public void gotoLine(int line) {
|
||||
setCaretPosition(ActionUtils.getDocumentPosition(this, line, 0));
|
||||
}
|
||||
|
||||
public void selectLine(int line) {
|
||||
Document d = getDocument();
|
||||
String text = "";
|
||||
try {
|
||||
text = d.getText(0, d.getLength());
|
||||
} catch (BadLocationException ex) {
|
||||
//ignore
|
||||
}
|
||||
int lineCnt = 1;
|
||||
int lineStart = 0;
|
||||
int lineEnd = -1;
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
if (text.charAt(i) == '\n') {
|
||||
lineCnt++;
|
||||
if (lineCnt == line) {
|
||||
lineStart = i + 1;
|
||||
}
|
||||
if (lineCnt == line + 1) {
|
||||
lineEnd = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lineCnt == 1) {
|
||||
lineEnd = text.length() - 1;
|
||||
if (line > 1) {
|
||||
lineStart = text.length() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
select(lineStart, lineEnd);
|
||||
requestFocus();
|
||||
}
|
||||
|
||||
public LineMarkedEditorPane() {
|
||||
setOpaque(false);
|
||||
addCaretListener(new CaretListener() {
|
||||
@@ -53,6 +93,7 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane {
|
||||
int currentLine = root.getElementIndex(caretPosition);
|
||||
if (currentLine != lastLine) {
|
||||
lastLine = currentLine;
|
||||
error = false;
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
@@ -62,6 +103,7 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane {
|
||||
@Override
|
||||
public void setText(String t) {
|
||||
lastLine = -1;
|
||||
error = false;
|
||||
if (Configuration.debugMode.get() && t.length() > truncateLimit) {
|
||||
t = t.substring(0, truncateLimit) + "\r\n" + AppStrings.translate("editorTruncateWarning").replace("%chars%", Integer.toString(truncateLimit));
|
||||
}
|
||||
@@ -72,6 +114,7 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane {
|
||||
@Override
|
||||
public void setText(String t, String contentType) {
|
||||
lastLine = -1;
|
||||
error = true;
|
||||
super.setText(t, contentType);
|
||||
setCaretPosition(0); //scroll to top
|
||||
}
|
||||
@@ -80,14 +123,20 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane {
|
||||
public void paint(Graphics g) {
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
FontMetrics fontMetrics = g.getFontMetrics();
|
||||
int lh = fontMetrics.getHeight();
|
||||
int a = fontMetrics.getAscent();
|
||||
int d = fontMetrics.getDescent();
|
||||
int h = a + d;
|
||||
int rH = h;
|
||||
g.setColor(new Color(0xee, 0xee, 0xee));
|
||||
g.fillRect(0, d + lh * lastLine - 1, getWidth(), lh);
|
||||
if (lastLine > 0) {
|
||||
FontMetrics fontMetrics = g.getFontMetrics();
|
||||
int lh = fontMetrics.getHeight();
|
||||
int a = fontMetrics.getAscent();
|
||||
int d = fontMetrics.getDescent();
|
||||
int h = a + d;
|
||||
int rH = h;
|
||||
if (error) {
|
||||
g.setColor(new Color(255, 200, 200));
|
||||
} else {
|
||||
g.setColor(new Color(0xee, 0xee, 0xee));
|
||||
}
|
||||
g.fillRect(0, d + lh * lastLine - 1, getWidth(), lh);
|
||||
}
|
||||
super.paint(g);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -714,7 +714,7 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene
|
||||
String newText = lastDecompiled;
|
||||
setDecompiledText(newText);
|
||||
if (lastLine > -1) {
|
||||
decompiledEditor.gotoLine(lastLine + prefLines + 1);
|
||||
decompiledEditor.gotoLine(lastLine + prefLines + 1);
|
||||
}
|
||||
decompiledEditor.setEditable(false);
|
||||
saveDecompiledButton.setVisible(false);
|
||||
@@ -775,8 +775,9 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene
|
||||
editMode = false;
|
||||
} catch (IOException ex) {
|
||||
} catch (ActionParseException ex) {
|
||||
View.showMessageDialog(this, AppStrings.translate("error.action.save").replace("%error%", ex.text).replace("%line%", "" + ex.line), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE);
|
||||
editor.gotoLine((int) ex.line);
|
||||
editor.markError();
|
||||
View.showMessageDialog(this, AppStrings.translate("error.action.save").replace("%error%", ex.text).replace("%line%", "" + ex.line), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
break;
|
||||
case ACTION_EDIT_DECOMPILED:
|
||||
|
||||
Reference in New Issue
Block a user