From b366de8eb4354b33b8f0eeb9962d4d0b3d4e8aec Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 20 Apr 2016 19:52:08 +0200 Subject: [PATCH] [java-decompiler] unneeded cast around byte/short constants --- .../modules/decompiler/ExprProcessor.java | 2 +- .../pkg/MoreAnnotations$TestEnum.class | Bin 1069 -> 977 bytes testData/classes/pkg/MoreAnnotations.class | Bin 2662 -> 2679 bytes testData/results/MoreAnnotations.dec | 8 ++++---- testData/src/pkg/MoreAnnotations.java | 14 +++++++------- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java b/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java index 50c206c..b791e62 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java @@ -891,7 +891,7 @@ public class ExprProcessor implements CodeConstants { castAlways || (!leftType.isSuperset(rightType) && (rightType.equals(VarType.VARTYPE_OBJECT) || leftType.type != CodeConstants.TYPE_OBJECT)) || (castNull && rightType.type == CodeConstants.TYPE_NULL && !UNDEFINED_TYPE_STRING.equals(getTypeName(leftType))) || - (isIntConstant(exprent) && VarType.VARTYPE_INT.isStrictSuperset(leftType)); + (isIntConstant(exprent) && rightType.isStrictSuperset(leftType)); boolean quote = cast && exprent.getPrecedence() >= FunctionExprent.getPrecedence(FunctionExprent.FUNCTION_CAST); diff --git a/testData/classes/pkg/MoreAnnotations$TestEnum.class b/testData/classes/pkg/MoreAnnotations$TestEnum.class index d221ad65a1982f7d75e376d7b71c225510c00175..5e4765d3df9a82e432b3c4efd62b67ad9d289c81 100644 GIT binary patch delta 245 zcmZ3>agp8T)W2Q(7#J8#7z{WWSQwPJ7?c@Q*cpV`8PvEKco@_{ga!u#FBec!1EfNe zgFz5PYq2wEZ?xfLY2MJ8o7eI5oW z2ICsf!1*ev1sjJU_HRVvH{3rWDp0EY+#vSpbDUBASnhElV@NCLIwtQ zEp3_Y3~U=Q6w3fbm>6UkI2hy@WG8QBj+BRp$TKK_WfU3sfixG;Xch)l20jN#0MBk4 Ag8%>k delta 344 zcmZvW%}T>S6ot?o$Ahz67J6vlA+&CM^Q3tGZf~z! Sn+4j!EV-ne9Cgf`EdBuy87@fx diff --git a/testData/classes/pkg/MoreAnnotations.class b/testData/classes/pkg/MoreAnnotations.class index 36178dea70f2c1bd9ea20087baa77a1fda68c668..85146c8c8b7174ee28a29cc5be67b7ecd55225ea 100644 GIT binary patch delta 877 zcmZva$!^n77==G)z@@6xP=W}Qc@&-7L}7+v8;e+|AW|{J3@ssyZGgIE1~WWDCEf$E zW5FICgat3a4me5eVnujy<@=p;uYLai|B?TdFMj|15Htdl_n(R%Q`z(%J)gg&W-`Xl?@ z8IR2#=RGcXOf%-Q#^$2U*3c$rQ?|LJm2utEU^_cn%Vj3Con#jVy94&DzFnc{lMbi_ z_yPMUX;iS&K3z1)w_1w0Vg&m5_h07}NZ zlB8%#IKacm*{h-|T!nIlgB1=*9Nyg<47;WO%6M|EZYzZ3EO`=F4r(Y z`~@ZRCI!yAXx;jKmfLZX(Y z+sg|UL-lq$S@h@UluDGtyN~4$_NQ<5Y|i@LDLPxyTn)EIwZ@?uhZ%`+Le_^I2{{^a zEaZ5|iI6EqMG4pta5BITm<~7zK{bv!0rc-WXwwvn*|XL((XDt zzw%!CFgr6W^_ue&+X#;`(fi*l#Wl)f!}ZU(iffF;%(Z4^#)8LFl<@=Rz(p;xWQgYQ zMJ%ywi2W7lZ-9ssJjuj-jHO$f#f4%n^DM(d=1PcC;d$0zSNXdh{VHFG_Oe&% JtIo`z_Xjg~bO!(c diff --git a/testData/results/MoreAnnotations.dec b/testData/results/MoreAnnotations.dec index 7ca5d12..37302cc 100644 --- a/testData/results/MoreAnnotations.dec +++ b/testData/results/MoreAnnotations.dec @@ -33,11 +33,11 @@ public @interface MoreAnnotations { String annotatedWithEmptyArrays = ""; @MoreAnnotations( intArray = {1, 0, 2147483647, -2147483648}, - byteArray = {(byte)1, (byte)0, (byte)127, (byte)-128}, + byteArray = {1, 0, 127, -128, -1}, floatArray = {1.0F, 0.0F, 3.4028235E38F, 1.4E-45F, 0.0F / 0.0, 1.0F / 0.0, -1.0F / 0.0}, doubleArray = {1.0D, 0.0D, 1.7976931348623157E308D, 4.9E-324D, 0.0D / 0.0, 1.0D / 0.0, -1.0D / 0.0}, booleanArray = {true, false}, - shortArray = {(short)1, (short)0, (short)32767, (short)-32768}, + shortArray = {1, 0, 32767, -32768, -1}, longArray = {1L, 0L, 9223372036854775807L, -9223372036854775808L}, charArray = {'a', '\n', '\u0001', '\u0000', '\uffff', '\u0000'}, enumArray = {MoreAnnotations.TestEnum.FirstValue, MoreAnnotations.TestEnum.SecondValue}, @@ -73,7 +73,7 @@ public @interface MoreAnnotations { int[] intArray() default {1, 0, 2147483647, -2147483648}; - byte[] byteArray() default {(byte)1, (byte)0, (byte)127, (byte)-128}; + byte[] byteArray() default {1, 0, 127, -128, -1}; float[] floatArray() default {1.0F, 0.0F, 3.4028235E38F, 1.4E-45F, 0.0F / 0.0, 1.0F / 0.0, -1.0F / 0.0}; @@ -81,7 +81,7 @@ public @interface MoreAnnotations { boolean[] booleanArray() default {true, false}; - short[] shortArray() default {(short)1, (short)0, (short)32767, (short)-32768}; + short[] shortArray() default {1, 0, 32767, -32768, -1}; long[] longArray() default {1L, 0L, 9223372036854775807L, -9223372036854775808L}; diff --git a/testData/src/pkg/MoreAnnotations.java b/testData/src/pkg/MoreAnnotations.java index e66835e..d29abce 100644 --- a/testData/src/pkg/MoreAnnotations.java +++ b/testData/src/pkg/MoreAnnotations.java @@ -16,16 +16,16 @@ public @interface MoreAnnotations { Class classValue() default CharSequence.class; int[] intArray() default { 1, 0, Integer.MAX_VALUE, Integer.MIN_VALUE }; - byte[] byteArray() default { 1, 0, Byte.MAX_VALUE, Byte.MIN_VALUE }; + byte[] byteArray() default { 1, 0, Byte.MAX_VALUE, Byte.MIN_VALUE, (byte)0xFF }; float[] floatArray() default { 1, 0, Float.MAX_VALUE, Float.MIN_VALUE, Float.NaN, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY }; double[] doubleArray() default { 1, 0, Double.MAX_VALUE, Double.MIN_VALUE, Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY }; boolean[] booleanArray() default { true, false }; - short[] shortArray() default { 1, 0, Short.MAX_VALUE, Short.MIN_VALUE }; + short[] shortArray() default { 1, 0, Short.MAX_VALUE, Short.MIN_VALUE, (short)0xFFFF }; long[] longArray() default { 1, 0, Long.MAX_VALUE, Long.MIN_VALUE }; char[] charArray() default { 1, 0, Character.MAX_VALUE, Character.MIN_VALUE }; TestEnum[] enumArray() default { TestEnum.FirstValue }; NestedAnnotation[] annotationArray() default { @NestedAnnotation }; - String[] stringArray() default { "first", "second", ""}; + String[] stringArray() default { "first", "second", "" }; Class[] classArray() default { CharSequence.class, String.class, StringBuilder.class }; @interface NestedAnnotation { @@ -66,16 +66,16 @@ public @interface MoreAnnotations { @MoreAnnotations( intArray = { 1, 0, Integer.MAX_VALUE, Integer.MIN_VALUE }, - byteArray = { 1, 0, Byte.MAX_VALUE, Byte.MIN_VALUE }, + byteArray = { 1, 0, Byte.MAX_VALUE, Byte.MIN_VALUE, (byte)0xFF }, floatArray = { 1, 0, Float.MAX_VALUE, Float.MIN_VALUE, Float.NaN, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY }, doubleArray = { 1, 0, Double.MAX_VALUE, Double.MIN_VALUE, Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY }, booleanArray = { true, false }, - shortArray = { 1, 0, Short.MAX_VALUE, Short.MIN_VALUE }, + shortArray = { 1, 0, Short.MAX_VALUE, Short.MIN_VALUE, (short)0xFFFF }, longArray = { 1, 0, Long.MAX_VALUE, Long.MIN_VALUE }, charArray = { 'a', '\n', 1, 0, Character.MAX_VALUE, Character.MIN_VALUE }, - enumArray = { TestEnum.FirstValue , TestEnum.SecondValue}, + enumArray = { TestEnum.FirstValue , TestEnum.SecondValue }, annotationArray = { @NestedAnnotation("a"), @NestedAnnotation("b") }, - stringArray = { "first", "second", ""}, + stringArray = { "first", "second", "" }, classArray = { CharSequence.class, String.class, StringBuilder.class } ) String annotatedWithArrays = "";