1 /*
   2  * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.internal.misc;
  27 
  28 import java.lang.module.ModuleDescriptor;
  29 import java.lang.reflect.Layer;
  30 import java.lang.reflect.Module;
  31 import java.net.URI;
  32 import java.util.stream.Stream;
  33 
  34 import jdk.internal.module.ServicesCatalog;
  35 
  36 /**
  37  * Provides access to non-public methods in java.lang.reflect.Module
  38  */
  39 
  40 public interface JavaLangReflectModuleAccess {
  41 
  42     /**
  43      * Defines the unnamed module for the given class loader.
  44      */
  45     Module defineUnnamedModule(ClassLoader loader);
  46 
  47     /**
  48      * Defines a new module to the Java virtual machine. The module
  49      * is defined to the given class loader.
  50      *
  51      * The URI is for information purposes only, it can be {@code null}.
  52      */
  53     Module defineModule(ClassLoader loader, ModuleDescriptor descriptor, URI uri);
  54 
  55     /**
  56      * Updates the readability so that module m1 reads m2. The new read edge
  57      * does not result in a strong reference to m2 (m2 can be GC'ed).
  58      *
  59      * This method is the same as m1.addReads(m2) but without a permission check.
  60      */
  61     void addReads(Module m1, Module m2);
  62 
  63     /**
  64      * Updates module m to read all unnamed modules.
  65      */
  66     void addReadsAllUnnamed(Module m);
  67 
  68     /**
  69      * Updates module m1 to export a package to module m2. The export does
  70      * not result in a strong reference to m2 (m2 can be GC'ed).
  71      */
  72     void addExports(Module m1, String pkg, Module m2);
  73 
  74     /**
  75      * Updates module m1 to open a package to module m2. Opening the
  76      * package does not result in a strong reference to m2 (m2 can be GC'ed).
  77      */
  78     void addOpens(Module m1, String pkg, Module m2);
  79 
  80     /**
  81      * Updates a module m to export a package to all modules.
  82      */
  83     void addExportsToAll(Module m, String pkg);
  84 
  85     /**
  86      * Updates a module m to open a package to all modules.
  87      */
  88     void addOpensToAll(Module m, String pkg);
  89 
  90     /**
  91      * Updates a module m to export a package to all unnamed modules.
  92      */
  93     void addExportsToAllUnnamed(Module m, String pkg);
  94 
  95     /**
  96      * Updates a module m to open a package to all unnamed modules.
  97      */
  98     void addOpensToAllUnnamed(Module m, String pkg);
  99 
 100     /**
 101      * Updates a module m to use a service.
 102      */
 103     void addUses(Module m, Class<?> service);
 104 
 105     /**
 106      * Add a package to the given module.
 107      */
 108     void addPackage(Module m, String pkg);
 109 
 110     /**
 111      * Returns the ServicesCatalog for the given Layer.
 112      */
 113     ServicesCatalog getServicesCatalog(Layer layer);
 114 
 115     /**
 116      * Returns an ordered stream of layers. The first element is is the
 117      * given layer, the remaining elements are its parents, in DFS order.
 118      */
 119     Stream<Layer> layers(Layer layer);
 120 
 121     /**
 122      * Returns a stream of the layers that have modules defined to the
 123      * given class loader.
 124      */
 125     Stream<Layer> layers(ClassLoader loader);
 126 
 127     /**
 128      * Tests if a module exports a package at least {@code other} via its
 129      * module declaration.
 130      *
 131      * @apiNote This is a temporary method for debugging features.
 132      */
 133     boolean isStaticallyExported(Module module, String pn, Module other);
 134 }