-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
143 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package java.lang; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* Dummy java compatibility class | ||
* | ||
* @author Matt | ||
*/ | ||
public abstract class Module { | ||
|
||
//CHECKSTYLE:OFF | ||
public ModuleLayer getLayer() { throw new UnsupportedOperationException(); } | ||
public Set<String> getPackages() { throw new UnsupportedOperationException(); } | ||
//CHECKSTYLE:ON | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package java.lang; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* Dummy java compatibility class | ||
* | ||
* @author xxDark | ||
*/ | ||
public abstract class ModuleLayer { | ||
|
||
//CHECKSTYLE:OFF | ||
public Set<Module> modules() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
public static ModuleLayer boot() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
//CHECKSTYLE:ON | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package me.coley.recaf.util; | ||
|
||
import java.lang.invoke.MethodHandle; | ||
import java.lang.invoke.MethodHandles; | ||
import java.lang.invoke.MethodHandles.Lookup; | ||
import java.lang.invoke.MethodType; | ||
import java.lang.reflect.Field; | ||
|
||
/** | ||
* Package-private util to deal with modules. | ||
* | ||
* @author xxDark | ||
*/ | ||
final class Java9Util { | ||
|
||
private static final MethodHandle CLASS_MODULE; | ||
private static final MethodHandle CLASS_LOADER_MDOULE; | ||
|
||
/** | ||
* Deny all constructions. | ||
*/ | ||
private Java9Util() { | ||
} | ||
|
||
/** | ||
* @param klass {@link Class} to get module from. | ||
* @return {@link Module} of the class. | ||
*/ | ||
static Module getClassModule(Class<?> klass) { | ||
try { | ||
return (Module) CLASS_MODULE.invokeExact(klass); | ||
} catch (Throwable t) { | ||
// That should never happen. | ||
throw new AssertionError(t); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* @param loader {@link ClassLoader} to get module from. | ||
* @return {@link Module} of the class. | ||
*/ | ||
static Module getLoaderModule(ClassLoader loader) { | ||
try { | ||
return (Module) CLASS_LOADER_MDOULE.invokeExact(loader); | ||
} catch (Throwable t) { | ||
// That should never happen. | ||
throw new AssertionError(t); | ||
} | ||
} | ||
|
||
static { | ||
try { | ||
Field field = Lookup.class.getDeclaredField("IMPL_LOOKUP"); | ||
field.setAccessible(true); | ||
MethodHandles.publicLookup(); | ||
Lookup lookup = (Lookup) field.get(null); | ||
MethodType type = MethodType.methodType(Module.class); | ||
CLASS_MODULE = lookup.findVirtual(Class.class, "getModule", type); | ||
CLASS_LOADER_MDOULE = lookup.findVirtual(ClassLoader.class, "getUnnamedModule", type); | ||
} catch (NoSuchMethodException | IllegalAccessException | NoSuchFieldException ex) { | ||
throw new ExceptionInInitializerError(ex); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters