Host class reference.
| 7 | * Host class reference. |
| 8 | */ |
| 9 | public class Initiator { |
| 10 | private static ClassLoader sHostClassLoader; |
| 11 | private static ClassLoader sPluginParentClassLoader; |
| 12 | |
| 13 | private Initiator() { |
| 14 | throw new AssertionError("No instance for you!"); |
| 15 | } |
| 16 | |
| 17 | public static void initWithHostClassLoader(ClassLoader classLoader) { |
| 18 | sHostClassLoader = classLoader; |
| 19 | sPluginParentClassLoader = Initiator.class.getClassLoader(); |
| 20 | } |
| 21 | |
| 22 | public static ClassLoader getPluginClassLoader() { |
| 23 | return Initiator.class.getClassLoader(); |
| 24 | } |
| 25 | |
| 26 | public static ClassLoader getHostClassLoader() { |
| 27 | return sHostClassLoader; |
| 28 | } |
| 29 | |
| 30 | @NonNull |
| 31 | public static Class<?> loadClass(@NonNull String className) throws ClassNotFoundException { |
| 32 | Class<?> clazz = load(className); |
| 33 | if (clazz == null) { |
| 34 | throw new ClassNotFoundException(className); |
| 35 | } |
| 36 | return clazz; |
| 37 | } |
| 38 | |
| 39 | @Nullable |
| 40 | public static Class<?> load(String className) { |
| 41 | if (className == null || className.isEmpty()) { |
| 42 | return null; |
| 43 | } |
| 44 | className = className.replace('/', '.'); |
| 45 | if (className.endsWith(";")) { |
| 46 | if (className.charAt(0) == 'L') { |
| 47 | className = className.substring(1, className.length() - 1); |
| 48 | } else { |
| 49 | className = className.substring(0, className.length() - 1); |
| 50 | } |
| 51 | } |
| 52 | if (className.startsWith(".")) { |
| 53 | className = HostInfo.getPackageName() + className; |
| 54 | } |
| 55 | try { |
| 56 | return sHostClassLoader.loadClass(className); |
| 57 | } catch (ClassNotFoundException ignored) { |
| 58 | } |
| 59 | try { |
| 60 | return sPluginParentClassLoader.loadClass(className); |
| 61 | } catch (ClassNotFoundException ignored) { |
| 62 | return null; |
| 63 | } |
| 64 | } |
| 65 | } |
nothing calls this directly
no outgoing calls
no test coverage detected