11874abe40afe1bda2b3ffc1bce0e444cbce667f2Erich Douglasspackage org.robolectric.internal.bytecode;
2e876a8fad71b3098795fc08a08f794795123442bChristian Williams
31021315c11e619e0735bea1349e04023178c4067Alexander Blomimport java.lang.invoke.MethodHandle;
41021315c11e619e0735bea1349e04023178c4067Alexander Blomimport java.lang.invoke.MethodType;
58c1cb81758ccdbc6249527f4e408c11850ff2e08Erich Douglassimport org.robolectric.util.ReflectionHelpers;
65bd5b619cbc1515a5470a2478ffa0835a8682996Christian Williams
7b5d56e95f27d484ad3098ac18867262e7c8826c1Christian Williams & Phil Goodwinpublic class RobolectricInternals {
829a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams
98c1cb81758ccdbc6249527f4e408c11850ff2e08Erich Douglass  @SuppressWarnings("UnusedDeclaration")
1029a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams  private static ClassHandler classHandler; // initialized via magic by SdkEnvironment
1129a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams
128c1cb81758ccdbc6249527f4e408c11850ff2e08Erich Douglass  @SuppressWarnings("UnusedDeclaration")
131021315c11e619e0735bea1349e04023178c4067Alexander Blom  private static ShadowInvalidator shadowInvalidator;
141021315c11e619e0735bea1349e04023178c4067Alexander Blom
151021315c11e619e0735bea1349e04023178c4067Alexander Blom  @SuppressWarnings("UnusedDeclaration")
16cdaac16def26d7a694e4a3e1e4578435e9d77221Christian Williams  private static SandboxClassLoader classLoader;
17704d59a9e57b28939ba5c709cf4b50d72aa072e6Christian Williams
18704d59a9e57b28939ba5c709cf4b50d72aa072e6Christian Williams  @SuppressWarnings("UnusedDeclaration")
1929a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams  public static void classInitializing(Class clazz) throws Exception {
2029a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams    classHandler.classInitializing(clazz);
2129a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams  }
2229a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams
238c1cb81758ccdbc6249527f4e408c11850ff2e08Erich Douglass  @SuppressWarnings("UnusedDeclaration")
2429a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams  public static Object initializing(Object instance) throws Exception {
2529a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams    return classHandler.initializing(instance);
2629a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams  }
2729a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams
288c1cb81758ccdbc6249527f4e408c11850ff2e08Erich Douglass  @SuppressWarnings("UnusedDeclaration")
2929a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams  public static ClassHandler.Plan methodInvoked(String signature, boolean isStatic, Class<?> theClass) {
3029a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams    return classHandler.methodInvoked(signature, isStatic, theClass);
3129a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams  }
3229a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams
331021315c11e619e0735bea1349e04023178c4067Alexander Blom  public static MethodHandle getShadowCreator(Class<?> caller) {
341021315c11e619e0735bea1349e04023178c4067Alexander Blom    return classHandler.getShadowCreator(caller);
351021315c11e619e0735bea1349e04023178c4067Alexander Blom  }
361021315c11e619e0735bea1349e04023178c4067Alexander Blom
371021315c11e619e0735bea1349e04023178c4067Alexander Blom  public static MethodHandle findShadowMethod(Class<?> theClass, String name,
381021315c11e619e0735bea1349e04023178c4067Alexander Blom      MethodType type, boolean isStatic) throws IllegalAccessException {
391021315c11e619e0735bea1349e04023178c4067Alexander Blom    return classHandler.findShadowMethod(theClass, name, type, isStatic);
401021315c11e619e0735bea1349e04023178c4067Alexander Blom  }
411021315c11e619e0735bea1349e04023178c4067Alexander Blom
428c1cb81758ccdbc6249527f4e408c11850ff2e08Erich Douglass  @SuppressWarnings("UnusedDeclaration")
431021315c11e619e0735bea1349e04023178c4067Alexander Blom  public static Throwable cleanStackTrace(Throwable exception) {
448c1cb81758ccdbc6249527f4e408c11850ff2e08Erich Douglass    return classHandler.stripStackTrace(exception);
458c1cb81758ccdbc6249527f4e408c11850ff2e08Erich Douglass  }
468c1cb81758ccdbc6249527f4e408c11850ff2e08Erich Douglass
4729a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams  public static Object intercept(String signature, Object instance, Object[] params, Class theClass) throws Throwable {
4829a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams    try {
4929a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams      return classHandler.intercept(signature, instance, params, theClass);
5097cd4c165846e15d003001e0eeea1eba33860361Christopher Amavisca and Ryan Spore    } catch (java.lang.LinkageError e) {
5129a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams      throw new Exception(e);
5229a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams    }
5329a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams  }
5429a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams
5529a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams  public static void performStaticInitialization(Class<?> clazz) {
56adc73c73d7ab98d2a5d6383295260ebf3d4ca4f9Erich Douglass    ReflectionHelpers.callStaticMethod(clazz, ShadowConstants.STATIC_INITIALIZER_METHOD_NAME);
5729a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams  }
581021315c11e619e0735bea1349e04023178c4067Alexander Blom
591021315c11e619e0735bea1349e04023178c4067Alexander Blom  public static ShadowInvalidator getShadowInvalidator() {
601021315c11e619e0735bea1349e04023178c4067Alexander Blom    return shadowInvalidator;
611021315c11e619e0735bea1349e04023178c4067Alexander Blom  }
62704d59a9e57b28939ba5c709cf4b50d72aa072e6Christian Williams
636b22a728f68e128cbf6a1131084855e188a912a9Christian Williams  public static ClassLoader getClassLoader() {
64704d59a9e57b28939ba5c709cf4b50d72aa072e6Christian Williams    return classLoader;
65704d59a9e57b28939ba5c709cf4b50d72aa072e6Christian Williams  }
66e876a8fad71b3098795fc08a08f794795123442bChristian Williams}
67