Class ReflectionUtils

java.lang.Object
org.apache.juneau.commons.reflect.ReflectionUtils

public class ReflectionUtils extends Object
Utility class providing convenient static methods for creating reflection info objects.

This class provides static factory methods that convert standard Java reflection objects (Class, Method, Field, Constructor) to their corresponding info wrapper objects (ClassInfo, MethodInfo, FieldInfo, ConstructorInfo).

Features:
  • Convenient factory methods - convert reflection objects to info wrappers
  • Null-safe - methods handle null inputs gracefully
  • Unified API - consistent method naming across all reflection types
Use Cases:
  • Converting reflection objects to info wrappers in a consistent way
  • Simplifying code that works with both reflection and info objects
  • Providing a centralized location for reflection-to-info conversions
Usage:

// Convert Class to ClassInfo ClassInfo ci = ReflectionUtils.info(MyClass.class); // Convert Method to MethodInfo Method m = MyClass.class.getMethod("myMethod"); MethodInfo mi = ReflectionUtils.info(m); // Convert Field to FieldInfo Field f = MyClass.class.getField("myField"); FieldInfo fi = ReflectionUtils.info(f); // Convert Constructor to ConstructorInfo Constructor<?> c = MyClass.class.getConstructor(); ConstructorInfo ci2 = ReflectionUtils.info(c);

Null Handling:

All methods in this class handle null inputs gracefully, returning null if the input is null. This makes it safe to use in scenarios where reflection objects may be null.

See Also:
  • Constructor Details

  • Method Details

    • info

      public static final <T> ClassInfoTyped<T> info(Class<T> o)
      Returns the ClassInfo wrapper for the specified class.
      Example:

      ClassInfo ci = ReflectionUtils.info(MyClass.class);

      Parameters:
      o - The class to wrap. Can be null.
      Returns:
      The ClassInfo wrapper, or null if the input is null.
    • info

      public static final ConstructorInfo info(Constructor<?> o)
      Returns the ConstructorInfo wrapper for the specified constructor.
      Example:

      Constructor<?> c = MyClass.class.getConstructor(); ConstructorInfo ci = ReflectionUtils.info(c);

      Parameters:
      o - The constructor to wrap. Can be null.
      Returns:
      The ConstructorInfo wrapper, or null if the input is null.
    • info

      public static final FieldInfo info(Field o)
      Returns the FieldInfo wrapper for the specified field.
      Example:

      Field f = MyClass.class.getField("myField"); FieldInfo fi = ReflectionUtils.info(f);

      Parameters:
      o - The field to wrap. Can be null.
      Returns:
      The FieldInfo wrapper, or null if the input is null.
    • info

      public static final MethodInfo info(Method o)
      Returns the MethodInfo wrapper for the specified method.
      Example:

      Method m = MyClass.class.getMethod("myMethod"); MethodInfo mi = ReflectionUtils.info(m);

      Parameters:
      o - The method to wrap. Can be null.
      Returns:
      The MethodInfo wrapper, or null if the input is null.
    • info

      public static final ClassInfo info(Object o)
      Returns the ClassInfo wrapper for the class of the specified object.
      Example:

      MyClass obj = new MyClass(); ClassInfo ci = ReflectionUtils.info(obj);

      Parameters:
      o - The object whose class to wrap. Can be null.
      Returns:
      The ClassInfo wrapper for the object's class, or null if the input is null.