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.append(';');
buffer.appendLineSeparator(); buffer.appendLineSeparator();
tracer.incrementCurrentSourceLine();
} }
else { else {
if (!clinit && !dinit) { if (!clinit && !dinit) {

View File

@ -26,9 +26,11 @@ public class BytecodeToSourceMappingTest extends SingleClassesTestBase {
protected Map<String, Object> getDecompilerOptions() { protected Map<String, Object> getDecompilerOptions() {
return new HashMap<String, Object>() {{ return new HashMap<String, Object>() {{
put(IFernflowerPreferences.BYTECODE_SOURCE_MAPPING, "1"); put(IFernflowerPreferences.BYTECODE_SOURCE_MAPPING, "1");
put(IFernflowerPreferences.DUMP_ORIGINAL_LINES, "1");
}}; }};
} }
@Test public void testSimpleBytecodeMapping() { doTest("pkg/TestClassSimpleBytecodeMapping"); } @Test public void testSimpleBytecodeMapping() { doTest("pkg/TestClassSimpleBytecodeMapping"); }
@Test public void testSynchronizedMapping() { doTest("pkg/TestSynchronizedMapping"); } @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 class TestClassSimpleBytecodeMapping {
public int test() { public int test() {
System.out.println("before"); System.out.println("before");// 12
this.run(new Runnable() { this.run(new Runnable() {// 14
public void run() { public void run() {
System.out.println("Runnable"); System.out.println("Runnable");// 17
} }
}); });
this.test2("1"); this.test2("1");// 21
if(Math.random() > 0.0D) { if(Math.random() > 0.0D) {// 23
System.out.println("0"); System.out.println("0");// 24
return 0; return 0;// 25
} else { } else {
System.out.println("1"); System.out.println("1");// 27
return 1; return 1;// 28
} }
} }
public void test2(String var1) { public void test2(String var1) {
try { try {
Integer.parseInt(var1); Integer.parseInt(var1);// 34
} catch (Exception var6) { } catch (Exception var6) {
System.out.println(var6); System.out.println(var6);
} finally { } finally {
@ -30,18 +30,18 @@ public class TestClassSimpleBytecodeMapping {
} }
void run(Runnable var1) { void run(Runnable var1) {
var1.run(); var1.run();// 49
} }
public class InnerClass2 { public class InnerClass2 {
public void print() { public void print() {
System.out.println("Inner2"); System.out.println("Inner2");// 54
} }
} }
public class InnerClass { public class InnerClass {
public void print() { public void print() {
System.out.println("Inner"); System.out.println("Inner");// 44
} }
} }
} }

View File

@ -2,13 +2,13 @@ package pkg;
public class TestSynchronizedMapping { public class TestSynchronizedMapping {
public int test(int var1) { public int test(int var1) {
synchronized(this) { synchronized(this) {// 8
return var1++; return var1++;// 9
} }
} }
public void test2(String var1) { 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);
}
}