mirror of
https://github.com/moparisthebest/fernflower
synced 2025-02-16 15:00:16 -05:00
decompiler: fixed line mapping in try-catch block
This commit is contained in:
parent
d00bc545fe
commit
0d80e663ae
@ -26,7 +26,6 @@ import org.jetbrains.java.decompiler.modules.decompiler.StatEdge;
|
||||
import org.jetbrains.java.decompiler.modules.decompiler.exps.VarExprent;
|
||||
import org.jetbrains.java.decompiler.modules.decompiler.vars.VarProcessor;
|
||||
import org.jetbrains.java.decompiler.struct.gen.VarType;
|
||||
import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -113,9 +112,6 @@ public class CatchAllStatement extends Statement {
|
||||
}
|
||||
|
||||
public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
|
||||
String indstr = InterpreterUtil.getIndentString(indent);
|
||||
String indstr1 = null;
|
||||
|
||||
String new_line_separator = DecompilerContext.getNewLineSeparator();
|
||||
|
||||
TextBuffer buf = new TextBuffer();
|
||||
@ -124,7 +120,7 @@ public class CatchAllStatement extends Statement {
|
||||
|
||||
boolean labeled = isLabeled();
|
||||
if (labeled) {
|
||||
buf.append(indstr).append("label").append(this.id.toString()).append(":").append(new_line_separator);
|
||||
buf.appendIndent(indent).append("label").append(this.id.toString()).append(":").appendLineSeparator();
|
||||
tracer.incrementCurrentSourceLine();
|
||||
}
|
||||
|
||||
@ -133,33 +129,33 @@ public class CatchAllStatement extends Statement {
|
||||
!labeled && !first.isLabeled() && (lstSuccs.isEmpty() || !lstSuccs.get(0).explicit)) {
|
||||
TextBuffer content = ExprProcessor.jmpWrapper(first, indent, true, tracer);
|
||||
content.setLength(content.length() - new_line_separator.length());
|
||||
tracer.incrementCurrentSourceLine(-1);
|
||||
buf.append(content);
|
||||
}
|
||||
else {
|
||||
buf.append(indstr).append("try {").append(new_line_separator);
|
||||
buf.appendIndent(indent).append("try {").appendLineSeparator();
|
||||
tracer.incrementCurrentSourceLine();
|
||||
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer));
|
||||
buf.append(indstr).append("}");
|
||||
buf.appendIndent(indent).append("}");
|
||||
}
|
||||
|
||||
buf.append(isFinally ? " finally" :
|
||||
" catch (" + vars.get(0).toJava(indent, tracer) + ")").append(" {").append(new_line_separator);
|
||||
" catch (" + vars.get(0).toJava(indent, tracer) + ")").append(" {").appendLineSeparator();
|
||||
tracer.incrementCurrentSourceLine();
|
||||
|
||||
if (monitor != null) {
|
||||
indstr1 = InterpreterUtil.getIndentString(indent + 1);
|
||||
buf.append(indstr1).append("if(").append(monitor.toJava(indent, tracer)).append(") {").append(new_line_separator);
|
||||
buf.appendIndent(indent+1).append("if(").append(monitor.toJava(indent, tracer)).append(") {").appendLineSeparator();
|
||||
tracer.incrementCurrentSourceLine();
|
||||
}
|
||||
|
||||
buf.append(ExprProcessor.jmpWrapper(handler, indent + 1 + (monitor != null ? 1 : 0), true, tracer));
|
||||
|
||||
if (monitor != null) {
|
||||
buf.append(indstr1).append("}").append(new_line_separator);
|
||||
buf.appendIndent(indent + 1).append("}").appendLineSeparator();
|
||||
tracer.incrementCurrentSourceLine();
|
||||
}
|
||||
|
||||
buf.append(indstr).append("}").append(new_line_separator);
|
||||
buf.appendIndent(indent).append("}").appendLineSeparator();
|
||||
tracer.incrementCurrentSourceLine();
|
||||
|
||||
return buf;
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -21,8 +21,10 @@ public class TestClassSimpleBytecodeMapping {
|
||||
public void test2(String var1) {
|
||||
try {
|
||||
Integer.parseInt(var1);
|
||||
} catch (Exception var3) {
|
||||
System.out.println(var3);
|
||||
} catch (Exception var6) {
|
||||
System.out.println(var6);
|
||||
} finally {
|
||||
System.out.println("Finally");
|
||||
}
|
||||
|
||||
}
|
||||
@ -81,23 +83,23 @@ class 'pkg/TestClassSimpleBytecodeMapping' {
|
||||
}
|
||||
|
||||
method 'run (Ljava/lang/Runnable;)V' {
|
||||
1 30
|
||||
1 32
|
||||
}
|
||||
}
|
||||
|
||||
class 'pkg/TestClassSimpleBytecodeMapping$InnerClass2' {
|
||||
method 'print ()V' {
|
||||
0 35
|
||||
3 35
|
||||
5 35
|
||||
0 37
|
||||
3 37
|
||||
5 37
|
||||
}
|
||||
}
|
||||
|
||||
class 'pkg/TestClassSimpleBytecodeMapping$InnerClass' {
|
||||
method 'print ()V' {
|
||||
0 41
|
||||
3 41
|
||||
5 41
|
||||
0 43
|
||||
3 43
|
||||
5 43
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,6 +114,6 @@ Lines mapping:
|
||||
27 <-> 16
|
||||
28 <-> 17
|
||||
34 <-> 23
|
||||
42 <-> 42
|
||||
47 <-> 31
|
||||
52 <-> 36
|
||||
44 <-> 44
|
||||
49 <-> 33
|
||||
54 <-> 38
|
||||
|
@ -1,6 +1,21 @@
|
||||
package pkg;
|
||||
|
||||
public class TestTryCatchFinally {
|
||||
public void test1(String var1) {
|
||||
try {
|
||||
System.out.println("sout1");
|
||||
} catch (Exception var9) {
|
||||
try {
|
||||
System.out.println("sout2");
|
||||
} catch (Exception var8) {
|
||||
;
|
||||
}
|
||||
} finally {
|
||||
System.out.println("finally");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int test(String var1) {
|
||||
try {
|
||||
int var2 = Integer.parseInt(var1);
|
||||
|
@ -34,6 +34,8 @@ public class TestClassSimpleBytecodeMapping {
|
||||
Integer.parseInt(a);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
} finally {
|
||||
System.out.println("Finally");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,22 @@
|
||||
package pkg;
|
||||
|
||||
public class TestTryCatchFinally {
|
||||
public void test1(String x) {
|
||||
try {
|
||||
System.out.println("sout1");
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
System.out.println("sout2");
|
||||
} catch (Exception e2) {
|
||||
// Empty
|
||||
// Empty
|
||||
// Empty
|
||||
}
|
||||
} finally {
|
||||
System.out.println("finally");
|
||||
}
|
||||
}
|
||||
|
||||
public int test(String a) {
|
||||
try {
|
||||
return Integer.parseInt(a);
|
||||
|
Loading…
Reference in New Issue
Block a user