34 import java.util.Set;
35
36 /*
37 * There are several patterns of access flag applicability. First, an
38 * access flag can be applied to the same set of locations for each
39 * class file format version. This is "invariant" usage. Second, an
40 * access flag can be defined for version N, therefore inapplicable
41 * for earlier versions, and then applied to the same locations for
42 * all subsequent versions. This is "step" usage. Finally, an access
43 * flag to have a more complicated pattern, having multiple steps of
44 * being allowed at more locations or even having locations removed if
45 * the access flag is retired.
46 *
47 * List of access flags and how they are tested:
48 *
49 * PUBLIC step
50 * PRIVATE step
51 * PROTECTED step
52 * STATIC step
53 * FINAL two-step
54 * SUPER invariant
55 * OPEN step
56 * TRANSITIVE step
57 * SYNCHRONIZED invariant
58 * STATIC_PHASE step
59 * VOLATILE invariant
60 * BRIDGE step
61 * TRANSIENT invariant
62 * VARARGS step
63 * NATIVE invariant
64 * INTERFACE step
65 * ABSTRACT step
66 * STRICT other
67 * SYNTHETIC other (three-step)
68 * ANNOTATION step
69 * ENUM step
70 * MANDATED two-step
71 * MODULE step
72 */
73
74 public class VersionedLocationsTest {
75 public static void main(String... args) throws Exception {
76 testInvariantAccessFlags();
77 testStepFunctionAccessFlags();
78 testTwoStepAccessFlags();
79 testSynthetic();
80 testStrict();
81 testLatestMatch();
82 }
83
84 /**
85 * Invariant access flags have the same set of locations for each
86 * class file format version.
87 */
88 private static void testInvariantAccessFlags() {
89 Set<AccessFlag> invariantAccessFlags =
90 Set.of(SUPER, SYNCHRONIZED, VOLATILE, TRANSIENT, NATIVE);
91 for(var accessFlag : invariantAccessFlags) {
92 Set<AccessFlag.Location> expected = accessFlag.locations();
93
94 for(var cffv : ClassFileFormatVersion.values()) {
95 compareLocations(accessFlag.locations(), accessFlag, cffv);
96 }
97 }
98 }
99
100 private static void testStepFunctionAccessFlags() {
101 StepFunctionTC[] testCases = {
102 new StepFunctionTC(PUBLIC,
103 removeInnerClass(PUBLIC.locations()),
104 ClassFileFormatVersion.RELEASE_1),
105
106 new StepFunctionTC(PRIVATE,
107 removeInnerClass(PRIVATE.locations()),
108 ClassFileFormatVersion.RELEASE_1),
109
110 new StepFunctionTC(PROTECTED,
111 removeInnerClass(PROTECTED.locations()),
112 ClassFileFormatVersion.RELEASE_1),
113
114 new StepFunctionTC(STATIC,
115 removeInnerClass(STATIC.locations()),
116 ClassFileFormatVersion.RELEASE_1),
117
118 new StepFunctionTC(OPEN,
119 Set.of(),
120 ClassFileFormatVersion.RELEASE_9),
121
122 new StepFunctionTC(TRANSITIVE,
123 Set.of(),
124 ClassFileFormatVersion.RELEASE_9),
125
126 new StepFunctionTC(STATIC_PHASE,
127 Set.of(),
128 ClassFileFormatVersion.RELEASE_9),
129
130 new StepFunctionTC(BRIDGE,
131 Set.of(),
132 ClassFileFormatVersion.RELEASE_5),
133
134 new StepFunctionTC(VARARGS,
135 Set.of(),
136 ClassFileFormatVersion.RELEASE_5),
137
|
34 import java.util.Set;
35
36 /*
37 * There are several patterns of access flag applicability. First, an
38 * access flag can be applied to the same set of locations for each
39 * class file format version. This is "invariant" usage. Second, an
40 * access flag can be defined for version N, therefore inapplicable
41 * for earlier versions, and then applied to the same locations for
42 * all subsequent versions. This is "step" usage. Finally, an access
43 * flag to have a more complicated pattern, having multiple steps of
44 * being allowed at more locations or even having locations removed if
45 * the access flag is retired.
46 *
47 * List of access flags and how they are tested:
48 *
49 * PUBLIC step
50 * PRIVATE step
51 * PROTECTED step
52 * STATIC step
53 * FINAL two-step
54 * SUPER step
55 * OPEN step
56 * TRANSITIVE step
57 * SYNCHRONIZED invariant
58 * STATIC_PHASE step
59 * VOLATILE invariant
60 * BRIDGE step
61 * TRANSIENT invariant
62 * VARARGS step
63 * NATIVE invariant
64 * INTERFACE step
65 * ABSTRACT step
66 * STRICT other
67 * SYNTHETIC other (three-step)
68 * ANNOTATION step
69 * ENUM step
70 * MANDATED two-step
71 * MODULE step
72 */
73
74 public class VersionedLocationsTest {
75 public static void main(String... args) throws Exception {
76 testInvariantAccessFlags();
77 testStepFunctionAccessFlags();
78 testTwoStepAccessFlags();
79 testSynthetic();
80 testStrict();
81 testLatestMatch();
82 }
83
84 /**
85 * Invariant access flags have the same set of locations for each
86 * class file format version.
87 */
88 private static void testInvariantAccessFlags() {
89 Set<AccessFlag> invariantAccessFlags =
90 Set.of(SYNCHRONIZED, VOLATILE, TRANSIENT, NATIVE);
91 for(var accessFlag : invariantAccessFlags) {
92 Set<AccessFlag.Location> expected = accessFlag.locations();
93
94 for(var cffv : ClassFileFormatVersion.values()) {
95 compareLocations(accessFlag.locations(), accessFlag, cffv);
96 }
97 }
98 }
99
100 private static void testStepFunctionAccessFlags() {
101 StepFunctionTC[] testCases = {
102 new StepFunctionTC(PUBLIC,
103 removeInnerClass(PUBLIC.locations()),
104 ClassFileFormatVersion.RELEASE_1),
105
106 new StepFunctionTC(PRIVATE,
107 removeInnerClass(PRIVATE.locations()),
108 ClassFileFormatVersion.RELEASE_1),
109
110 new StepFunctionTC(PROTECTED,
111 removeInnerClass(PROTECTED.locations()),
112 ClassFileFormatVersion.RELEASE_1),
113
114 new StepFunctionTC(STATIC,
115 removeInnerClass(STATIC.locations()),
116 ClassFileFormatVersion.RELEASE_1),
117
118 new StepFunctionTC(SUPER,
119 Set.of(AccessFlag.Location.CLASS),
120 ClassFileFormatVersion.RELEASE_22),
121
122 new StepFunctionTC(OPEN,
123 Set.of(),
124 ClassFileFormatVersion.RELEASE_9),
125
126 new StepFunctionTC(TRANSITIVE,
127 Set.of(),
128 ClassFileFormatVersion.RELEASE_9),
129
130 new StepFunctionTC(STATIC_PHASE,
131 Set.of(),
132 ClassFileFormatVersion.RELEASE_9),
133
134 new StepFunctionTC(BRIDGE,
135 Set.of(),
136 ClassFileFormatVersion.RELEASE_5),
137
138 new StepFunctionTC(VARARGS,
139 Set.of(),
140 ClassFileFormatVersion.RELEASE_5),
141
|