decompiler: map line number for catch statement
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
package org.jetbrains.java.decompiler.modules.decompiler.stats;
|
package org.jetbrains.java.decompiler.modules.decompiler.stats;
|
||||||
|
|
||||||
import org.jetbrains.java.decompiler.code.CodeConstants;
|
import org.jetbrains.java.decompiler.code.CodeConstants;
|
||||||
|
import org.jetbrains.java.decompiler.code.cfg.BasicBlock;
|
||||||
import org.jetbrains.java.decompiler.main.DecompilerContext;
|
import org.jetbrains.java.decompiler.main.DecompilerContext;
|
||||||
import org.jetbrains.java.decompiler.main.TextBuffer;
|
import org.jetbrains.java.decompiler.main.TextBuffer;
|
||||||
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer;
|
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer;
|
||||||
@@ -167,9 +168,17 @@ public class CatchStatement extends Statement {
|
|||||||
buf.appendIndent(indent).append("}");
|
buf.appendIndent(indent).append("}");
|
||||||
|
|
||||||
for (int i = 1; i < stats.size(); i++) {
|
for (int i = 1; i < stats.size(); i++) {
|
||||||
List<String> exception_types = exctstrings.get(i - 1);
|
Statement stat = stats.get(i);
|
||||||
|
// map first instruction storing the exception to the catch statement
|
||||||
|
BasicBlock block = stat.getBasichead().getBlock();
|
||||||
|
if (!block.getSeq().isEmpty() && block.getInstruction(0).opcode == CodeConstants.opc_astore) {
|
||||||
|
Integer offset = block.getOldOffset(0);
|
||||||
|
if (offset > -1) tracer.addMapping(offset);
|
||||||
|
}
|
||||||
|
|
||||||
buf.append(" catch (");
|
buf.append(" catch (");
|
||||||
|
|
||||||
|
List<String> exception_types = exctstrings.get(i - 1);
|
||||||
if (exception_types.size() > 1) { // multi-catch, Java 7 style
|
if (exception_types.size() > 1) { // multi-catch, Java 7 style
|
||||||
for (int exc_index = 1; exc_index < exception_types.size(); ++exc_index) {
|
for (int exc_index = 1; exc_index < exception_types.size(); ++exc_index) {
|
||||||
VarType exc_type = new VarType(CodeConstants.TYPE_OBJECT, 0, exception_types.get(exc_index));
|
VarType exc_type = new VarType(CodeConstants.TYPE_OBJECT, 0, exception_types.get(exc_index));
|
||||||
@@ -181,7 +190,7 @@ public class CatchStatement extends Statement {
|
|||||||
buf.append(vars.get(i - 1).toJava(indent, tracer));
|
buf.append(vars.get(i - 1).toJava(indent, tracer));
|
||||||
buf.append(") {").appendLineSeparator();
|
buf.append(") {").appendLineSeparator();
|
||||||
tracer.incrementCurrentSourceLine();
|
tracer.incrementCurrentSourceLine();
|
||||||
buf.append(ExprProcessor.jmpWrapper(stats.get(i), indent + 1, true, tracer)).appendIndent(indent)
|
buf.append(ExprProcessor.jmpWrapper(stat, indent + 1, true, tracer)).appendIndent(indent)
|
||||||
.append("}");
|
.append("}");
|
||||||
}
|
}
|
||||||
buf.appendLineSeparator();
|
buf.appendLineSeparator();
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class TestClassSimpleBytecodeMapping {
|
|||||||
public void test2(String var1) {
|
public void test2(String var1) {
|
||||||
try {
|
try {
|
||||||
Integer.parseInt(var1);// 34
|
Integer.parseInt(var1);// 34
|
||||||
} catch (Exception var6) {
|
} catch (Exception var6) {// 35
|
||||||
System.out.println(var6);// 36
|
System.out.println(var6);// 36
|
||||||
} finally {
|
} finally {
|
||||||
System.out.println("Finally");// 38
|
System.out.println("Finally");// 38
|
||||||
@@ -81,6 +81,7 @@ class 'pkg/TestClassSimpleBytecodeMapping' {
|
|||||||
|
|
||||||
method 'test2 (Ljava/lang/String;)V' {
|
method 'test2 (Ljava/lang/String;)V' {
|
||||||
1 22
|
1 22
|
||||||
|
10 23
|
||||||
11 24
|
11 24
|
||||||
15 24
|
15 24
|
||||||
23 26
|
23 26
|
||||||
@@ -125,6 +126,7 @@ Lines mapping:
|
|||||||
27 <-> 16
|
27 <-> 16
|
||||||
28 <-> 17
|
28 <-> 17
|
||||||
34 <-> 23
|
34 <-> 23
|
||||||
|
35 <-> 24
|
||||||
36 <-> 25
|
36 <-> 25
|
||||||
38 <-> 27
|
38 <-> 27
|
||||||
40 <-> 30
|
40 <-> 30
|
||||||
@@ -135,5 +137,4 @@ Lines mapping:
|
|||||||
54 <-> 38
|
54 <-> 38
|
||||||
55 <-> 39
|
55 <-> 39
|
||||||
Not mapped:
|
Not mapped:
|
||||||
35
|
|
||||||
39
|
39
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ public class TestTryCatchFinally {
|
|||||||
} catch (Exception var9) {
|
} catch (Exception var9) {
|
||||||
try {
|
try {
|
||||||
System.out.println("sout2");// 27
|
System.out.println("sout2");// 27
|
||||||
} catch (Exception var8) {
|
} catch (Exception var8) {// 28
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -30,7 +30,7 @@ public class TestTryCatchFinally {
|
|||||||
try {
|
try {
|
||||||
int var2 = Integer.parseInt(var1);// 51
|
int var2 = Integer.parseInt(var1);// 51
|
||||||
return var2;
|
return var2;
|
||||||
} catch (Exception var6) {
|
} catch (Exception var6) {// 52
|
||||||
System.out.println("Error" + var6);// 53
|
System.out.println("Error" + var6);// 53
|
||||||
} finally {
|
} finally {
|
||||||
System.out.println("Finally");// 55
|
System.out.println("Finally");// 55
|
||||||
@@ -48,6 +48,7 @@ class 'pkg/TestTryCatchFinally' {
|
|||||||
14 8
|
14 8
|
||||||
17 8
|
17 8
|
||||||
19 8
|
19 8
|
||||||
|
1f 9
|
||||||
2b 13
|
2b 13
|
||||||
2d 13
|
2d 13
|
||||||
30 13
|
30 13
|
||||||
@@ -68,6 +69,7 @@ class 'pkg/TestTryCatchFinally' {
|
|||||||
1 30
|
1 30
|
||||||
4 30
|
4 30
|
||||||
e 31
|
e 31
|
||||||
|
f 32
|
||||||
10 33
|
10 33
|
||||||
1a 33
|
1a 33
|
||||||
23 33
|
23 33
|
||||||
@@ -83,6 +85,7 @@ class 'pkg/TestTryCatchFinally' {
|
|||||||
Lines mapping:
|
Lines mapping:
|
||||||
24 <-> 6
|
24 <-> 6
|
||||||
27 <-> 9
|
27 <-> 9
|
||||||
|
28 <-> 10
|
||||||
34 <-> 14
|
34 <-> 14
|
||||||
36 <-> 17
|
36 <-> 17
|
||||||
39 <-> 20
|
39 <-> 20
|
||||||
@@ -91,13 +94,12 @@ Lines mapping:
|
|||||||
42 <-> 23
|
42 <-> 23
|
||||||
45 <-> 25
|
45 <-> 25
|
||||||
51 <-> 31
|
51 <-> 31
|
||||||
|
52 <-> 33
|
||||||
53 <-> 34
|
53 <-> 34
|
||||||
55 <-> 36
|
55 <-> 36
|
||||||
56 <-> 39
|
56 <-> 39
|
||||||
57 <-> 39
|
57 <-> 39
|
||||||
Not mapped:
|
Not mapped:
|
||||||
25
|
25
|
||||||
28
|
|
||||||
32
|
32
|
||||||
35
|
35
|
||||||
52
|
|
||||||
|
|||||||
Reference in New Issue
Block a user