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 8266670 8291734 8296743
27 * @summary Test expected AccessFlag's on classes.
28 */
29
30 import java.lang.annotation.*;
31 import java.lang.reflect.*;
32 import java.util.*;
33
34 import static java.lang.reflect.AccessFlag.*;
35
36 /*
37 * Class access flags that can directly or indirectly declared in
38 * source include:
39 * public, private, protected, static, final, interface, abstract,
40 * annotation, enum.
41 *
42 * Additionally, the access flags super and synthetic cannot be
43 * explicitly applied.
44 *
45 * This test is written on top of the facilities of core reflection.
46 *
47 * Note that core reflection does not offer a supported mechanism to
48 * return the Class object created from a module-info.class
49 * file. Therefore, this test does not attempt to probe the setting of
50 * that access flag.
51 */
52 @ExpectedClassFlags({PUBLIC, FINAL, SUPER})
53 public final class ClassAccessFlagTest {
54 public static void main(String... args) {
55 // Top-level and auxiliary classes; i.e. non-inner classes
56 Class<?>[] testClasses = {
57 ClassAccessFlagTest.class,
58 TestInterface.class,
59 ExpectedClassFlags.class,
60 TestOuterEnum.class
61 };
62 checkClasses(testClasses);
63
64 // Nested classes of ClassAccessFlagTest
65 checkClasses(ClassAccessFlagTest.class.getDeclaredClasses());
66
67 checkPrimitives();
68 checkArrays();
69 }
70
71 private static void checkClasses(Class<?>[] classes) {
72 for (var clazz : classes) {
73 checkClass(clazz);
74 }
|
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 8266670 8291734 8296743
27 * @summary Test expected AccessFlag's on classes.
28 * @modules java.base/jdk.internal.misc
29 * @library /test/lib ..
30 * @enablePreview
31 */
32
33
34 import jdk.internal.misc.PreviewFeatures;
35
36 import java.lang.annotation.*;
37 import java.lang.reflect.*;
38 import java.util.*;
39
40 import jtreg.SkippedException;
41
42
43 import static java.lang.reflect.AccessFlag.*;
44
45 /*
46 * Class access flags that can directly or indirectly declared in
47 * source include:
48 * public, private, protected, static, final, interface, abstract,
49 * annotation, enum.
50 *
51 * Additionally, the access flags super and synthetic cannot be
52 * explicitly applied.
53 *
54 * This test is written on top of the facilities of core reflection.
55 *
56 * Note that core reflection does not offer a supported mechanism to
57 * return the Class object created from a module-info.class
58 * file. Therefore, this test does not attempt to probe the setting of
59 * that access flag.
60 */
61 @ExpectedClassFlags({PUBLIC, FINAL, SUPER})
62 public final class ClassAccessFlagTest {
63 public static void main(String... args) {
64 if (PreviewFeatures.isEnabled()) {
65 throw new SkippedException("Preview mode not supported");
66 }
67 // Top-level and auxiliary classes; i.e. non-inner classes
68 Class<?>[] testClasses = {
69 ClassAccessFlagTest.class,
70 TestInterface.class,
71 ExpectedClassFlags.class,
72 TestOuterEnum.class
73 };
74 checkClasses(testClasses);
75
76 // Nested classes of ClassAccessFlagTest
77 checkClasses(ClassAccessFlagTest.class.getDeclaredClasses());
78
79 checkPrimitives();
80 checkArrays();
81 }
82
83 private static void checkClasses(Class<?>[] classes) {
84 for (var clazz : classes) {
85 checkClass(clazz);
86 }
|