From 17d489484894a0e4f00e61eec1e606f891ca3e29 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Fri, 5 May 2017 13:10:53 +0300 Subject: [PATCH] IDEA-172200 Decompiler switch-on-enum multiple switches in same class generates wrong cases for all but the first switch-on-enum --- .../modules/decompiler/SwitchHelper.java | 5 +- testData/classes/pkg/TestSwitchOnEnum$1.class | Bin 700 -> 1346 bytes .../pkg/TestSwitchOnEnum$Example$A.class | Bin 0 -> 1103 bytes .../pkg/TestSwitchOnEnum$Example$B.class | Bin 0 -> 1103 bytes .../pkg/TestSwitchOnEnum$Example.class | Bin 0 -> 1204 bytes testData/classes/pkg/TestSwitchOnEnum.class | Bin 711 -> 763 bytes testData/results/TestSwitchOnEnum.dec | 62 ++++++++++++++++++ testData/src/pkg/TestSwitchOnEnum.java | 26 ++++++++ 8 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 testData/classes/pkg/TestSwitchOnEnum$Example$A.class create mode 100644 testData/classes/pkg/TestSwitchOnEnum$Example$B.class create mode 100644 testData/classes/pkg/TestSwitchOnEnum$Example.class diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/SwitchHelper.java b/src/org/jetbrains/java/decompiler/modules/decompiler/SwitchHelper.java index 01d56e2..cf935f4 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/SwitchHelper.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/SwitchHelper.java @@ -37,8 +37,9 @@ public class SwitchHelper { List> caseValues = switchStatement.getCaseValues(); Map mapping = new HashMap<>(caseValues.size()); ArrayExprent array = (ArrayExprent)value; + FieldExprent arrayField = (FieldExprent)array.getArray(); ClassesProcessor.ClassNode classNode = - DecompilerContext.getClassProcessor().getMapRootClasses().get(((FieldExprent)array.getArray()).getClassname()); + DecompilerContext.getClassProcessor().getMapRootClasses().get(arrayField.getClassname()); if (classNode != null) { MethodWrapper wrapper = classNode.getWrapper().getMethodWrapper(CodeConstants.CLINIT_NAME, "()V"); if (wrapper != null) { @@ -48,7 +49,7 @@ public class SwitchHelper { if (exprent instanceof AssignmentExprent) { AssignmentExprent assignment = (AssignmentExprent)exprent; Exprent left = assignment.getLeft(); - if (isEnumArray(left)) { + if (left.type == Exprent.EXPRENT_ARRAY && ((ArrayExprent)left).getArray().equals(arrayField)) { mapping.put(assignment.getRight(), ((InvocationExprent)((ArrayExprent)left).getIndex()).getInstance()); } } diff --git a/testData/classes/pkg/TestSwitchOnEnum$1.class b/testData/classes/pkg/TestSwitchOnEnum$1.class index aebc1c568ce9e3d2e92dc364bfca59486d4c7ff1..6c54901212381a045f0240ca9a4b318e49065185 100644 GIT binary patch literal 1346 zcmb7EYflqF6g|@xmexfI@~Fs5Sb6xMfG8>mw53&~kHjK;;L~=y!oqeJw=MdQ{46Gf z7{d?n_xRa(W_cMxXiR4I-ZOLV%$+-D_Sc^uCje%Vk6;)hVYEXF(|aJ{sDd#G#v_=( zLpk>-Oz*LTqtbg4!6f2xVk%5;T0%}tVn)GJ1NaplK5<}wOG@QJs!fxEQ>&- z=+-^M%vdt0>uR2p@~~V!?HIOOwVdsoS=({T3Z5%?p<*5jD!S3B;x!gkEMZxoSBAuG z-Pw-k-D2I?$ylacPJ5o~sYqZ^K~e^;sOXY`X=GHqK}Nw_IlQXkjvRi6H5FN`33Ri5 z@vC`h(*o+MV7JSC81dP9wQitCjvN4NdUq-p}mnMSEmFM_>s9toL8qH!LlJnq}?*H7v? zeyQvDrLKqN(Qo8%M>V&adS57}Q-%CWQDCrPfO5g@yQ!?vAwJFyzVKi)CIte}Qa`?> z06D|QfgZ$Y?-Kn+kREVw3~}-^@*ROg*@8z1g$iF0TJvEuVUrJ!q4>0xL$HO95ILt2 z-Xc7wsXnds5Nx-P&~{EEj1r#GzM&amX4QixW;B9P+9|4gk#>pN&e3k71e5k7KA}b% zL@)EbO$+kJFn~PKJ)!`6ANvs0O$GhP$1D&Wgn*BPK#&@<~aJ2 RwHl`PYB|Q=-yBlQvA;4lLv{cF delta 287 zcmW-b%`QVx6otQY|4#39)b-Q$YSC&{Zxa(@fLViq0UdN8CgdgzNJBz+2gBw(iK&Qz zp(io*0%D&I*4}Gnt^M2qFL26Czm^upP_2l zJ++^;H0y>o9YaiF*r03Jq-S4MGs@{Is&?C}*k5&E2Yy>eFU9!z=E)ZR#o*!b`u4sU zEBw5FqR^w`!{OP{C~e90l6<4m%q?|H^bAJ&tf)JDVUXK;(7SrWlhhJ5LNYpXJQTky nel$&$nG@~_Qh^~j*UWS3isTli-lEJyKt<}BAdyKeowW219(^G0 diff --git a/testData/classes/pkg/TestSwitchOnEnum$Example$A.class b/testData/classes/pkg/TestSwitchOnEnum$Example$A.class new file mode 100644 index 0000000000000000000000000000000000000000..7bd4f3d2b9586271b468ca4e812f8a44faa82cb7 GIT binary patch literal 1103 zcma)4?{Csj6g`g?3SIZZ4(33dn?nWWV4F-oKo-cdB}<5W=p#G{j-!M z&S*6I>>p*kuOkk08NMd(NAJ1koO|E<`RnTs042PLK}J?Z4tWI$1#2oaJQdS=6w@jN z*9D>w#k^RH3N{!*wM_+E49eaI-Z^zF2JOIgEpON1y`I%$U^Ry2`surN@zCn|#(Ud0 zj~niu+wWwCDVbVX@CcGjvsQn#XE3b1o}3an<4#{ltY&ln0hf2XZ^+(k-FB^){Z7mB z4tYx$Rsx>JTZU4$e!|aq(cx~pX!xG(w#&K6M)Z2ur!6)Ce`W&Jz$Mqy;MyK*8r_#9GFXq>M0^4 zh6UUO!y=s?(kg~J0Q-#4C8UpZVo1^)31UgYr*LnGFCi5CRdqT41>sA`0v{T~r|FM& zg~EL-1#xO4p@iZlB>Dg)zm~p0l_mATm=a{XUMhDh1r zj=#e&cZ1-5w#gv-M-EjMGn_Uz{k}&`Qbq)#Wy>8VZ;eokewN2M-Jw3KMz`--_MRgu zPyBr)c~QQGxVZj=hNmbpEZu&08j{%7a39MWCZTJXh0ZW_)kk4X!83-`ZA1)V%k6S9 z70+Zx3Tw2EZObR)+oP=tURP-Z_UE#$>r!6)Ce_LYJz$Mqy;NBct^r!fI53kG)l)=9 z40E^(hIu+Ypj8ZY0QMQ73rHX7#IQhfB#12%K8eL4zKBrpSJma*7lbb$3w-DrK1F}D zOBC*5DTq@W2_+OaA<+jYxwX_eBA4 zpX31(AN&FS0)LJ1+-+4tNVQ4t%-oqX_sq=Q`~BzFZva+NHZTM$fjP_@7{NjUX=HRP z8dySB$6e*g8AxJ5M_$K04J#V%3uxQ#WuxWV0_KkA*?!rT?Y7<4uqq%*8Xiy-1>)>lnBTM8 zLG_&z)Q@((ZLia?dISp08qg#2Jkd}vv5uz#k>aw34HKK#QpSpj zBG#ytmes<^lmw>xbxRWk1F)D;Fu4{Fc-&!as)yHilZBQcw;oeu4NLx+l2C z!_5gyQa8H+n8I~hzzs}uM}dDZS(MT}MP%s=(cCBHS4q3asKnDfec=?bk%2SBKVnd+ z8r4(i*)t?USoR!ds;65j(D;iPq^dYZp*YSX!F2`}i_79RPrbuiIgeL-CEg%|I$wzs zWZI^ve0r3{VsEbRz04pYt|#x5-53L}!#u5L~8IWjRy JIY&Q|`Y-k_4vqi- literal 0 HcmV?d00001 diff --git a/testData/classes/pkg/TestSwitchOnEnum.class b/testData/classes/pkg/TestSwitchOnEnum.class index 3117de8c4e21e479f4230977e7c9643f5d5f107e..f7c13a2596df74ff06741e4cb5a8a44c1403835e 100644 GIT binary patch delta 287 zcmXYq%Syvg5Qe{rCMS)jZLF7iX}v~;Zi-Oc2yP^x8(ruN6bULeA()E#7?LM(CAe@a z_&%-#aaz0iZ}ZR0r~Bg`ef_?F06q2sTvjT0tOm4b8`cc#h7G}FSe2~2Ce}|T;Ws7Y?WZ7Z2Jdn8E%I~hbmq{_ac)T56-JEA}_K-%Ct@2sYvw#`> z>!9bUD%R9>l||X@ydkgSab3|Hhd!Zd`(I#|hB{%6dBs}Ua}K3m=1%iu)LPWT(3!MG fYC$uhsj16UB%*~SH4e)d<%TLxnb5~)nhO3OxEUqE delta 261 zcmXYqy-osA6okLCdiO5N6%kha7sZV+6dDpb6B;TTYeS_4m4+DiNz6WkwUvnltqJdA zMPeLQo0&6bX3kl 9 16 <-> 11 18 <-> 13 20 <-> 15 +30 <-> 21 +32 <-> 23 +33 <-> 24 +35 <-> 26 +38 <-> 29 +40 <-> 31 +41 <-> 32 +43 <-> 34 +46 <-> 37 diff --git a/testData/src/pkg/TestSwitchOnEnum.java b/testData/src/pkg/TestSwitchOnEnum.java index e26d407..0ea59ec 100644 --- a/testData/src/pkg/TestSwitchOnEnum.java +++ b/testData/src/pkg/TestSwitchOnEnum.java @@ -19,4 +19,30 @@ public class TestSwitchOnEnum { } return 0; } + + static class Example { + + enum A { A1, A2} + + enum B { B1, B2} + + void test(A a, B b){ + switch (a){ + case A1: + System.out.println("A1"); + break; + case A2: + System.out.println("A2"); + break; + } + switch (b){ + case B1: + System.out.println("B1"); + break; + case B2: + System.out.println("B2"); + break; + } + } + } }