2929import java .io .IOException ;
3030import java .io .PrintStream ;
3131import java .io .UncheckedIOException ;
32+ import java .lang .reflect .AccessFlag ;
3233import java .nio .ByteBuffer ;
3334import java .nio .file .Path ;
3435import java .util .ArrayList ;
@@ -105,7 +106,7 @@ public enum Modifier {
105106 * An open module. An open module does not declare any open packages
106107 * but the resulting module is treated as if all packages are open.
107108 */
108- OPEN ,
109+ OPEN ( AccessFlag . OPEN . mask ()) ,
109110
110111 /**
111112 * An automatic module. An automatic module is treated as if it exports
@@ -114,19 +115,24 @@ public enum Modifier {
114115 * @apiNote This modifier does not correspond to a module flag in the
115116 * binary form of a module declaration ({@code module-info.class}).
116117 */
117- AUTOMATIC ,
118+ AUTOMATIC ( 0 /* no flag per above comment */ ) ,
118119
119120 /**
120121 * The module was not explicitly or implicitly declared.
121122 */
122- SYNTHETIC ,
123+ SYNTHETIC ( AccessFlag . SYNTHETIC . mask ()) ,
123124
124125 /**
125126 * The module was implicitly declared.
126127 */
127- MANDATED ;
128- }
128+ MANDATED (AccessFlag .MANDATED .mask ());
129129
130+ private final int mask ;
131+ private Modifier (int mask ) {
132+ this .mask = mask ;
133+ }
134+ private int mask () {return mask ;}
135+ }
130136
131137 /**
132138 * <p> A dependence upon a module. </p>
@@ -152,28 +158,31 @@ public enum Modifier {
152158 * module</i> to have an implicitly declared dependence on the module
153159 * named by the {@code Requires}.
154160 */
155- TRANSITIVE ,
161+ TRANSITIVE ( AccessFlag . TRANSITIVE . mask ()) ,
156162
157163 /**
158164 * The dependence is mandatory in the static phase, during compilation,
159165 * but is optional in the dynamic phase, during execution.
160166 */
161- STATIC ,
167+ STATIC ( AccessFlag . STATIC_PHASE . mask ()) ,
162168
163169 /**
164170 * The dependence was not explicitly or implicitly declared in the
165171 * source of the module declaration.
166172 */
167- SYNTHETIC ,
173+ SYNTHETIC ( AccessFlag . SYNTHETIC . mask ()) ,
168174
169175 /**
170176 * The dependence was implicitly declared in the source of the module
171177 * declaration.
172178 */
173- MANDATED ;
174-
179+ MANDATED (AccessFlag .MANDATED .mask ());
180+ private final int mask ;
181+ private Modifier (int mask ) {
182+ this .mask = mask ;
183+ }
184+ private int mask () {return mask ;}
175185 }
176-
177186 private final Set <Modifier > mods ;
178187 private final String name ;
179188 private final Version compiledVersion ;
@@ -203,6 +212,21 @@ public Set<Modifier> modifiers() {
203212 return mods ;
204213 }
205214
215+ /**
216+ * {@return an unmodifiable set of the module {@linkplain AccessFlag
217+ * requires flags, possibly empty}}
218+ * @see #modifiers()
219+ * @jvms 4.7.25 The Module Attribute
220+ * @since 20
221+ */
222+ public Set <AccessFlag > accessFlags () {
223+ int mask = 0 ;
224+ for (var modifier : mods ) {
225+ mask |= modifier .mask ();
226+ }
227+ return AccessFlag .maskToAccessFlags (mask , AccessFlag .Location .MODULE_REQUIRES );
228+ }
229+
206230 /**
207231 * Return the module name.
208232 *
@@ -376,14 +400,19 @@ public enum Modifier {
376400 * The export was not explicitly or implicitly declared in the
377401 * source of the module declaration.
378402 */
379- SYNTHETIC ,
403+ SYNTHETIC ( AccessFlag . SYNTHETIC . mask ()) ,
380404
381405 /**
382406 * The export was implicitly declared in the source of the module
383407 * declaration.
384408 */
385- MANDATED ;
409+ MANDATED ( AccessFlag . MANDATED . mask ()) ;
386410
411+ private final int mask ;
412+ private Modifier (int mask ) {
413+ this .mask = mask ;
414+ }
415+ private int mask () {return mask ;}
387416 }
388417
389418 private final Set <Modifier > mods ;
@@ -417,6 +446,21 @@ public Set<Modifier> modifiers() {
417446 return mods ;
418447 }
419448
449+ /**
450+ * {@return an unmodifiable set of the module {@linkplain AccessFlag
451+ * export flags} for this module descriptor, possibly empty}
452+ * @see #modifiers()
453+ * @jvms 4.7.25 The Module Attribute
454+ * @since 20
455+ */
456+ public Set <AccessFlag > accessFlags () {
457+ int mask = 0 ;
458+ for (var modifier : mods ) {
459+ mask |= modifier .mask ();
460+ }
461+ return AccessFlag .maskToAccessFlags (mask , AccessFlag .Location .MODULE_EXPORTS );
462+ }
463+
420464 /**
421465 * Returns {@code true} if this is a qualified export.
422466 *
@@ -579,14 +623,18 @@ public enum Modifier {
579623 * The open package was not explicitly or implicitly declared in
580624 * the source of the module declaration.
581625 */
582- SYNTHETIC ,
626+ SYNTHETIC ( AccessFlag . SYNTHETIC . mask ()) ,
583627
584628 /**
585629 * The open package was implicitly declared in the source of the
586630 * module declaration.
587631 */
588- MANDATED ;
589-
632+ MANDATED (AccessFlag .MANDATED .mask ());
633+ private final int mask ;
634+ private Modifier (int mask ) {
635+ this .mask = mask ;
636+ }
637+ private int mask () {return mask ;}
590638 }
591639
592640 private final Set <Modifier > mods ;
@@ -620,6 +668,21 @@ public Set<Modifier> modifiers() {
620668 return mods ;
621669 }
622670
671+ /**
672+ * {@return an unmodifiable set of the module {@linkplain AccessFlag
673+ * opens flags}, possibly empty}
674+ * @see #modifiers()
675+ * @jvms 4.7.25 The Module Attribute
676+ * @since 20
677+ */
678+ public Set <AccessFlag > accessFlags () {
679+ int mask = 0 ;
680+ for (var modifier : mods ) {
681+ mask |= modifier .mask ();
682+ }
683+ return AccessFlag .maskToAccessFlags (mask , AccessFlag .Location .MODULE_OPENS );
684+ }
685+
623686 /**
624687 * Returns {@code true} if this is a qualified {@code Opens}.
625688 *
@@ -1290,6 +1353,21 @@ public Set<Modifier> modifiers() {
12901353 return modifiers ;
12911354 }
12921355
1356+ /**
1357+ * {@return an unmodifiable set of the {@linkplain AccessFlag
1358+ * module flags}, possibly empty}
1359+ * @see #modifiers()
1360+ * @jvms 4.7.25 The Module Attribute
1361+ * @since 20
1362+ */
1363+ public Set <AccessFlag > accessFlags () {
1364+ int mask = 0 ;
1365+ for (var modifier : modifiers ) {
1366+ mask |= modifier .mask ();
1367+ }
1368+ return AccessFlag .maskToAccessFlags (mask , AccessFlag .Location .MODULE );
1369+ }
1370+
12931371 /**
12941372 * <p> Returns {@code true} if this is an open module. </p>
12951373 *
0 commit comments