From eaa28305964ee54e5266bf78189c75c4d5eb7878 Mon Sep 17 00:00:00 2001 From: upnotes Date: Fri, 28 Sep 2018 15:54:51 +0200 Subject: [PATCH] Addressed review comments + additional test --- .../decompiler/main/ClassesProcessor.java | 51 ++++--- .../java/decompiler/SingleClassesTest.java | 1 + .../pkg/TestSuspendLambdaKt$sl1$1.class | Bin 0 -> 2808 bytes .../classes/pkg/TestSuspendLambdaKt.class | Bin 0 -> 1171 bytes testData/results/TestSuspendLambdaKt.dec | 139 ++++++++++++++++++ testData/src/pkg/TestSuspendLambda.kt | 4 + 6 files changed, 171 insertions(+), 24 deletions(-) create mode 100644 testData/classes/pkg/TestSuspendLambdaKt$sl1$1.class create mode 100644 testData/classes/pkg/TestSuspendLambdaKt.class create mode 100644 testData/results/TestSuspendLambdaKt.dec create mode 100644 testData/src/pkg/TestSuspendLambda.kt diff --git a/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java b/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java index 2e52ba1..0e29334 100644 --- a/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java +++ b/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java @@ -245,30 +245,33 @@ public class ClassesProcessor implements CodeConstants { mt.expandData(); InstructionSequence seq = mt.getInstructionSequence(); - int len = seq.length(); - for (int i = 0; i < len; i++) { - Instruction instr = seq.getInstr(i); - - switch(instr.opcode) { - case opc_checkcast: - case opc_instanceof: - if(cl.qualifiedName.equals(pool.getPrimitiveConstant(instr.operand(0)).getString())) { - ref_counter++; - ref_not_new = true; - } - break; - case opc_new: - case opc_anewarray: - case opc_multianewarray: - if(cl.qualifiedName.equals(pool.getPrimitiveConstant(instr.operand(0)).getString())) { - ref_counter++; - } - break; - case opc_getstatic: - case opc_putstatic: - if(cl.qualifiedName.equals(pool.getLinkConstant(instr.operand(0)).classname)) { - ref_counter++; - ref_not_new = true; + if(seq != null) { + + int len = seq.length(); + for (int i = 0; i < len; i++) { + Instruction instr = seq.getInstr(i); + + switch(instr.opcode) { + case opc_checkcast: + case opc_instanceof: + if(cl.qualifiedName.equals(pool.getPrimitiveConstant(instr.operand(0)).getString())) { + ref_counter++; + ref_not_new = true; + } + break; + case opc_new: + case opc_anewarray: + case opc_multianewarray: + if(cl.qualifiedName.equals(pool.getPrimitiveConstant(instr.operand(0)).getString())) { + ref_counter++; + } + break; + case opc_getstatic: + case opc_putstatic: + if(cl.qualifiedName.equals(pool.getLinkConstant(instr.operand(0)).classname)) { + ref_counter++; + ref_not_new = true; + } } } } diff --git a/test/org/jetbrains/java/decompiler/SingleClassesTest.java b/test/org/jetbrains/java/decompiler/SingleClassesTest.java index 896d2db..b2df702 100644 --- a/test/org/jetbrains/java/decompiler/SingleClassesTest.java +++ b/test/org/jetbrains/java/decompiler/SingleClassesTest.java @@ -123,6 +123,7 @@ public class SingleClassesTest { @Test public void testGroovyClass() { doTest("pkg/TestGroovyClass"); } @Test public void testGroovyTrait() { doTest("pkg/TestGroovyTrait"); } @Test public void testPrivateClasses() { doTest("pkg/PrivateClasses"); } + @Test public void testSuspendLambdaKt() { doTest("pkg/TestSuspendLambdaKt"); } private void doTest(String testFile, String... companionFiles) { ConsoleDecompiler decompiler = fixture.getDecompiler(); diff --git a/testData/classes/pkg/TestSuspendLambdaKt$sl1$1.class b/testData/classes/pkg/TestSuspendLambdaKt$sl1$1.class new file mode 100644 index 0000000000000000000000000000000000000000..dd1fe0e7d04ef998b189081ff1e702befaa7acf8 GIT binary patch literal 2808 zcmbVO+jA3D82_Cl?Iug;jRJCyQfZqMmLP(Xij+2$&@`=VTdY-avpJ;OYamdGrYxrgUURD!%zY>G+*=b16yfXeN8E-}$b;?>pzuzkmG=z!f}ZII+N8Pxak( zZk6&{wOG<-ydl?252YnAh9B}3+cOPI(QU`}J;UOzvbIrG49nw=rJ2f}qnSFjAbIFp zx@Xvyt4s%@^mu*0h1;ZU5nEpqq~jOs1dEp8Wo~BjYubjUn3`2q=89`v7i$b-|3xPW z5r(tDiGB2v(9O_oSQ~bQGh7&H7dzU%)a1I4H4!#kaTy^TW;nd7 zR^Vrbp}g&sl{M}a9nB!;YL;btHSf7f!8c8j?Z*FlRSI9n47uES}VJbVtFgViDia{KeaRkR0x=1f>GO%16@8Cp? zY&*$tE)cK!y3Sp9&Y9K>(|7n#&`UVY5aXLVUl;ITINB11g;mFXRI@gYvp5&S86+6O zYCavsdklR|=%|lfk5?rO(Kdm&!N#zad9u}0J%?-6OdJ<59K-t-ig=~}jInWZ8AW!!MV0TTzZNlZj z`LIMFAIa7I(=fqRT1!QsZ&pSZrb!i@Lg-QQ-aeTBL7W-ldP`A?;%+n5_td^-en`kO z9M@O5UYXY%t;(r7=G?+=o-qt}fJ%$YS|U)uoQzq_i&#vF3UH4hagf4s+(AwdFUHY} zm>At>=&v7}<(^j3JdGk2s&0g-@-xvKqG_=b5T8evzBh!E@eAGV%07Y&~ui>ok>%3T~6tKB5=`C zoBME?K-EPNrB?xAgi1KIU40XDQN?JbLbIbp5u!epOzq&%7J8o11n3u#B!mf)AE}Q} zKedhHh2#sI`dLtjmq_zBm|FfFXMTdbgEKGi?(6#l=VzZ|bZiUCbA0&h6|OH2eEbrh zyrv^znA9F4v191LO?*l-F}j5bQmRU`9-;}?_QSYFvaQ{miN25e zb^0XA1X5f4Cg>e4+$l-rnc9O;PO6FeXj)Ds(ut15ZHx8SrJT&m z>GSEat2feelB)Oy35~#@_7QzD`A66zkhV!}mgdV8q%T(x&S9nY{|aB%XW!)T0N>`I Yp(sZB3Yd!$_zEH}9=a&Ih`NaX1B0pc`v3p{ literal 0 HcmV?d00001 diff --git a/testData/classes/pkg/TestSuspendLambdaKt.class b/testData/classes/pkg/TestSuspendLambdaKt.class new file mode 100644 index 0000000000000000000000000000000000000000..c686101169d710526af7dbbf4884515d885c357f GIT binary patch literal 1171 zcmb_a-%ry}6#i~ox~@(c1#ufF2q>EZ-FRgoF(f356QctX!&A4FrK4+2@9p9v@lWwD z@W+Ej6SLr(f0XguLj8rvi%omZJ*Ve8=iGC?uirj?2CxpBVRF~yq80P!ZqRKygLc<> zC^BFS`MxuBY~Klb_TzTn?T}YxP`O`Ym~S41!uJBZKOESHanKQ77;t<0>{Q!e=w1?1 zPyctqD2#;{xZK_f13JWx%vN7b1NH(>Y;0~c|Lli+42#V$>e+o)v?Ir(7MvgmMUsHq zJE7Q#eV?NAo-10i@r80FO?y%6IgCNiLctXVqu!xgdSa6Xu5h}Ja45Ml z7^*Z)CIw-Xc49)B3IjVL*9(tCm+J40j;GDhv8fc4(=SgtFCB)uutJAY!C;nY8J1=# zRkf;Ex}_CZRjaZuAK2*lxNTw%3kr+I1*~;qcOJ|0fojtuT%{?zShZ z<{ClZMq9qaxyxy^XT9&A>l`&=nI@@&k|Z5j%aSz6piEjPzmeEQWMLAaDrC))S3cTX zD_Bl(2vaVnZWfZD)B@>-Zot*HjCV_J$EQWOrrIEpA8z~C6;nBkb^xS70J4wFOw E4(0SBy8r+H literal 0 HcmV?d00001 diff --git a/testData/results/TestSuspendLambdaKt.dec b/testData/results/TestSuspendLambdaKt.dec new file mode 100644 index 0000000..2193908 --- /dev/null +++ b/testData/results/TestSuspendLambdaKt.dec @@ -0,0 +1,139 @@ +import kotlin.Metadata; +import kotlin.Unit; +import kotlin.SuccessOrFailure.Failure; +import kotlin.coroutines.Continuation; +import kotlin.coroutines.intrinsics.IntrinsicsKt; +import kotlin.coroutines.jvm.internal.SuspendLambda; +import kotlin.jvm.functions.Function1; +import kotlin.jvm.internal.Intrinsics; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@Metadata( + mv = {1, 1, 11}, + bv = {1, 0, 2}, + k = 2, + xi = 2, + d1 = {"\u0000\u0016\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0002\u0010\u0000\n\u0002\b\u0003\",\u0010\u0000\u001a\u0018\b\u0001\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00030\u0002\u0012\u0006\u0012\u0004\u0018\u00010\u00040\u0001ø\u0001\u0000¢\u0006\n\n\u0002\u0010\u0007\u001a\u0004\b\u0005\u0010\u0006\u0082\u0002\u0004\n\u0002\b\u0019"}, + d2 = {"sl1", "Lkotlin/Function1;", "Lkotlin/coroutines/Continuation;", "", "", "getSl1", "()Lkotlin/jvm/functions/Function1;", "Lkotlin/jvm/functions/Function1;"} +) +public final class TestSuspendLambdaKt { + @NotNull + private static final Function1, Object> sl1; + + @NotNull + public static final Function1, Object> getSl1() { + return sl1; + } + + static { + @Metadata( + mv = {1, 1, 11}, + bv = {1, 0, 2}, + k = 3, + xi = 2, + d1 = {"\u0000\n\n\u0000\n\u0002\u0010\u0002\n\u0002\b\u0002\u0010\u0000\u001a\u00020\u0001H\u008a@ø\u0001\u0000¢\u0006\u0004\b\u0002\u0010\u0003"}, + d2 = {"", "", "invoke", "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;"} + ) + final class NamelessClass_1 extends SuspendLambda implements Function1, Object> { + int label; + + @Nullable + public final Object invokeSuspend(@NotNull Object var1) { + Object var3 = IntrinsicsKt.getCOROUTINE_SUSPENDED(); + switch(this.label) { + case 0: + if (var1 instanceof Failure) { + throw ((Failure)var1).exception; + } + + String var2 = "SL1";// 3 + System.out.println(var2); + return Unit.INSTANCE;// 4 + default: + throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine"); + } + } + + NamelessClass_1(Continuation var1) { + super(1, var1); + } + + @NotNull + public final Continuation create(@NotNull Continuation continuation) { + Intrinsics.checkParameterIsNotNull(continuation, "continuation"); + NamelessClass_1 var2 = new NamelessClass_1(continuation); + return var2; + } + + @Nullable + public final Object invoke(@NotNull Continuation continuation) { + return ((NamelessClass_1)this.create(continuation)).invokeSuspend(Unit.INSTANCE); + } + } + + sl1 = (Function1)(new NamelessClass_1((Continuation)null));// 2 + } +} + +class 'TestSuspendLambdaKt' { + method 'getSl1 ()Lkotlin/jvm/functions/Function1;' { + 0 25 + 3 25 + } + + method ' ()V' { + 4 74 + 8 74 + b 74 + e 75 + } +} + +class 'TestSuspendLambdaKt$sl1$1' { + method 'invokeSuspend (Ljava/lang/Object;)Ljava/lang/Object;' { + 0 42 + 3 42 + 5 43 + 8 43 + 1e 45 + 21 45 + 24 46 + 27 46 + 2a 46 + 2c 49 + 2e 49 + 2f 50 + 33 50 + 36 51 + 39 51 + 3e 53 + 43 53 + } + + method ' (Lkotlin/coroutines/Continuation;)V' { + 1 58 + 3 58 + 6 59 + } + + method 'create (Lkotlin/coroutines/Continuation;)Lkotlin/coroutines/Continuation;' { + 1 63 + 3 63 + e 64 + 10 65 + } + + method 'invoke (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;' { + 2 70 + 5 70 + 8 70 + b 70 + e 70 + } +} + +Lines mapping: +2 <-> 75 +3 <-> 50 +4 <-> 52 diff --git a/testData/src/pkg/TestSuspendLambda.kt b/testData/src/pkg/TestSuspendLambda.kt new file mode 100644 index 0000000..6feef9d --- /dev/null +++ b/testData/src/pkg/TestSuspendLambda.kt @@ -0,0 +1,4 @@ + +val sl1: suspend () -> Unit = { + println("SL1") +} \ No newline at end of file