From a74f586e348022f3af0c0600e58eb08253c7b317 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 21 Jan 2015 21:21:43 +0300 Subject: [PATCH] decompiler: fixed anonymous class line numbers --- .../modules/decompiler/exps/NewExprent.java | 12 +- .../classes/pkg/TestAnonymousClass$5.class | Bin 0 -> 586 bytes .../classes/pkg/TestAnonymousClass$6.class | Bin 0 -> 645 bytes .../classes/pkg/TestAnonymousClass$7.class | Bin 0 -> 586 bytes .../classes/pkg/TestAnonymousClass$8.class | Bin 0 -> 645 bytes .../pkg/TestAnonymousClass$Inner.class | Bin 443 -> 443 bytes .../TestAnonymousClass$InnerRecursive.class | Bin 0 -> 472 bytes testData/classes/pkg/TestAnonymousClass.class | Bin 1113 -> 1563 bytes testData/results/TestAnonymousClass.dec | 128 ++++++++++++++---- testData/src/pkg/TestAnonymousClass.java | 41 ++++++ 10 files changed, 148 insertions(+), 33 deletions(-) create mode 100644 testData/classes/pkg/TestAnonymousClass$5.class create mode 100644 testData/classes/pkg/TestAnonymousClass$6.class create mode 100644 testData/classes/pkg/TestAnonymousClass$7.class create mode 100644 testData/classes/pkg/TestAnonymousClass$8.class create mode 100644 testData/classes/pkg/TestAnonymousClass$InnerRecursive.class diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java index a143828..960f26b 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java @@ -252,12 +252,16 @@ public class NewExprent extends Exprent { buf.setLength(0); // remove the usual 'new ()', it will be replaced with lambda style '() ->' } Exprent methodObject = constructor == null ? null : constructor.getInstance(); - new ClassWriter().classLambdaToJava(child, buf, methodObject, indent); - tracer.incrementCurrentSourceLine(buf.countLines()); + TextBuffer clsBuf = new TextBuffer(); + new ClassWriter().classLambdaToJava(child, clsBuf, methodObject, indent); + buf.append(clsBuf); + tracer.incrementCurrentSourceLine(clsBuf.countLines()); } else { - new ClassWriter().classToJava(child, buf, indent, tracer); - tracer.incrementCurrentSourceLine(buf.countLines()); + TextBuffer clsBuf = new TextBuffer(); + new ClassWriter().classToJava(child, clsBuf, indent, tracer); + buf.append(clsBuf); + tracer.incrementCurrentSourceLine(clsBuf.countLines()); } } else if (directArrayInit) { diff --git a/testData/classes/pkg/TestAnonymousClass$5.class b/testData/classes/pkg/TestAnonymousClass$5.class new file mode 100644 index 0000000000000000000000000000000000000000..e3df9c842f74ec0afdee4cb773d25e85f0d5c0c7 GIT binary patch literal 586 zcmZ`$%TB^T6g>l#mWP0-fIAa0Q84O4S0ITJjYeRh#66D@sxUR3mc-9;VN6{30e+P6 zl$aO-?c~1BoH@OB=KJUK3&07s;)r5B0RtN*HcjLOV&2HsrDK6&^W}MX)REddSB`p} zIKFO-yINPtsoBc*>H_H-rKEc&`@XB~sT4@ffEiC}fs4H`kr2EzFIe4w5HK3ffYOy6l^tvp7P~%t>Q1{9xm5kJqir>8NpIu~OcYXB zK`aFmMb5l@^7ZTZQ&>gb~%|rqMNoG5&qm0RN zEFNa9{}gbMWA6liZC|RYE#jcqHRSP4OtC40%Amz2$$#*wm``3 zm`?6YAXR>UYoFGn<6c{~_0hM7PO(>aoC13;P0Mtz1Y#x2l7otD4hN1ok^;I{@cN`9 zaC0zEWKKOdDOfms6$ljV7Nz55(~^(FenSpw^+u1CXw@DLn)1$6NpjlhNw+?#^Wd%3 z?AeZKwI8J0v0EB;b;J31W_FeigZPbh;sJXqvtLJ_UCL(8W%{+?i0w*`zO=0 zBg@wc^F@OMeUhQ9dXa9uNW*|(sEL>h!oUjSDp&XL!Oxh6>Jn{yWV*+$0kKi?C#J}mfb&>-oWYU zD5S7}SPD9doO%Apr2~P@kge&41@iNG0+q14n4KBxd=`x_B(m9{J7y7@jsygf%r;m@ z8IzUjJ49vs1CckDynp%_BXC1oMEdVQl`#<1jkg$c$)i5e1gp~R(HU;;&G4J{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#|YRue~ z^0Mg!7_6ZqRYm7Hx@zbq%6$$`4PK&p&f#lBZ8eMbQ6WLvrPE|SPg&TofC0h>R9qju qTt5XFBz%wb#7o|HNz}^vkuI^wUL4Uxal9s!$g4OKwWy926XOp~&riev delta 581 zcmYL`%T5zf7{`BSrqeT>4vN}>Wu`5c%1uO}c)t{Mg@Fac#IPY@!NwR8>;v!&qkopFnp$iSa)SvF9Y`_g&6+JLhfuJ3RXN_uCI(g{Kjhn6u1Bcw8@2Wue3k z79(zQ%d!+^K8K1r0>vs3MmIns2 zZt%9-hRVjPz2onxE1PZe(CwO4KOuD=%viD%lkg~}Nosi<^MsCNHD--*x8>FSQLef} zu_hjiW8#UoXj1pbOI^!vd&#Uj^he!i|K-uJ<^rD@3X@dR&Z#iz0Y=qQoposwqRFiD zrg%bN>BY8))kGG>Re{Hq)$ diff --git a/testData/results/TestAnonymousClass.dec b/testData/results/TestAnonymousClass.dec index 18cfaef..d0ae4ec 100644 --- a/testData/results/TestAnonymousClass.dec +++ b/testData/results/TestAnonymousClass.dec @@ -19,6 +19,30 @@ public abstract class TestAnonymousClass { boolean var2 = true;// 54 } }; + private final TestAnonymousClass.InnerRecursive y = new TestAnonymousClass.InnerRecursive(new TestAnonymousClass.InnerRecursive((TestAnonymousClass.InnerRecursive)null) { + void foo() { + boolean var1 = true;// 75 + boolean var2 = true;// 76 + boolean var3 = true;// 77 + } + }) { + int v = 5; + int t = 5; + int j = 5; + int o = 5; + }; + private final TestAnonymousClass.InnerRecursive x = new TestAnonymousClass.InnerRecursive(new TestAnonymousClass.InnerRecursive((TestAnonymousClass.InnerRecursive)null) { + void foo() { + boolean var1 = true;// 90 + boolean var2 = true;// 91 + boolean var3 = true;// 92 + } + }) { + int v = 5; + int t = 5; + int j = 5; + int o = 5; + }; void foo(int var1) throws Exception { if(var1 > 0) {// 10 @@ -43,8 +67,19 @@ public abstract class TestAnonymousClass { boolean var1 = true;// 39 } + static class InnerRecursive { + TestAnonymousClass.InnerRecursive r; + + public InnerRecursive(TestAnonymousClass.InnerRecursive var1) { + this.r = var1;// 105 + } + + void foo() { + } + } + private static class Inner { - private static final Runnable R_I = new Runnable() { + private static Runnable R_I = new Runnable() { public void run() { boolean var1 = true;// 66 boolean var2 = true;// 67 @@ -84,59 +119,94 @@ class 'pkg/TestAnonymousClass$4' { } } +class 'pkg/TestAnonymousClass$5' { + method 'foo ()V' { + 0 23 + 1 23 + 2 24 + 3 24 + 4 25 + 5 25 + } +} + +class 'pkg/TestAnonymousClass$7' { + method 'foo ()V' { + 0 35 + 1 35 + 2 36 + 3 36 + 4 37 + 5 37 + } +} + class 'pkg/TestAnonymousClass$1' { method 'foo ()V' { - 0 26 - 1 26 - 2 27 - 3 27 + 0 50 + 1 50 + 2 51 + 3 51 } } class 'pkg/TestAnonymousClass' { method 'foo (I)V' { - 1 23 - c 29 - e 30 - 16 32 - 19 32 - 1a 32 + 1 47 + c 53 + e 54 + 16 56 + 19 56 + 1a 56 } method 'boo ()V' { - 0 38 - 1 38 + 0 62 + 1 62 } method 'zoo ()V' { - 0 42 - 1 42 + 0 66 + 1 66 + } +} + +class 'pkg/TestAnonymousClass$InnerRecursive' { + method ' (Lpkg/TestAnonymousClass$InnerRecursive;)V' { + 6 73 } } class 'pkg/TestAnonymousClass$Inner$1' { method 'run ()V' { - 0 48 - 1 48 - 2 49 - 3 49 + 0 83 + 1 83 + 2 84 + 3 84 } } Lines mapping: -10 <-> 24 -11 <-> 30 -13 <-> 27 -14 <-> 28 -17 <-> 31 -21 <-> 33 +10 <-> 48 +11 <-> 54 +13 <-> 51 +14 <-> 52 +17 <-> 55 +21 <-> 57 28 <-> 6 29 <-> 7 -35 <-> 39 -39 <-> 43 +35 <-> 63 +39 <-> 67 45 <-> 12 46 <-> 13 53 <-> 18 54 <-> 19 -66 <-> 49 -67 <-> 50 +66 <-> 84 +67 <-> 85 +75 <-> 24 +76 <-> 25 +77 <-> 26 +90 <-> 36 +91 <-> 37 +92 <-> 38 +105 <-> 74 diff --git a/testData/src/pkg/TestAnonymousClass.java b/testData/src/pkg/TestAnonymousClass.java index 3c2e3b0..3683338 100644 --- a/testData/src/pkg/TestAnonymousClass.java +++ b/testData/src/pkg/TestAnonymousClass.java @@ -68,4 +68,45 @@ public abstract class TestAnonymousClass { } }; } + + private final InnerRecursive y = new InnerRecursive(new InnerRecursive(null) { + @Override + void foo() { + int a =5; + int b =5; + int g =5; + } + }) { + int v =5; + int t =5; + int j =5; + int o =5; + }; + + + private final InnerRecursive x = new InnerRecursive(new InnerRecursive(null) { + @Override + void foo() { + int a =5; + int b =5; + int g =5; + } + }) { + int v =5; + int t =5; + int j =5; + int o =5; + }; + + static class InnerRecursive { + InnerRecursive r; + + public InnerRecursive(InnerRecursive r) { + this.r = r; + } + + void foo() { + + } + } }