From 917c680276948c2cb2346da82224f913d3e2536c Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 25 Mar 2015 12:29:06 +0300 Subject: [PATCH] decompiler: better line matching for single block methods --- .../main/collectors/BytecodeMappingTracer.java | 6 +++++- testData/results/InvalidMethodSignature.dec | 6 +++--- testData/results/TestEnum.dec | 12 ++++++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/main/collectors/BytecodeMappingTracer.java b/src/org/jetbrains/java/decompiler/main/collectors/BytecodeMappingTracer.java index 8a4fc44..84ca0b7 100644 --- a/src/org/jetbrains/java/decompiler/main/collectors/BytecodeMappingTracer.java +++ b/src/org/jetbrains/java/decompiler/main/collectors/BytecodeMappingTracer.java @@ -101,6 +101,8 @@ public class BytecodeMappingTracer { } Map res = new HashMap(); + + // first match offsets from line number table int[] data = lineNumberTable.getRawData(); for (int i = 0; i < data.length; i += 2) { int originalOffset = data[i]; @@ -113,9 +115,11 @@ public class BytecodeMappingTracer { unmappedLines.add(originalLine); } } + + // now match offsets from decompiler mapping for (Entry entry : mapping.entrySet()) { int originalLine = lineNumberTable.findLineNumber(entry.getKey()); - if (originalLine > -1) { + if (originalLine > -1 && !res.containsKey(originalLine)) { res.put(originalLine, entry.getValue()); unmappedLines.remove(originalLine); } diff --git a/testData/results/InvalidMethodSignature.dec b/testData/results/InvalidMethodSignature.dec index 34f2236..7b4f8c5 100644 --- a/testData/results/InvalidMethodSignature.dec +++ b/testData/results/InvalidMethodSignature.dec @@ -12,9 +12,9 @@ class i implements bg { private final b b; i(b var1, j var2) { - this.b = var1; + this.b = var1;// 1 this.a = var2; - }// 1 + } public void a(c var1, k var2, boolean var3) { File var4 = this.a.b().a(var1);// 2 @@ -50,7 +50,7 @@ class 'a/a/a/a/e/f/i' { Lines mapping: 0 <-> 25 -1 <-> 17 +1 <-> 15 2 <-> 20 3 <-> 21 4 <-> 22 diff --git a/testData/results/TestEnum.dec b/testData/results/TestEnum.dec index ff3d765..06649c0 100644 --- a/testData/results/TestEnum.dec +++ b/testData/results/TestEnum.dec @@ -18,12 +18,12 @@ public enum TestEnum { }// 30 private TestEnum() { - this("?"); - }// 34 + this("?");// 34 + } private TestEnum(@Deprecated String var3) { - this.s = var3; - }// 35 + this.s = var3;// 35 + } } class 'pkg/TestEnum$1' { @@ -59,5 +59,5 @@ Lines mapping: 22 <-> 7 27 <-> 12 30 <-> 18 -34 <-> 22 -35 <-> 26 +34 <-> 21 +35 <-> 25