68 import jdk.internal.org.objectweb.asm.Opcodes;
69 import jdk.internal.reflect.CallerSensitive;
70 import jdk.internal.reflect.Reflection;
71 import sun.security.util.SecurityConstants;
72
73 /**
74 * Represents a run-time module, either {@link #isNamed() named} or unnamed.
75 *
76 * <p> Named modules have a {@link #getName() name} and are constructed by the
77 * Java Virtual Machine when a graph of modules is defined to the Java virtual
78 * machine to create a {@linkplain ModuleLayer module layer}. </p>
79 *
80 * <p> An unnamed module does not have a name. There is an unnamed module for
81 * each {@link ClassLoader ClassLoader}, obtained by invoking its {@link
82 * ClassLoader#getUnnamedModule() getUnnamedModule} method. All types that are
83 * not in a named module are members of their defining class loader's unnamed
84 * module. </p>
85 *
86 * <p> The package names that are parameters or returned by methods defined in
87 * this class are the fully-qualified names of the packages as defined in
88 * section 6.5.3 of <cite>The Java™ Language Specification</cite>, for
89 * example, {@code "java.lang"}. </p>
90 *
91 * <p> Unless otherwise specified, passing a {@code null} argument to a method
92 * in this class causes a {@link NullPointerException NullPointerException} to
93 * be thrown. </p>
94 *
95 * @since 9
96 * @spec JPMS
97 * @see Class#getModule()
98 */
99
100 public final class Module implements AnnotatedElement {
101
102 // the layer that contains this module, can be null
103 private final ModuleLayer layer;
104
105 // module name and loader, these fields are read by VM
106 private final String name;
107 private final ClassLoader loader;
108
655 boolean isReflectivelyExported(String pn, Module other) {
656 return isReflectivelyExportedOrOpen(pn, other, false);
657 }
658
659 /**
660 * Returns {@code true} if this module reflectively opens the
661 * given package to the given module.
662 */
663 boolean isReflectivelyOpened(String pn, Module other) {
664 return isReflectivelyExportedOrOpen(pn, other, true);
665 }
666
667
668 /**
669 * If the caller's module is this module then update this module to export
670 * the given package to the given module.
671 *
672 * <p> This method has no effect if the package is already exported (or
673 * <em>open</em>) to the given module. </p>
674 *
675 * @apiNote As specified in section 5.4.3 of the <cite>The Java™
676 * Virtual Machine Specification </cite>, if an attempt to resolve a
677 * symbolic reference fails because of a linkage error, then subsequent
678 * attempts to resolve the reference always fail with the same error that
679 * was thrown as a result of the initial resolution attempt.
680 *
681 * @param pn
682 * The package name
683 * @param other
684 * The module
685 *
686 * @return this module
687 *
688 * @throws IllegalArgumentException
689 * If {@code pn} is {@code null}, or this is a named module and the
690 * package {@code pn} is not a package in this module
691 * @throws IllegalCallerException
692 * If this is a named module and the caller's module is not this
693 * module
694 *
695 * @jvms 5.4.3 Resolution
|
68 import jdk.internal.org.objectweb.asm.Opcodes;
69 import jdk.internal.reflect.CallerSensitive;
70 import jdk.internal.reflect.Reflection;
71 import sun.security.util.SecurityConstants;
72
73 /**
74 * Represents a run-time module, either {@link #isNamed() named} or unnamed.
75 *
76 * <p> Named modules have a {@link #getName() name} and are constructed by the
77 * Java Virtual Machine when a graph of modules is defined to the Java virtual
78 * machine to create a {@linkplain ModuleLayer module layer}. </p>
79 *
80 * <p> An unnamed module does not have a name. There is an unnamed module for
81 * each {@link ClassLoader ClassLoader}, obtained by invoking its {@link
82 * ClassLoader#getUnnamedModule() getUnnamedModule} method. All types that are
83 * not in a named module are members of their defining class loader's unnamed
84 * module. </p>
85 *
86 * <p> The package names that are parameters or returned by methods defined in
87 * this class are the fully-qualified names of the packages as defined in
88 * section 6.5.3 of <cite>The Java Language Specification</cite>, for
89 * example, {@code "java.lang"}. </p>
90 *
91 * <p> Unless otherwise specified, passing a {@code null} argument to a method
92 * in this class causes a {@link NullPointerException NullPointerException} to
93 * be thrown. </p>
94 *
95 * @since 9
96 * @spec JPMS
97 * @see Class#getModule()
98 */
99
100 public final class Module implements AnnotatedElement {
101
102 // the layer that contains this module, can be null
103 private final ModuleLayer layer;
104
105 // module name and loader, these fields are read by VM
106 private final String name;
107 private final ClassLoader loader;
108
655 boolean isReflectivelyExported(String pn, Module other) {
656 return isReflectivelyExportedOrOpen(pn, other, false);
657 }
658
659 /**
660 * Returns {@code true} if this module reflectively opens the
661 * given package to the given module.
662 */
663 boolean isReflectivelyOpened(String pn, Module other) {
664 return isReflectivelyExportedOrOpen(pn, other, true);
665 }
666
667
668 /**
669 * If the caller's module is this module then update this module to export
670 * the given package to the given module.
671 *
672 * <p> This method has no effect if the package is already exported (or
673 * <em>open</em>) to the given module. </p>
674 *
675 * @apiNote As specified in section 5.4.3 of the <cite>The Java
676 * Virtual Machine Specification </cite>, if an attempt to resolve a
677 * symbolic reference fails because of a linkage error, then subsequent
678 * attempts to resolve the reference always fail with the same error that
679 * was thrown as a result of the initial resolution attempt.
680 *
681 * @param pn
682 * The package name
683 * @param other
684 * The module
685 *
686 * @return this module
687 *
688 * @throws IllegalArgumentException
689 * If {@code pn} is {@code null}, or this is a named module and the
690 * package {@code pn} is not a package in this module
691 * @throws IllegalCallerException
692 * If this is a named module and the caller's module is not this
693 * module
694 *
695 * @jvms 5.4.3 Resolution
|