Package org.eclipse.net4j.util

# Class ReflectUtil

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

public final class ReflectUtil extends 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 enum`
`ReflectUtil.PrimitiveType`
`static class`
`ReflectUtil.ReflectionException`
`static final class`
`ReflectUtil.Setting`

## Field Summary

Fields
Modifier and Type
Field
Description
`static boolean`
`DUMP_STATICS`
`static final Object[]`
`NO_ARGUMENTS`
`static final Class<?>[]`
`NO_PARAMETERS`
`static boolean`
`REMEMBER_IDS`
`static final Class<Object>`
`ROOT_CLASS`

## Method Summary

Modifier and Type
Method
Description
`static void`
`appendStackTrace(StringBuilder builder, StackTraceElement[] stackTrace)`
`static void`
`collectFields(Class<?> c, List<Field> fields)`
`static void`
`dump(Object object)`
`static void`
`dump(Object object, String prefix)`
`static void`
`dump(Object object, String prefix, PrintStream out)`
`static void`
`dump(Object object, Predicate<ReflectUtil.Setting> consumer)`
`static String`
`dumpThread()`
`static Pair<Field,Object>[]`
`dumpToArray(Object object)`
`static Field`
`getAccessibleField(Class<?> c, String fieldName)`
Deprecated.
As of 3.14 use `getField(Class, String)`.
`static Field`
`getField(Class<?> c, String fieldName)`
`static Field`
`getFieldOrNull(Class<?> c, String fieldName)`
`static Field`
`getFieldOrNullSafe(Class<?> c, String fieldName)`
`static Integer`
`getHashCode(Object object)`
`static Long`
`getID(Object object)`
`static String`
`getLabel(Object object)`
`static Method`
`getMethod(Class<?> c, String methodName, Class<?>... parameterTypes)`
`static Method`
`getMethodOrNull(Class<?> c, String methodName, Class<?>... parameterTypes)`
`static Method`
`getMethodOrNullSafe(Class<?> c, String methodName, Class<?>... parameterTypes)`
`static String`
`getPackageName(Class<? extends Object> c)`
`static String`
`getPackageName(String className)`
`static String`
`getSimpleClassName(Object object)`
`static String`
`getSimpleClassName(String name)`
`static String`
`getSimpleName(Class<? extends Object> c)`
`static Object`
`getValue(Field field, Object target)`
`static <T> T`
`getValue(String fieldName, Object target)`
`static Object`
`instantiate(Map<Object,Object> properties, String namespace, String classKey, ClassLoader classLoader)`
`static Object`
`invokeMethod(Method method, Object target, Object... arguments)`
`static <T> T`
`invokeMethod(String methodName, Object target)`
`static boolean`
`isSetter(Method method)`
`static boolean`
`isSetterName(String name)`
`static <T> void`
`makeAccessible(AccessibleObject accessibleObject)`
Deprecated.
This method performs only ordinary Java reflection accessibility handling.
`static void`
`makeAccessibleNormally(AccessibleObject accessibleObject)`
Makes a reflective object accessible using only the supported Java reflection API.
`static void`
`printStackTrace()`
Prints the stack trace of the current thread to `System.err`.
`static void`
`printStackTrace(PrintStream out, StackTraceElement[] stackTrace)`
`static void`
`printStackTrace(StackTraceElement[] stackTrace)`
`static void`
`setValue(Field field, Object target, Object value)`
`static void`
`setValue(Field field, Object target, Object value, boolean force)`
Deprecated.
The `force` parameter is retained only for API compatibility and is ignored.
`static String`
`toString(Object object)`
`static String`
`toString(Object object, String prefix)`

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

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

## Field Details

### ROOT_CLASS

public static final Class<Object> ROOT_CLASS

### NO_PARAMETERS

public static final Class<?>[] NO_PARAMETERS

### NO_ARGUMENTS

public static final Object[] NO_ARGUMENTS

### REMEMBER_IDS

public static boolean REMEMBER_IDS

Since:
  3.3

### DUMP_STATICS

public static boolean DUMP_STATICS

## Method Details

### makeAccessible

@Deprecated public static <T> void makeAccessible(AccessibleObject accessibleObject)
Deprecated.
This method performs only ordinary Java reflection accessibility handling. It does not bypass Java module-access checks, and callers must not rely on access to members rejected by normal Java access or module rules. Use `makeAccessibleNormally(AccessibleObject)`.

Since:
  3.12

### makeAccessibleNormally

public static void makeAccessibleNormally(AccessibleObject accessibleObject)
Makes a reflective object accessible using only the supported Java reflection API.

Parameters:
  `accessibleObject` - the field, method, or constructor to make accessible.
Since:
  3.30

### getMethod

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

### getMethodOrNull

public static Method getMethodOrNull(Class<?> c, String methodName, Class<?>... parameterTypes)

Since:
  3.20

### getMethodOrNullSafe

public static Method getMethodOrNullSafe(Class<?> c, String methodName, Class<?>... parameterTypes)

Since:
  3.28

### invokeMethod

public static Object invokeMethod(Method method, Object target, Object... arguments)

### invokeMethod

public static <T> T invokeMethod(String methodName, Object target)

Since:
  3.14

### getField

public static Field getField(Class<?> c, String fieldName)

### getFieldOrNull

public static Field getFieldOrNull(Class<?> c, String fieldName)

Since:
  3.28

### getFieldOrNullSafe

public static Field getFieldOrNullSafe(Class<?> c, String fieldName)

Since:
  3.28

### getAccessibleField

@Deprecated public static Field getAccessibleField(Class<?> c, String fieldName)
Deprecated.
As of 3.14 use `getField(Class, String)`.

Since:
  3.8

### collectFields

public static void collectFields(Class<?> c, List<Field> fields)

### getValue

public static Object getValue(Field field, Object target)

### getValue

public static <T> T getValue(String fieldName, Object target)

Since:
  3.14

### setValue

public static void setValue(Field field, Object target, Object value)

### setValue

@Deprecated public static void setValue(Field field, Object target, Object value, boolean force)
Deprecated.
The `force` parameter is retained only for API compatibility and is ignored. Use `setValue(Field, Object, Object)`.

Since:
  3.14

### dumpThread

public static String dumpThread()

Since:
  3.8

### appendStackTrace

public static void appendStackTrace(StringBuilder builder, StackTraceElement[] stackTrace)

Since:
  3.11

### printStackTrace

public static void printStackTrace(PrintStream out, StackTraceElement[] stackTrace)

### printStackTrace

public static void printStackTrace(StackTraceElement[] stackTrace)

### printStackTrace

public static void printStackTrace()
Prints the stack trace of the current thread to `System.err`.

Since:
  3.4

### getHashCode

public static Integer getHashCode(Object object)

### getID

public static Long getID(Object object)

### getPackageName

public static String getPackageName(Class<? extends Object> c)

### getPackageName

public static String getPackageName(String className)

### getSimpleName

public static String getSimpleName(Class<? extends Object> c)

### getSimpleClassName

public static String getSimpleClassName(String name)

### getSimpleClassName

public static String getSimpleClassName(Object object)

### getLabel

public static String getLabel(Object object)

### dump

public static void dump(Object object)

### dump

public static void dump(Object object, String prefix)

### dump

public static void dump(Object object, String prefix, PrintStream out)

### dump

public static void dump(Object object, Predicate<ReflectUtil.Setting> consumer)

Since:
  3.22

### dumpToArray

public static Pair<Field,Object>[] dumpToArray(Object object)

### instantiate

public static Object instantiate(Map<Object,Object> properties, String namespace, String classKey, ClassLoader classLoader) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException

Throws:
  `ClassNotFoundException`
  `InstantiationException`
  `IllegalAccessException`
  `IllegalArgumentException`
  `InvocationTargetException`

### isSetter

public static boolean isSetter(Method method)

### isSetterName

public static boolean isSetterName(String name)

### toString

public static String toString(Object object)

### toString

public static String toString(Object object, String prefix)