Package org.eclipse.net4j.util

## Class ReflectUtil

- java.lang.Object
- - org.eclipse.net4j.util.ReflectUtil

-     public final class ReflectUtil
      extends java.lang.Object

  Various static helper methods for dealing with Java reflection.
  Since:
    3.14
  Author:
    Eike Stepper

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static interface` | `ReflectUtil.ExcludeFromDump` | Annotates fields that are to be skipped in `ReflectUtil.collectFields()` and `ReflectUtil.toString()`.
    `static class` | `ReflectUtil.PrimitiveType` |
    `static class` | `ReflectUtil.ReflectionException` |

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static boolean` | `DUMP_STATICS` |
    `static java.lang.Object[]` | `NO_ARGUMENTS` |
    `static java.lang.Class<?>[]` | `NO_PARAMETERS` |
    `static boolean` | `REMEMBER_IDS` |
    `static java.lang.Class<java.lang.Object>` | `ROOT_CLASS` |

  - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static void` | `appendStackTrace​(java.lang.StringBuilder builder, java.lang.StackTraceElement[] stackTrace)` |
    `static void` | `collectFields​(java.lang.Class<?> c, java.util.List<java.lang.reflect.Field> fields)` |
    `static void` | `dump​(java.lang.Object object)` |
    `static void` | `dump​(java.lang.Object object, java.lang.String prefix)` |
    `static void` | `dump​(java.lang.Object object, java.lang.String prefix, java.io.PrintStream out)` |
    `static java.lang.String` | `dumpThread()` |
    `static Pair<java.lang.reflect.Field,​java.lang.Object>[]` | `dumpToArray​(java.lang.Object object)` |
    `static java.lang.reflect.Field` | `getAccessibleField​(java.lang.Class<?> c, java.lang.String fieldName)` | Deprecated. As of 3.14 use `getField(Class, String)`.
    `static java.lang.reflect.Field` | `getField​(java.lang.Class<?> c, java.lang.String fieldName)` |
    `static java.lang.Integer` | `getHashCode​(java.lang.Object object)` |
    `static java.lang.Long` | `getID​(java.lang.Object object)` |
    `static java.lang.String` | `getLabel​(java.lang.Object object)` |
    `static java.lang.reflect.Method` | `getMethod​(java.lang.Class<?> c, java.lang.String methodName, java.lang.Class<?>... parameterTypes)` |
    `static java.lang.String` | `getPackageName​(java.lang.Class<? extends java.lang.Object> c)` |
    `static java.lang.String` | `getPackageName​(java.lang.String className)` |
    `static java.lang.String` | `getSimpleClassName​(java.lang.Object object)` |
    `static java.lang.String` | `getSimpleClassName​(java.lang.String name)` |
    `static java.lang.String` | `getSimpleName​(java.lang.Class<? extends java.lang.Object> c)` |
    `static java.lang.Object` | `getValue​(java.lang.reflect.Field field, java.lang.Object target)` |
    `static <T> T` | `getValue​(java.lang.String fieldName, java.lang.Object target)` |
    `static java.lang.Object` | `instantiate​(java.util.Map<java.lang.Object,​java.lang.Object> properties, java.lang.String namespace, java.lang.String classKey, java.lang.ClassLoader classLoader)` |
    `static java.lang.Object` | `invokeMethod​(java.lang.reflect.Method method, java.lang.Object target, java.lang.Object... arguments)` |
    `static <T> T` | `invokeMethod​(java.lang.String methodName, java.lang.Object target)` |
    `static boolean` | `isSetter​(java.lang.reflect.Method method)` |
    `static boolean` | `isSetterName​(java.lang.String name)` |
    `static <T> void` | `makeAccessible​(java.lang.reflect.AccessibleObject accessibleObject)` |
    `static void` | `printStackTrace()` | Prints the stack trace of the current thread to `System.err`.
    `static void` | `printStackTrace​(java.io.PrintStream out, java.lang.StackTraceElement[] stackTrace)` |
    `static void` | `printStackTrace​(java.lang.StackTraceElement[] stackTrace)` |
    `static void` | `setValue​(java.lang.reflect.Field field, java.lang.Object target, java.lang.Object value)` |
    `static void` | `setValue​(java.lang.reflect.Field field, java.lang.Object target, java.lang.Object value, boolean force)` |
    `static java.lang.String` | `toString​(java.lang.Object object)` |
    `static java.lang.String` | `toString​(java.lang.Object object, java.lang.String prefix)` |

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### ROOT_CLASS

          public static final java.lang.Class<java.lang.Object> ROOT_CLASS

    - #### NO_PARAMETERS

          public static final java.lang.Class<?>[] NO_PARAMETERS

    - #### NO_ARGUMENTS

          public static final java.lang.Object[] NO_ARGUMENTS

    - #### REMEMBER_IDS

          public static boolean REMEMBER_IDS

      Since:
        3.3

    - #### DUMP_STATICS

          public static boolean DUMP_STATICS

  - ### Method Detail

    - #### makeAccessible

          public static <T> void makeAccessible​(java.lang.reflect.AccessibleObject accessibleObject)

      Since:
        3.12

    - #### getMethod

          public static java.lang.reflect.Method getMethod​(java.lang.Class<?> c,
                                                           java.lang.String methodName,
                                                           java.lang.Class<?>... parameterTypes)

    - #### invokeMethod

          public static java.lang.Object invokeMethod​(java.lang.reflect.Method method,
                                                      java.lang.Object target,
                                                      java.lang.Object... arguments)

    - #### invokeMethod

          public static <T> T invokeMethod​(java.lang.String methodName,
                                           java.lang.Object target)

      Since:
        3.14

    - #### getField

          public static java.lang.reflect.Field getField​(java.lang.Class<?> c,
                                                         java.lang.String fieldName)

    - #### getAccessibleField

          @Deprecated
          public static java.lang.reflect.Field getAccessibleField​(java.lang.Class<?> c,
                                                                   java.lang.String fieldName)

      Deprecated.
      As of 3.14 use `getField(Class, String)`.
      Since:
        3.8

    - #### collectFields

          public static void collectFields​(java.lang.Class<?> c,
                                           java.util.List<java.lang.reflect.Field> fields)

    - #### getValue

          public static java.lang.Object getValue​(java.lang.reflect.Field field,
                                                  java.lang.Object target)

    - #### getValue

          public static <T> T getValue​(java.lang.String fieldName,
                                       java.lang.Object target)

      Since:
        3.14

    - #### setValue

          public static void setValue​(java.lang.reflect.Field field,
                                      java.lang.Object target,
                                      java.lang.Object value)

    - #### setValue

          public static void setValue​(java.lang.reflect.Field field,
                                      java.lang.Object target,
                                      java.lang.Object value,
                                      boolean force)

      Since:
        3.14

    - #### dumpThread

          public static java.lang.String dumpThread()

      Since:
        3.8

    - #### appendStackTrace

          public static void appendStackTrace​(java.lang.StringBuilder builder,
                                              java.lang.StackTraceElement[] stackTrace)

      Since:
        3.11

    - #### printStackTrace

          public static void printStackTrace​(java.io.PrintStream out,
                                             java.lang.StackTraceElement[] stackTrace)

    - #### printStackTrace

          public static void printStackTrace​(java.lang.StackTraceElement[] stackTrace)

    - #### printStackTrace

          public static void printStackTrace()

      Prints the stack trace of the current thread to `System.err`.
      Since:
        3.4

    - #### getHashCode

          public static java.lang.Integer getHashCode​(java.lang.Object object)

    - #### getID

          public static java.lang.Long getID​(java.lang.Object object)

    - #### getPackageName

          public static java.lang.String getPackageName​(java.lang.Class<? extends java.lang.Object> c)

    - #### getPackageName

          public static java.lang.String getPackageName​(java.lang.String className)

    - #### getSimpleName

          public static java.lang.String getSimpleName​(java.lang.Class<? extends java.lang.Object> c)

    - #### getSimpleClassName

          public static java.lang.String getSimpleClassName​(java.lang.String name)

    - #### getSimpleClassName

          public static java.lang.String getSimpleClassName​(java.lang.Object object)

    - #### getLabel

          public static java.lang.String getLabel​(java.lang.Object object)

    - #### dump

          public static void dump​(java.lang.Object object)

    - #### dump

          public static void dump​(java.lang.Object object,
                                  java.lang.String prefix)

    - #### dump

          public static void dump​(java.lang.Object object,
                                  java.lang.String prefix,
                                  java.io.PrintStream out)

    - #### dumpToArray

          public static Pair<java.lang.reflect.Field,​java.lang.Object>[] dumpToArray​(java.lang.Object object)

    - #### instantiate

          public static java.lang.Object instantiate​(java.util.Map<java.lang.Object,​java.lang.Object> properties,
                                                     java.lang.String namespace,
                                                     java.lang.String classKey,
                                                     java.lang.ClassLoader classLoader)
                                              throws java.lang.ClassNotFoundException,
                                                     java.lang.InstantiationException,
                                                     java.lang.IllegalAccessException,
                                                     java.lang.IllegalArgumentException,
                                                     java.lang.reflect.InvocationTargetException

      Throws:
        `java.lang.ClassNotFoundException`
        `java.lang.InstantiationException`
        `java.lang.IllegalAccessException`
        `java.lang.IllegalArgumentException`
        `java.lang.reflect.InvocationTargetException`

    - #### isSetter

          public static boolean isSetter​(java.lang.reflect.Method method)

    - #### isSetterName

          public static boolean isSetterName​(java.lang.String name)

    - #### toString

          public static java.lang.String toString​(java.lang.Object object)

    - #### toString

          public static java.lang.String toString​(java.lang.Object object,
                                                  java.lang.String prefix)