decompiler: fixed incorrect line mapping after abstract and native methods

master
Egor.Ushakov 10 years ago
parent 472f68f18a
commit 4a6a658b4c
  1. 1
      src/org/jetbrains/java/decompiler/main/ClassWriter.java
  2. 2
      test/org/jetbrains/java/decompiler/BytecodeToSourceMappingTest.java
  3. BIN
      testData/classes/pkg/TestAbstractMethods.class
  4. 30
      testData/results/TestAbstractMethods.dec
  5. 26
      testData/results/TestClassSimpleBytecodeMapping.dec
  6. 6
      testData/results/TestSynchronizedMapping.dec
  7. 19
      testData/src/pkg/TestAbstractMethods.java

@ -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) {

@ -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"); }
} }

@ -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

@ -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
} }
} }
} }

@ -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
} }
} }

@ -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);
}
}
Loading…
Cancel
Save