From 4a6a658b4c7aca95c2b351cb71c72af02d25b795 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 24 Dec 2014 20:42:07 +0300 Subject: [PATCH] decompiler: fixed incorrect line mapping after abstract and native methods --- .../java/decompiler/main/ClassWriter.java | 1 + .../BytecodeToSourceMappingTest.java | 2 ++ .../classes/pkg/TestAbstractMethods.class | Bin 0 -> 488 bytes testData/results/TestAbstractMethods.dec | 30 ++++++++++++++++++ .../TestClassSimpleBytecodeMapping.dec | 26 +++++++-------- testData/results/TestSynchronizedMapping.dec | 6 ++-- testData/src/pkg/TestAbstractMethods.java | 19 +++++++++++ 7 files changed, 68 insertions(+), 16 deletions(-) create mode 100644 testData/classes/pkg/TestAbstractMethods.class create mode 100644 testData/results/TestAbstractMethods.dec create mode 100644 testData/src/pkg/TestAbstractMethods.java diff --git a/src/org/jetbrains/java/decompiler/main/ClassWriter.java b/src/org/jetbrains/java/decompiler/main/ClassWriter.java index 9847814..e401dee 100644 --- a/src/org/jetbrains/java/decompiler/main/ClassWriter.java +++ b/src/org/jetbrains/java/decompiler/main/ClassWriter.java @@ -782,6 +782,7 @@ public class ClassWriter { buffer.append(';'); buffer.appendLineSeparator(); + tracer.incrementCurrentSourceLine(); } else { if (!clinit && !dinit) { diff --git a/test/org/jetbrains/java/decompiler/BytecodeToSourceMappingTest.java b/test/org/jetbrains/java/decompiler/BytecodeToSourceMappingTest.java index a258ca0..d84dd99 100644 --- a/test/org/jetbrains/java/decompiler/BytecodeToSourceMappingTest.java +++ b/test/org/jetbrains/java/decompiler/BytecodeToSourceMappingTest.java @@ -26,9 +26,11 @@ public class BytecodeToSourceMappingTest extends SingleClassesTestBase { protected Map getDecompilerOptions() { return new HashMap() {{ 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"); } } diff --git a/testData/classes/pkg/TestAbstractMethods.class b/testData/classes/pkg/TestAbstractMethods.class new file mode 100644 index 0000000000000000000000000000000000000000..12ff5b20d8693779a4b91e0404489652f7e83511 GIT binary patch literal 488 zcmZvYUrPc(6vfZzx})os|1wQ82ztSSxWBfDeJcj~1c3VP@R z^r50Vn_xlvaL?}Vo_pu)e15%u064;yg%pYzl(1%@jCGC*N0q@m_5)v?FeIC;8wTS{ z4h2K5>j&a;KJ`S{cfARb1`d+*$gwhJlrZe-*ife}~-K YpMF7N?-j}ADOSu2G*KjPUhhQV8!B2`X8-^I literal 0 HcmV?d00001 diff --git a/testData/results/TestAbstractMethods.dec b/testData/results/TestAbstractMethods.dec new file mode 100644 index 0000000..59b1027 --- /dev/null +++ b/testData/results/TestAbstractMethods.dec @@ -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 diff --git a/testData/results/TestClassSimpleBytecodeMapping.dec b/testData/results/TestClassSimpleBytecodeMapping.dec index e284fa5..2911513 100644 --- a/testData/results/TestClassSimpleBytecodeMapping.dec +++ b/testData/results/TestClassSimpleBytecodeMapping.dec @@ -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 } } } diff --git a/testData/results/TestSynchronizedMapping.dec b/testData/results/TestSynchronizedMapping.dec index fa411a6..ca38d8c 100644 --- a/testData/results/TestSynchronizedMapping.dec +++ b/testData/results/TestSynchronizedMapping.dec @@ -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 } } diff --git a/testData/src/pkg/TestAbstractMethods.java b/testData/src/pkg/TestAbstractMethods.java new file mode 100644 index 0000000..9a05f11 --- /dev/null +++ b/testData/src/pkg/TestAbstractMethods.java @@ -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); + } +}