< prev index next > src/java.base/share/classes/java/lang/module/ModuleDescriptor.java
Print this page
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.UncheckedIOException;
+ import java.lang.reflect.AccessFlag;
import java.nio.ByteBuffer;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
public enum Modifier {
/**
* An open module. An open module does not declare any open packages
* but the resulting module is treated as if all packages are open.
*/
! OPEN,
/**
* An automatic module. An automatic module is treated as if it exports
* and opens all packages.
*
* @apiNote This modifier does not correspond to a module flag in the
* binary form of a module declaration ({@code module-info.class}).
*/
! AUTOMATIC,
/**
* The module was not explicitly or implicitly declared.
*/
! SYNTHETIC,
/**
* The module was implicitly declared.
*/
! MANDATED;
- }
/**
* <p> A dependence upon a module. </p>
*
* @see ModuleDescriptor#requires()
public enum Modifier {
/**
* An open module. An open module does not declare any open packages
* but the resulting module is treated as if all packages are open.
*/
! OPEN(AccessFlag.OPEN.mask()),
/**
* An automatic module. An automatic module is treated as if it exports
* and opens all packages.
*
* @apiNote This modifier does not correspond to a module flag in the
* binary form of a module declaration ({@code module-info.class}).
*/
! AUTOMATIC(0 /* no flag per above comment */),
/**
* The module was not explicitly or implicitly declared.
*/
! SYNTHETIC(AccessFlag.SYNTHETIC.mask()),
/**
* The module was implicitly declared.
*/
! MANDATED(AccessFlag.MANDATED.mask());
+ private int mask;
+ private Modifier(int mask) {
+ this.mask = mask;
+ }
+ private int mask() {return mask;}
+ }
/**
* <p> A dependence upon a module. </p>
*
* @see ModuleDescriptor#requires()
/**
* The dependence causes any module which depends on the <i>current
* module</i> to have an implicitly declared dependence on the module
* named by the {@code Requires}.
*/
! TRANSITIVE,
/**
* The dependence is mandatory in the static phase, during compilation,
* but is optional in the dynamic phase, during execution.
*/
! STATIC,
/**
* The dependence was not explicitly or implicitly declared in the
* source of the module declaration.
*/
! SYNTHETIC,
/**
* The dependence was implicitly declared in the source of the module
* declaration.
*/
! MANDATED;
!
}
-
private final Set<Modifier> mods;
private final String name;
private final Version compiledVersion;
private final String rawCompiledVersion;
/**
* The dependence causes any module which depends on the <i>current
* module</i> to have an implicitly declared dependence on the module
* named by the {@code Requires}.
*/
! TRANSITIVE(AccessFlag.TRANSITIVE.mask()),
/**
* The dependence is mandatory in the static phase, during compilation,
* but is optional in the dynamic phase, during execution.
*/
! STATIC(AccessFlag.STATIC.mask()),
/**
* The dependence was not explicitly or implicitly declared in the
* source of the module declaration.
*/
! SYNTHETIC(AccessFlag.SYNTHETIC.mask()),
/**
* The dependence was implicitly declared in the source of the module
* declaration.
*/
! MANDATED(AccessFlag.MANDATED.mask());
! private int mask;
+ private Modifier(int mask) {
+ this.mask = mask;
+ }
+ private int mask() {return mask;}
}
private final Set<Modifier> mods;
private final String name;
private final Version compiledVersion;
private final String rawCompiledVersion;
*/
public Set<Modifier> modifiers() {
return mods;
}
+ /**
+ * {@return an unmodifiable set of the module {@linkplain AccessFlag
+ * requires flags, possibly empty}}
+ * @see #modifiers()
+ * @jvms 4.7.25 The Module Attribute
+ * @since 20
+ */
+ public Set<AccessFlag> accessFlags() {
+ int mask = 0;
+ for (var modifier : mods) {
+ mask |= modifier.mask();
+ }
+ return AccessFlag.maskToAccessFlags(mask, AccessFlag.Location.MODULE_REQUIRES);
+ }
+
/**
* Return the module name.
*
* @return The module name
*/
/**
* The export was not explicitly or implicitly declared in the
* source of the module declaration.
*/
! SYNTHETIC,
/**
* The export was implicitly declared in the source of the module
* declaration.
*/
! MANDATED;
}
private final Set<Modifier> mods;
private final String source;
private final Set<String> targets; // empty if unqualified export
/**
* The export was not explicitly or implicitly declared in the
* source of the module declaration.
*/
! SYNTHETIC(AccessFlag.SYNTHETIC.mask()),
/**
* The export was implicitly declared in the source of the module
* declaration.
*/
! MANDATED(AccessFlag.MANDATED.mask());
+ private int mask;
+ private Modifier(int mask) {
+ this.mask = mask;
+ }
+ private int mask() {return mask;}
}
private final Set<Modifier> mods;
private final String source;
private final Set<String> targets; // empty if unqualified export
*/
public Set<Modifier> modifiers() {
return mods;
}
+ /**
+ * {@return an unmodifiable set of the module {@linkplain AccessFlag
+ * export flags} for this module descriptor, possibly empty}
+ * @see #modifiers()
+ * @jvms 4.7.25 The Module Attribute
+ * @since 20
+ */
+ public Set<AccessFlag> accessFlags() {
+ int mask = 0;
+ for (var modifier : mods) {
+ mask |= modifier.mask();
+ }
+ return AccessFlag.maskToAccessFlags(mask, AccessFlag.Location.MODULE_EXPORTS);
+ }
+
/**
* Returns {@code true} if this is a qualified export.
*
* @return {@code true} if this is a qualified export
*/
/**
* The open package was not explicitly or implicitly declared in
* the source of the module declaration.
*/
! SYNTHETIC,
/**
* The open package was implicitly declared in the source of the
* module declaration.
*/
! MANDATED;
!
}
private final Set<Modifier> mods;
private final String source;
private final Set<String> targets; // empty if unqualified export
/**
* The open package was not explicitly or implicitly declared in
* the source of the module declaration.
*/
! SYNTHETIC(AccessFlag.SYNTHETIC.mask()),
/**
* The open package was implicitly declared in the source of the
* module declaration.
*/
! MANDATED(AccessFlag.MANDATED.mask());
! private int mask;
+ private Modifier(int mask) {
+ this.mask = mask;
+ }
+ private int mask() {return mask;}
}
private final Set<Modifier> mods;
private final String source;
private final Set<String> targets; // empty if unqualified export
*/
public Set<Modifier> modifiers() {
return mods;
}
+ /**
+ * {@return an unmodifiable set of the module {@linkplain AccessFlag
+ * opens flags}, possibly empty}
+ * @see #modifiers()
+ * @jvms 4.7.25 The Module Attribute
+ * @since 20
+ */
+ public Set<AccessFlag> accessFlags() {
+ int mask = 0;
+ for (var modifier : mods) {
+ mask |= modifier.mask();
+ }
+ return AccessFlag.maskToAccessFlags(mask, AccessFlag.Location.MODULE_OPENS);
+ }
+
/**
* Returns {@code true} if this is a qualified {@code Opens}.
*
* @return {@code true} if this is a qualified {@code Opens}
*/
*/
public Set<Modifier> modifiers() {
return modifiers;
}
+ /**
+ * {@return an unmodifiable set of the {@linkplain AccessFlag
+ * module flags}, possibly empty}
+ * @see #modifiers()
+ * @jvms 4.7.25 The Module Attribute
+ * @since 20
+ */
+ public Set<AccessFlag> accessFlags() {
+ int mask = 0;
+ for (var modifier : modifiers) {
+ mask |= modifier.mask();
+ }
+ return AccessFlag.maskToAccessFlags(mask, AccessFlag.Location.MODULE);
+ }
+
/**
* <p> Returns {@code true} if this is an open module. </p>
*
* <p> This method is equivalent to testing if the set of {@link #modifiers()
* modifiers} contains the {@link Modifier#OPEN OPEN} modifier. </p>
< prev index next >