Class ReflectionUtil

java.lang.Object
net.orbyfied.j8.util.ReflectionUtil

public class ReflectionUtil extends Object
Utilities for working with reflection safely.
  • Constructor Details

    • ReflectionUtil

      public ReflectionUtil()
  • Method Details

    • getCallerClass

      public static Class<?> getCallerClass(int off)
      Get the caller class at the provided offset.
      Parameters:
      off - The offset into the call stack.
      Returns:
      The caller class.
      See Also:
    • getCallerFrame

      public static StackTraceElement getCallerFrame(int off)
      Get the caller stack trace element at the provided offset.
      Parameters:
      off - The offset into the call stack.
      Returns:
      The stack trace element.
    • getCallerFrame

      public static StackTraceElement getCallerFrame(int off, Predicate<StackTraceElement> pred)
    • walkParents

      public static void walkParents(Class<?> klass, Predicate<Class<?>> pred, Consumer<Class<?>> consumer)
    • walkParents

      public static void walkParents(Class<?> klass, Predicate<Class<?>> pred, BiConsumer<Integer,Class<?>> consumer)
    • internalWalkParents

      public static void internalWalkParents(Class<?> klass, Predicate<Class<?>> pred, BiConsumer<Integer,Class<?>> consumer, int depth)
    • printParentTree

      public static void printParentTree(PrintStream out, Class<?> klass)
    • printParentTree

      public static void printParentTree(Class<?> klass)
    • printCallTree

      public static void printCallTree(PrintStream out, int off)
    • printCallTree

      public static void printCallTree()
    • printCallTree

      public static void printCallTree(int off)
    • printCallTree

      public static void printCallTree(PrintStream out)
    • getClassSafe

      public static Class<?> getClassSafe(String name)
    • getDeclaredFieldSafe

      public static Field getDeclaredFieldSafe(Class<?> klass, String name)
    • getDeclaredMethodSafe

      public static Method getDeclaredMethodSafe(Class<?> klass, String name, Class... argTypes)
    • getDeclaredConstructorSafe

      public static Constructor<?> getDeclaredConstructorSafe(Class<?> klass, Class... argTypes)
    • queryFieldSafe

      public static <T> T queryFieldSafe(Object on, Field f)
    • setFieldSafe

      public static void setFieldSafe(Object on, Field f, Object val)
    • invokeSafe

      public static <T> T invokeSafe(Method m, Object on, Object... args)
    • newInstance

      public static <T> T newInstance(Constructor<?> c, Object... args)