8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 6298888 6992705 8161500 6304578 8322878
27 * @summary Check Class.toGenericString()
28 */
29
30 import java.lang.reflect.*;
31 import java.lang.annotation.*;
32 import java.util.*;
33
34 @ExpectedGenericString("public class GenericStringTest")
35 public class GenericStringTest {
36 public Map<String, Integer>[] mixed = null;
37 public Map<String, Integer>[][] mixed2 = null;
38
39 private static record PlatformTestCase(Class<?> clazz, String expected) {}
40
41 public static void main(String... args) throws ReflectiveOperationException {
42 int failures = 0;
43
44 String[][] nested = {{""}};
45 int[][] intArray = {{1}};
46
47 List<PlatformTestCase> platformTestCases =
69 );
70
71 for (PlatformTestCase platformTestCase : platformTestCases) {
72 failures += checkToGenericString(platformTestCase.clazz,
73 platformTestCase.expected);
74 }
75
76 Field f = GenericStringTest.class.getDeclaredField("mixed");
77 // The expected value includes "<K,V>" rather than
78 // "<...String,...Integer>" since the Class object rather than
79 // Type objects is being queried.
80 failures += checkToGenericString(f.getType(), "java.util.Map<K,V>[]");
81 f = GenericStringTest.class.getDeclaredField("mixed2");
82 failures += checkToGenericString(f.getType(), "java.util.Map<K,V>[][]");
83
84 for(Class<?> clazz : List.of(GenericStringTest.class,
85 AnInterface.class,
86 LocalMap.class,
87 AnEnum.class,
88 AnotherEnum.class,
89
90 SealedRootClass.class,
91 SealedRootClass.ChildA.class,
92 SealedRootClass.ChildB.class,
93 SealedRootClass.ChildB.GrandChildAB.class,
94 SealedRootClass.ChildC.class,
95 SealedRootClass.ChildC.GrandChildACA.class,
96 SealedRootClass.ChildC.GrandChildACB.class,
97 SealedRootClass.ChildC.GrandChildACC.class,
98 SealedRootClass.ChildC.GrandChildACC.GreatGrandChildACCA.class,
99 SealedRootClass.ChildC.GrandChildACC.GreatGrandChildACCB.class,
100
101 SealedRootIntf.class,
102 SealedRootIntf.ChildA.class,
103 SealedRootIntf.ChildB.class,
104 SealedRootIntf.ChildB.GrandChildAB.class,
105 SealedRootIntf.ChildC.class,
106 SealedRootIntf.ChildC.GrandChildACA.class,
107 SealedRootIntf.ChildC.GrandChildACB.class,
108 SealedRootIntf.ChildC.GrandChildACC.class,
139
140 @ExpectedGenericString("abstract interface AnInterface")
141 strictfp interface AnInterface {}
142
143 @ExpectedGenericString("abstract interface LocalMap<K,V>")
144 interface LocalMap<K,V> {}
145
146 @ExpectedGenericString("final enum AnEnum")
147 enum AnEnum {
148 FOO;
149 }
150
151 // If an enum class has a specialized enum constant, that is compiled
152 // by having the enum class as being sealed rather than final. See JLS
153 // 8.9 Enum Classes.
154 @ExpectedGenericString("sealed enum AnotherEnum")
155 enum AnotherEnum {
156 BAR{};
157 }
158
159 // Test cases for sealed/non-sealed _class_ hierarchy.
160 @ExpectedGenericString("sealed class SealedRootClass")
161 sealed class SealedRootClass
162 permits
163 SealedRootClass.ChildA,
164 SealedRootClass.ChildB,
165 SealedRootClass.ChildC {
166
167 @ExpectedGenericString("final class SealedRootClass$ChildA")
168 final class ChildA extends SealedRootClass {}
169
170 @ExpectedGenericString("sealed class SealedRootClass$ChildB")
171 sealed class ChildB extends SealedRootClass permits SealedRootClass.ChildB.GrandChildAB {
172 @ExpectedGenericString("final class SealedRootClass$ChildB$GrandChildAB")
173 final class GrandChildAB extends ChildB {}
174 }
175
176 @ExpectedGenericString("non-sealed class SealedRootClass$ChildC")
177 non-sealed class ChildC extends SealedRootClass {
178 // The subclasses of ChildC do not themselves have to be
|
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 6298888 6992705 8161500 6304578 8322878
27 * @summary Check Class.toGenericString()
28 * @enablePreview
29 * @compile GenericStringTest.java
30 * @run main/othervm GenericStringTest
31 */
32
33 import java.lang.reflect.*;
34 import java.lang.annotation.*;
35 import java.util.*;
36
37 @ExpectedGenericString("public class GenericStringTest")
38 public class GenericStringTest {
39 public Map<String, Integer>[] mixed = null;
40 public Map<String, Integer>[][] mixed2 = null;
41
42 private static record PlatformTestCase(Class<?> clazz, String expected) {}
43
44 public static void main(String... args) throws ReflectiveOperationException {
45 int failures = 0;
46
47 String[][] nested = {{""}};
48 int[][] intArray = {{1}};
49
50 List<PlatformTestCase> platformTestCases =
72 );
73
74 for (PlatformTestCase platformTestCase : platformTestCases) {
75 failures += checkToGenericString(platformTestCase.clazz,
76 platformTestCase.expected);
77 }
78
79 Field f = GenericStringTest.class.getDeclaredField("mixed");
80 // The expected value includes "<K,V>" rather than
81 // "<...String,...Integer>" since the Class object rather than
82 // Type objects is being queried.
83 failures += checkToGenericString(f.getType(), "java.util.Map<K,V>[]");
84 f = GenericStringTest.class.getDeclaredField("mixed2");
85 failures += checkToGenericString(f.getType(), "java.util.Map<K,V>[][]");
86
87 for(Class<?> clazz : List.of(GenericStringTest.class,
88 AnInterface.class,
89 LocalMap.class,
90 AnEnum.class,
91 AnotherEnum.class,
92 AValueClass.class,
93
94 SealedRootClass.class,
95 SealedRootClass.ChildA.class,
96 SealedRootClass.ChildB.class,
97 SealedRootClass.ChildB.GrandChildAB.class,
98 SealedRootClass.ChildC.class,
99 SealedRootClass.ChildC.GrandChildACA.class,
100 SealedRootClass.ChildC.GrandChildACB.class,
101 SealedRootClass.ChildC.GrandChildACC.class,
102 SealedRootClass.ChildC.GrandChildACC.GreatGrandChildACCA.class,
103 SealedRootClass.ChildC.GrandChildACC.GreatGrandChildACCB.class,
104
105 SealedRootIntf.class,
106 SealedRootIntf.ChildA.class,
107 SealedRootIntf.ChildB.class,
108 SealedRootIntf.ChildB.GrandChildAB.class,
109 SealedRootIntf.ChildC.class,
110 SealedRootIntf.ChildC.GrandChildACA.class,
111 SealedRootIntf.ChildC.GrandChildACB.class,
112 SealedRootIntf.ChildC.GrandChildACC.class,
143
144 @ExpectedGenericString("abstract interface AnInterface")
145 strictfp interface AnInterface {}
146
147 @ExpectedGenericString("abstract interface LocalMap<K,V>")
148 interface LocalMap<K,V> {}
149
150 @ExpectedGenericString("final enum AnEnum")
151 enum AnEnum {
152 FOO;
153 }
154
155 // If an enum class has a specialized enum constant, that is compiled
156 // by having the enum class as being sealed rather than final. See JLS
157 // 8.9 Enum Classes.
158 @ExpectedGenericString("sealed enum AnotherEnum")
159 enum AnotherEnum {
160 BAR{};
161 }
162
163 @ExpectedGenericString("final value class AValueClass<E>")
164 value class AValueClass<E> {}
165
166 // Test cases for sealed/non-sealed _class_ hierarchy.
167 @ExpectedGenericString("sealed class SealedRootClass")
168 sealed class SealedRootClass
169 permits
170 SealedRootClass.ChildA,
171 SealedRootClass.ChildB,
172 SealedRootClass.ChildC {
173
174 @ExpectedGenericString("final class SealedRootClass$ChildA")
175 final class ChildA extends SealedRootClass {}
176
177 @ExpectedGenericString("sealed class SealedRootClass$ChildB")
178 sealed class ChildB extends SealedRootClass permits SealedRootClass.ChildB.GrandChildAB {
179 @ExpectedGenericString("final class SealedRootClass$ChildB$GrandChildAB")
180 final class GrandChildAB extends ChildB {}
181 }
182
183 @ExpectedGenericString("non-sealed class SealedRootClass$ChildC")
184 non-sealed class ChildC extends SealedRootClass {
185 // The subclasses of ChildC do not themselves have to be
|