From 1ac2304d60323d5ff439fe058f35825bafb366aa Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 11 Apr 2016 21:42:48 +0200 Subject: [PATCH] [java-decompiler] fixes enum constant initializer decompilation (IDEA-154547) --- .../decompiler/main/InitializerProcessor.java | 6 ++-- testData/classes/pkg/TestEnum$2.class | Bin 428 -> 506 bytes testData/classes/pkg/TestEnum$Type.class | Bin 0 -> 871 bytes testData/classes/pkg/TestEnum.class | Bin 1491 -> 1652 bytes testData/results/TestEnum.dec | 28 +++++++++++------- testData/src/pkg/TestEnum.java | 10 ++++--- 6 files changed, 26 insertions(+), 18 deletions(-) create mode 100644 testData/classes/pkg/TestEnum$Type.class diff --git a/src/org/jetbrains/java/decompiler/main/InitializerProcessor.java b/src/org/jetbrains/java/decompiler/main/InitializerProcessor.java index fe1a4f7..206b669 100644 --- a/src/org/jetbrains/java/decompiler/main/InitializerProcessor.java +++ b/src/org/jetbrains/java/decompiler/main/InitializerProcessor.java @@ -117,7 +117,8 @@ public class InitializerProcessor { StructClass cl = wrapper.getClassStruct(); Statement firstData = Statements.findFirstData(root); if (firstData != null) { - boolean isInterface = cl.hasModifier(CodeConstants.ACC_INTERFACE); + boolean inlineInitializers = cl.hasModifier(CodeConstants.ACC_INTERFACE) || cl.hasModifier(CodeConstants.ACC_ENUM); + while (!firstData.getExprents().isEmpty()) { Exprent exprent = firstData.getExprents().get(0); @@ -131,8 +132,7 @@ public class InitializerProcessor { cl.hasField(fExpr.getName(), fExpr.getDescriptor().descriptorString)) { // interfaces fields should always be initialized inline - if (isInterface || isExprentIndependent(assignExpr.getRight(), method)) { - + if (inlineInitializers || isExprentIndependent(assignExpr.getRight(), method)) { String keyField = InterpreterUtil.makeUniqueKey(fExpr.getName(), fExpr.getDescriptor().descriptorString); if (!wrapper.getStaticFieldInitializers().containsKey(keyField)) { wrapper.getStaticFieldInitializers().addWithKey(assignExpr.getRight(), keyField); diff --git a/testData/classes/pkg/TestEnum$2.class b/testData/classes/pkg/TestEnum$2.class index 99faf412adc5a16866dfbb7efba6b1040bcddadd..3dedba7752417dc953984d6750c47d95d9ff7410 100644 GIT binary patch delta 272 zcmZ3({EOM@)W2Q(7#J8#7{s|4m>C4v83frGgcupvY%=pQOYGPggc%uFLMjVV85wvy z^YT)QoO2S3i&Kjk8LTHNs!jaO2bP@Z7Re|&ae;_hL3X-+NNRD3YhGzCBZD9^R|RAW zJA)V_gEz9yU#9gO42%q%KsP8euraU#X>KiT8C^*h#_bG@8-ZL#1}-4U2BaAnB!MJ1 z0}oV#Bv=-x0$rIj&?~$^NhSt927VyT0^~C=umiCaki`nbYz|UDSs-xW;9wAeFaRi( BESvxU delta 232 zcmeyxyoOov)W2Q(7#J8#7(}=jm>GE48Ti;41Q;3EY%=pQOY9gKG$vZ9O)QQu6JliG zE67gQ4@oU9am_2uRWV{@;PK4MOD%HFNh~f-Ee3Lt<=Gj885t}lTA57tWmKzWWdIrp zv__GEm4O9Fb82bJ=rV3+VB84gFfy$N!|0v_RMX{#4P43A#=R4>7&guR6>+25yud$N>$A*UIs3<5Zc%ebZmbeTRS&fp0 zK$t4>!d4Y*GsxZjeFon9aOp7UhraJj_B?w!b*2o(&gJ`2z2{7WwjW+p1g1gQcE5eZ zpj7&AJI8H{q4aJpE`4Qtp=k5aFy|xq-uRSQmpZQR9EBGHXVS9=9z~R>w0p*|WpvK% zE4%L5{-|yR6W1R#%=vUp*LQZF3IE zE={jl<8U%`4qTx#`*$}rAyP*{ti7n?C0;40G2|2b)3J=YjxrwW$RejBj~v6|zZnHL zLu%-aeIh6sW=vOiaPABP5~0WYGQ5dT9R0mUtm=Mi|C2OYJM;*2dO31yMQ8!Yk{lpc z7L!nhBZCqifR;+$23c{m8Q5n?w~#-Q$MA^mbd*~o{4!SV@lq7k3cUISsaxd1@RNcf-$1=aCUP_$ISZ-pl#*xk i|4;Y~3)VGQvbT)8?(29;-6TB25?PH{I5x4^D*py=Ft1_& literal 0 HcmV?d00001 diff --git a/testData/classes/pkg/TestEnum.class b/testData/classes/pkg/TestEnum.class index 01c608244d3bbc45b24058733d9c66c7ab99a89f..036f3e623b9467f49e9ec677abc19ea8c9156cb2 100644 GIT binary patch literal 1652 zcmZ`(>r&HD5dKatNg9JdfJ!S0)T%8PD+1n%P=ujZ2IusL2TEoI!U`$igW7?E*801VqgT+({GLUMyzPq z2eGVEvFroF$>H33dM}w}7<}2CLwau%YrMp8B--QjY?NOUnZdMWo7=V0zFFBd_KReZ zMO5YuLnzW)G1^^(l^EQSXpTWzv24p(W$^cjOL2rRYaQ5zQ>##!ct22Yy^eBWKEOE7 z6zLQFA82T&W;<5N%vn{78hmP0jFRb?m37-LJBDMGZJLn3t@5UMSTPHRW4@;OUg=XP z)mdplFxu)1>^ZT{P|;7PshLe#DHL1NoNA-Smt&;^A73SsYPMXf6wC(}Kfi&0TXc;V z*Ki$+Tr6m~!uR{Ch8@tlXzdH9VGg^rWosJ3xU69kQ?!%qh%m)Zb1R$Iu!o$6P%nm7 zmd$E-&fS-U`?P;foi?!}XY)RI3&pZc#7861wpKIyZ_R>3%`LYNR@|C+8?1E^+9O*x z$er2TWEkm~R&#;qCMI*q?Zh-)&hzv;kP-pjF+iGn6q>pdn%V&1;$s1Zf_#Sbt-yx} zqF|VzuMlbesCBr%!t)E>PxQqwOHvX(o$zy*Kf$|%Rn?`LZ;*dM>cul$L#%}lh-{Sc zb646aB1R`mvPr`WHzCxS*$G`?N4@wkZjj$aiFw>2p?O@Gw3oC-aYyjY%zuH}UFmWw zatX_X^l|<-=>dv7H@a+~jL^UM>bGGvVPan2Ajrq>W5Izbt z@ah;+UO(eLf~x`T7z26zEJY7CFeE&~UR|$agz_~odW^BW?w9m)b&MY&&_GcBLE-K? zv~1o}$51x!tz$Hsm+A;+8*ra;_KTT}(9eDpL5$P!1+WU8T5QhnF5<-Ag%w;R9VGh% RF}#on(r=%hghG)*{{2&;EmqRZVk~D>4YNo%F?_g{eV5KL^nd8g zA)INYIxjI8iFP?X+m&OTqOyjm@72pkdi6j%Dv?FBqxL^Cgd*J)qn$-qnZX^29x@0? z!!)c7hCq+F3`h8KM$y!)dX>sVdVzY>qp;x~P@XRIwr*NRSwA#t22p>bRkgBi>D4XM ztXP_5R7~nU;K;e7pH}sPX6eT?xqCgbW^QyBjwg7TwVuGPUGxf-l7&)xDANuee8@MwV>}Bd<}j7k71ElQt$vVE*2Do_({$xc!ew-lk;vAMDUu9WmCa4W)zHJ zoKDM$2*(vna4VxklihAQIySFh%Jy8h$O$ue3#E!l)cldCqnZ7q6TM&&{Z;3j?DI}I zVC{=_M%t&InxPjXNH3s}3Ua~#X`*OrVrXmPLkJh|3K$sWBcNvqK7?@>v`cylk>)?S z0rz)!F5vw_PYm}-3bs!rd<4-eyvw%AsxbEh;su0mJi{F3+j!2AS72W|(oPaFS`0}} zV+J0$N&DvJ$5pA-4G&?F+%C$?!(s&HVPVo9(h7yOD0tx;7N<;Kb^lY4~6#M(u+QPL{?^OHtOq6l061EUHa-T(jq diff --git a/testData/results/TestEnum.dec b/testData/results/TestEnum.dec index 06649c0..6fabfae 100644 --- a/testData/results/TestEnum.dec +++ b/testData/results/TestEnum.dec @@ -6,8 +6,8 @@ public enum TestEnum { public void m() { }// 22 }, - E3("-"), - E4("+") { + E3("-", TestEnum.Type.ODD), + E4("+", TestEnum.Type.EVEN) { public void m() { }// 27 }; @@ -15,14 +15,19 @@ public enum TestEnum { private String s; public void m() { - }// 30 + }// 32 private TestEnum() { - this("?");// 34 + this("?", (TestEnum.Type)null);// 36 } - private TestEnum(@Deprecated String var3) { - this.s = var3;// 35 + private TestEnum(@Deprecated String var3, TestEnum.Type var4) { + this.s = var3;// 37 + } + + private static enum Type { + ODD, + EVEN; } } @@ -46,10 +51,11 @@ class 'pkg/TestEnum' { method ' (Ljava/lang/String;I)V' { 3 20 5 20 - 8 21 + 6 20 + 9 21 } - method ' (Ljava/lang/String;ILjava/lang/String;)V' { + method ' (Ljava/lang/String;ILjava/lang/String;Lpkg/TestEnum$Type;)V' { 8 24 b 25 } @@ -58,6 +64,6 @@ class 'pkg/TestEnum' { Lines mapping: 22 <-> 7 27 <-> 12 -30 <-> 18 -34 <-> 21 -35 <-> 25 +32 <-> 18 +36 <-> 21 +37 <-> 25 diff --git a/testData/src/pkg/TestEnum.java b/testData/src/pkg/TestEnum.java index 43fab48..e474d34 100644 --- a/testData/src/pkg/TestEnum.java +++ b/testData/src/pkg/TestEnum.java @@ -21,16 +21,18 @@ public enum TestEnum { @Override public void m() { } }, - E3("-"), - E4("+") { + E3("-", Type.ODD), + E4("+", Type.EVEN) { @Override public void m() { } }; + private enum Type {ODD, EVEN} + public void m() { } private String s; - private TestEnum() { this("?"); } - private TestEnum(@Deprecated String s) { this.s = s; } + private TestEnum() { this("?", null); } + private TestEnum(@Deprecated String s, Type t) { this.s = s; } }