decompiler: fixed incorrect line mapping after abstract and native methods

This commit is contained in:
Egor.Ushakov 2014-12-24 20:42:07 +03:00
parent 472f68f18a
commit 4a6a658b4c
7 changed files with 68 additions and 16 deletions

View File

@ -782,6 +782,7 @@ public class ClassWriter {
buffer.append(';');
buffer.appendLineSeparator();
tracer.incrementCurrentSourceLine();
}
else {
if (!clinit && !dinit) {

View File

@ -26,9 +26,11 @@ public class BytecodeToSourceMappingTest extends SingleClassesTestBase {
protected Map<String, Object> getDecompilerOptions() {
return new HashMap<String, Object>() {{
put(IFernflowerPreferences.BYTECODE_SOURCE_MAPPING, "1");
put(IFernflowerPreferences.DUMP_ORIGINAL_LINES, "1");
}};
}
@Test public void testSimpleBytecodeMapping() { doTest("pkg/TestClassSimpleBytecodeMapping"); }
@Test public void testSynchronizedMapping() { doTest("pkg/TestSynchronizedMapping"); }
@Test public void testAbstractMethods() { doTest("pkg/TestAbstractMethods"); }
}

Binary file not shown.

View File

@ -0,0 +1,30 @@
package pkg;
public abstract class TestAbstractMethods {
public abstract void foo();
public int test(int var1) {
return var1;// 11
}
protected abstract void foo1();
public void test2(String var1) {
System.out.println(var1);// 17
}
}
class 'pkg/TestAbstractMethods' {
method 'test (I)I' {
1 6
}
method 'test2 (Ljava/lang/String;)V' {
0 12
4 12
}
}
Lines mapping:
11 <-> 7
17 <-> 13

View File

@ -2,25 +2,25 @@ package pkg;
public class TestClassSimpleBytecodeMapping {
public int test() {
System.out.println("before");
this.run(new Runnable() {
System.out.println("before");// 12
this.run(new Runnable() {// 14
public void run() {
System.out.println("Runnable");
System.out.println("Runnable");// 17
}
});
this.test2("1");
if(Math.random() > 0.0D) {
System.out.println("0");
return 0;
this.test2("1");// 21
if(Math.random() > 0.0D) {// 23
System.out.println("0");// 24
return 0;// 25
} else {
System.out.println("1");
return 1;
System.out.println("1");// 27
return 1;// 28
}
}
public void test2(String var1) {
try {
Integer.parseInt(var1);
Integer.parseInt(var1);// 34
} catch (Exception var6) {
System.out.println(var6);
} finally {
@ -30,18 +30,18 @@ public class TestClassSimpleBytecodeMapping {
}
void run(Runnable var1) {
var1.run();
var1.run();// 49
}
public class InnerClass2 {
public void print() {
System.out.println("Inner2");
System.out.println("Inner2");// 54
}
}
public class InnerClass {
public void print() {
System.out.println("Inner");
System.out.println("Inner");// 44
}
}
}

View File

@ -2,13 +2,13 @@ package pkg;
public class TestSynchronizedMapping {
public int test(int var1) {
synchronized(this) {
return var1++;
synchronized(this) {// 8
return var1++;// 9
}
}
public void test2(String var1) {
System.out.println(var1);
System.out.println(var1);// 14
}
}

View File

@ -0,0 +1,19 @@
package pkg;
import java.lang.Override;
import java.lang.Runnable;
public abstract class TestAbstractMethods {
public abstract void foo();
public int test(int a) {
return a;
}
protected abstract void foo1();
public void test2(String a) {
System.out.println(a);
}
}