A ModuleReference proxy, written using reflection to preserve backwards compatibility with JDK 7 and 8.
| 40 | |
| 41 | /** A ModuleReference proxy, written using reflection to preserve backwards compatibility with JDK 7 and 8. */ |
| 42 | public class ModuleRef implements Comparable<ModuleRef> { |
| 43 | /** The name of the module. */ |
| 44 | private final String name; |
| 45 | |
| 46 | /** The ModuleReference for the module. */ |
| 47 | private final Object reference; |
| 48 | |
| 49 | /** The ModuleLayer for the module. */ |
| 50 | private final Object layer; |
| 51 | |
| 52 | /** The ModuleDescriptor for the module. */ |
| 53 | private final Object descriptor; |
| 54 | |
| 55 | /** The packages in the module. */ |
| 56 | private final List<String> packages; |
| 57 | |
| 58 | /** The location URI for the module (may be null). */ |
| 59 | private final URI location; |
| 60 | |
| 61 | /** The location URI for the module, as a cached string (may be null). */ |
| 62 | private String locationStr; |
| 63 | |
| 64 | /** A file formed from the location URI. The file will not exist if the location URI is a "jrt:" URI. */ |
| 65 | private File locationFile; |
| 66 | |
| 67 | /** The raw module version, or null if none. */ |
| 68 | private String rawVersion; |
| 69 | |
| 70 | /** The ClassLoader that loads classes in the module. May be null, to represent the bootstrap classloader. */ |
| 71 | private final ClassLoader classLoader; |
| 72 | |
| 73 | ReflectionUtils reflectionUtils; |
| 74 | |
| 75 | /** |
| 76 | * Constructor. |
| 77 | * |
| 78 | * @param moduleReference |
| 79 | * The module reference, of JPMS type ModuleReference. |
| 80 | * @param moduleLayer |
| 81 | * The module layer, of JPMS type ModuleLayer |
| 82 | * @param reflectionUtils |
| 83 | * The ReflectionUtils instance. |
| 84 | */ |
| 85 | public ModuleRef(final Object moduleReference, final Object moduleLayer, |
| 86 | final ReflectionUtils reflectionUtils) { |
| 87 | if (moduleReference == null) { |
| 88 | throw new IllegalArgumentException("moduleReference cannot be null"); |
| 89 | } |
| 90 | if (moduleLayer == null) { |
| 91 | throw new IllegalArgumentException("moduleLayer cannot be null"); |
| 92 | } |
| 93 | this.reference = moduleReference; |
| 94 | this.layer = moduleLayer; |
| 95 | this.reflectionUtils = reflectionUtils; |
| 96 | |
| 97 | this.descriptor = reflectionUtils.invokeMethod(/* throwException = */ true, moduleReference, "descriptor"); |
| 98 | if (this.descriptor == null) { |
| 99 | // Should not happen |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…