From 13595773550f5511e8431058699d04faa8d0d6ad Mon Sep 17 00:00:00 2001 From: Alexandru-Constantin Bledea Date: Thu, 17 Mar 2016 23:15:54 +0200 Subject: [PATCH] add additional tests for static initializers --- .../java/decompiler/SingleClassesTest.java | 4 ++- testData/classes/pkg/TestClassFields.class | Bin 415 -> 513 bytes .../classes/pkg/TestInterfaceWithObject.class | Bin 329 -> 0 bytes .../pkg/TestInterfaceWithObjectField.class | Bin 0 -> 339 bytes .../pkg/TestInterfaceWithPrimitiveField.class | Bin 0 -> 225 bytes .../pkg/TestMutableStaticOtherClass.class | Bin 0 -> 462 bytes testData/results/TestClassFields.dec | 17 +++++------ ...t.dec => TestInterfaceWithObjectField.dec} | 2 +- .../TestInterfaceWithPrimitiveField.dec | 6 ++++ .../results/TestMutableStaticOtherClass.dec | 27 ++++++++++++++++++ testData/src/pkg/TestClassFields.java | 1 + ...java => TestInterfaceWithObjectField.java} | 2 +- .../pkg/TestInterfaceWithPrimitiveField.java | 13 +++++++++ .../src/pkg/TestMutableStaticOtherClass.java | 15 ++++++++++ 14 files changed, 76 insertions(+), 11 deletions(-) delete mode 100644 testData/classes/pkg/TestInterfaceWithObject.class create mode 100644 testData/classes/pkg/TestInterfaceWithObjectField.class create mode 100644 testData/classes/pkg/TestInterfaceWithPrimitiveField.class create mode 100644 testData/classes/pkg/TestMutableStaticOtherClass.class rename testData/results/{TestInterfaceWithObject.dec => TestInterfaceWithObjectField.dec} (68%) create mode 100644 testData/results/TestInterfaceWithPrimitiveField.dec create mode 100644 testData/results/TestMutableStaticOtherClass.dec rename testData/src/pkg/{TestInterfaceWithObject.java => TestInterfaceWithObjectField.java} (78%) create mode 100644 testData/src/pkg/TestInterfaceWithPrimitiveField.java create mode 100644 testData/src/pkg/TestMutableStaticOtherClass.java diff --git a/test/org/jetbrains/java/decompiler/SingleClassesTest.java b/test/org/jetbrains/java/decompiler/SingleClassesTest.java index 180428d..cbbbc2d 100644 --- a/test/org/jetbrains/java/decompiler/SingleClassesTest.java +++ b/test/org/jetbrains/java/decompiler/SingleClassesTest.java @@ -83,7 +83,9 @@ public class SingleClassesTest { @Test public void testMethodReferenceLetterClass() { doTest("pkg/TestMethodReferenceLetterClass"); } @Test public void testMemberAnnotations() { doTest("pkg/TestMemberAnnotations"); } @Test public void testStaticNameClash() { doTest("pkg/TestStaticNameClash"); } - @Test public void testInterfaceWithObject() { doTest("pkg/TestInterfaceWithObject"); } + @Test public void testInterfaceWithPrimitiveField() { doTest("pkg/TestInterfaceWithPrimitiveField"); } + @Test public void testInterfaceWithObjectField() { doTest("pkg/TestInterfaceWithObjectField"); } + @Test public void testTestMutableStaticOtherClass() { doTest("pkg/TestMutableStaticOtherClass"); } protected void doTest(String testFile, String... companionFiles) { ConsoleDecompiler decompiler = fixture.getDecompiler(); diff --git a/testData/classes/pkg/TestClassFields.class b/testData/classes/pkg/TestClassFields.class index 603bab20676cb402340cf83eb6720ffaac0b2a17..a25091d6a5f2925bb6daf82bf43f81a91b474d8b 100644 GIT binary patch delta 274 zcmbQw+{j{c>ff$?3=9k=42oO~91N1|3{o5n(i{vjoDA#?vLHf^ok5Qj)Nt{;+GT;iOQ zSX}IunVOSQY(25skeQ!BVB&gJ4qgU69tLg(o{4vil9++kb24xN-NFSD0@FZwAkDHn5-&gD{ZI15v;r!XOIdaWIHMG*1p=)R6_L YyOV(QG&JddhP_I@MkWlH)Uk*iQmw*x1A9l~l^}Vitk;7U>m@PNr?ae diff --git a/testData/classes/pkg/TestInterfaceWithObjectField.class b/testData/classes/pkg/TestInterfaceWithObjectField.class new file mode 100644 index 0000000000000000000000000000000000000000..bf7ec687a2f7be273dd0d02d72e5c8dff7d985ac GIT binary patch literal 339 zcmaJ-Jx{|x41L#>e9%A(R7gy~1`Ao(iWu6a5GgdM4Ir^Zm-I-lBq<74{ui(@@B{c! z2q&xv5B7VuY(M+!`{NV9DY_OmuxUX<+d#*_7Q=4;=3*Lo<0!mzqoF$puC6`bolwDF z@E7jnT+N-nOot+oInR0w=2?=-LaK8H?dbTHp*dL21Vh`Gg&42$Sd<};Gs>(_m#Z=n zBUzEdP&_NIP@;U`iMW$$9>fcgsF4)e?4;UdVB5wHbQ^2X84jKvQ|G@XhE6Rp<3;NH z4rA#4rJ6L}yOV&1YG~3Y81||iH8Nqqq>M#upJHXk8`wJv9Pq`pFU7vtnMg{?dHvgoo)Z`L2Mg}GZkUJO| WBpFy3Sb;PfkjKQp4i@78vpE6pB04$% literal 0 HcmV?d00001 diff --git a/testData/classes/pkg/TestMutableStaticOtherClass.class b/testData/classes/pkg/TestMutableStaticOtherClass.class new file mode 100644 index 0000000000000000000000000000000000000000..14b1efdd89c333e2f89f96ac09e3d32c47ea60c7 GIT binary patch literal 462 zcmah_O;5r=5PefhTS@^1Ke;G3KN5TKChm&Z|3cMe7?N{xJ2DY9@PSB*eSrqu8Tbv`vkk+xxXP$hu}2TLg{Nl?&NgH zOlvuogi2Q}jl;tIWvM_MwF4u#5N0kM*IiH7Ph|t|K(qA literal 0 HcmV?d00001 diff --git a/testData/results/TestClassFields.dec b/testData/results/TestClassFields.dec index 75ece1e..d139051 100644 --- a/testData/results/TestClassFields.dec +++ b/testData/results/TestClassFields.dec @@ -1,25 +1,26 @@ package pkg; public class TestClassFields { + static int staticMutable; private static int[] sizes; private static String[] names = new String[]{"name1", "name2"}; static { - sizes = new int[names.length];// 26 - }// 27 + sizes = new int[names.length];// 27 + }// 28 } class 'pkg/TestClassFields' { method ' ()V' { - 11 7 - 14 7 - 17 7 - 1a 8 + 11 8 + 14 8 + 17 8 + 1a 9 } } Lines mapping: -26 <-> 8 27 <-> 9 +28 <-> 10 Not mapped: -25 +26 diff --git a/testData/results/TestInterfaceWithObject.dec b/testData/results/TestInterfaceWithObjectField.dec similarity index 68% rename from testData/results/TestInterfaceWithObject.dec rename to testData/results/TestInterfaceWithObjectField.dec index 5afeed6..c9418d8 100644 --- a/testData/results/TestInterfaceWithObject.dec +++ b/testData/results/TestInterfaceWithObjectField.dec @@ -2,7 +2,7 @@ package pkg; import java.math.BigDecimal; -public interface TestInterfaceWithObject { +public interface TestInterfaceWithObjectField { BigDecimal BUGS_IN_THE_DECOMPILER = BigDecimal.ZERO; } diff --git a/testData/results/TestInterfaceWithPrimitiveField.dec b/testData/results/TestInterfaceWithPrimitiveField.dec new file mode 100644 index 0000000..542e858 --- /dev/null +++ b/testData/results/TestInterfaceWithPrimitiveField.dec @@ -0,0 +1,6 @@ +package pkg; + +public interface TestInterfaceWithPrimitiveField { + int MAX_BYTE_VALUE = 127; +} + diff --git a/testData/results/TestMutableStaticOtherClass.dec b/testData/results/TestMutableStaticOtherClass.dec new file mode 100644 index 0000000..6e7ed33 --- /dev/null +++ b/testData/results/TestMutableStaticOtherClass.dec @@ -0,0 +1,27 @@ +package pkg; + +import pkg.TestClassFields; + +public class TestMutableStaticOtherClass { + private static final int SIZE; + + static { + TestClassFields.staticMutable = 3;// 12 + SIZE = TestClassFields.staticMutable;// 13 + }// 14 +} + +class 'pkg/TestMutableStaticOtherClass' { + method ' ()V' { + 0 8 + 1 8 + 4 9 + 7 9 + a 10 + } +} + +Lines mapping: +12 <-> 9 +13 <-> 10 +14 <-> 11 diff --git a/testData/src/pkg/TestClassFields.java b/testData/src/pkg/TestClassFields.java index a1f2fac..2341ff7 100644 --- a/testData/src/pkg/TestClassFields.java +++ b/testData/src/pkg/TestClassFields.java @@ -17,6 +17,7 @@ package pkg; public class TestClassFields { + static int staticMutable; private static int[] sizes; private static String[] names; diff --git a/testData/src/pkg/TestInterfaceWithObject.java b/testData/src/pkg/TestInterfaceWithObjectField.java similarity index 78% rename from testData/src/pkg/TestInterfaceWithObject.java rename to testData/src/pkg/TestInterfaceWithObjectField.java index 4653d70..ac0bd64 100644 --- a/testData/src/pkg/TestInterfaceWithObject.java +++ b/testData/src/pkg/TestInterfaceWithObjectField.java @@ -6,7 +6,7 @@ import java.math.BigDecimal; * @author Alexandru-Constantin Bledea * @since March 06, 2016 */ -public interface TestInterfaceWithObject { +public interface TestInterfaceWithObjectField { BigDecimal BUGS_IN_THE_DECOMPILER = BigDecimal.ZERO; diff --git a/testData/src/pkg/TestInterfaceWithPrimitiveField.java b/testData/src/pkg/TestInterfaceWithPrimitiveField.java new file mode 100644 index 0000000..89d1b7a --- /dev/null +++ b/testData/src/pkg/TestInterfaceWithPrimitiveField.java @@ -0,0 +1,13 @@ +package pkg; + +import java.math.BigDecimal; + +/** + * @author Alexandru-Constantin Bledea + * @since March 06, 2016 + */ +public interface TestInterfaceWithPrimitiveField { + + int MAX_BYTE_VALUE = Byte.MAX_VALUE; + +} diff --git a/testData/src/pkg/TestMutableStaticOtherClass.java b/testData/src/pkg/TestMutableStaticOtherClass.java new file mode 100644 index 0000000..4015c83 --- /dev/null +++ b/testData/src/pkg/TestMutableStaticOtherClass.java @@ -0,0 +1,15 @@ +package pkg; + +/** + * @author Alexandru-Constantin Bledea + * @since March 17, 2016 + */ +public class TestMutableStaticOtherClass { + + private static final int SIZE; + + static { + TestClassFields.staticMutable = 3; + SIZE = TestClassFields.staticMutable; + } +}