Package ghidra.app.util.bin.format.golang.structmapping

# Class ReflectionHelper

java.lang.Object
ghidra.app.util.bin.format.golang.structmapping.ReflectionHelper

public class ReflectionHelper extends Object

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ReflectionHelper()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `assignField(Field field, Object obj, Object value)`
  Write a value to a field in a java class.
  `static <T> T`
  `callCtor(Constructor<T> ctor, Object... params)`
  `static <T> Object`
  `callGetter(Method getterMethod, T obj)`
  `static <T, R> R`
  `callGetter(Method getterMethod, T obj, Class<R> expectedType)`
  `static <T> void`
  `callSetter(Object obj, Method setterMethod, T value)`
  `static <T, CTX> T`
  `createInstance(Class<T> targetClass, CTX optionalContext)`
  Creates an instance of the specified target class, using an optional context parameter to the constructor.
  `static Method`
  `findGetter(Class<?> structClass, String getterName)`
  `static Method`
  `findSetter(String fieldName, String setterNameOverride, Class<?> structClass, Class<?> valueClass)`
  `static <T extends Annotation>
  List<T>`
  `getAnnotations(Class<?> targetClass, Class<T> annotationClass, List<T> result)`
  `static DataType`
  `getArrayOutputDataType(Object array_value, Class<?> fieldType, int length, Signedness signedness, DataTypeMapper dataTypeMapper)`
  Return Ghidra data type representing an array of primitive values.
  `static Method`
  `getCommentMethod(Class<?> clazz, String commentGetterName, String defaultGetterName)`
  `static <T> Constructor<T>`
  `getCtor(Class<T> clazz, Class<?>... paramTypes)`
  `static Signedness`
  `getDataTypeSignedness(DataType dt)`
  `static <R> R`
  `getFieldValue(Object obj, Field field, Class<R> expectedType)`
  `static List<Method>`
  `getMarkedMethods(Class<?> targetClass, Class<? extends Annotation> annotationClass, List<Method> methods, boolean includeParentClasses, Class<?>... paramClasses)`
  Returns a list of methods that have been marked with a specific annotation.
  `static DataType`
  `getPrimitiveOutputDataType(Class<?> fieldType, int length, Signedness signedness, DataTypeMapper dataTypeMapper)`
  `static int`
  `getPrimitiveSizeof(Class<?> fieldType)`
  `static Class<?>`
  `getPrimitiveWrapper(Class<?> primitiveType)`
  `static boolean`
  `hasStructureMapping(Class<?> clazz)`
  `static void`
  `invokeMethods(List<Method> methods, Object obj, Object... params)`
  `static boolean`
  `isPrimitiveType(Class<?> clazz)`
  `static Method`
  `requireGetter(Class<?> clazz, String getterName)`

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

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

- ## Constructor Details

  - ### ReflectionHelper

    public ReflectionHelper()

- ## Method Details

  - ### isPrimitiveType

    public static boolean isPrimitiveType(Class<?> clazz)

  - ### getPrimitiveWrapper

    public static Class<?> getPrimitiveWrapper(Class<?> primitiveType)

  - ### assignField

    public static void assignField(Field field, Object obj, Object value) throws IOException
    Write a value to a field in a java class.
    Parameters:
      `field` - reflection `Field`
      `obj` - java instance that contains the field
      `value` - value to write
    Throws:
      `IOException` - if error accessing field or converting value

  - ### getArrayOutputDataType

    public static DataType getArrayOutputDataType(Object array_value, Class<?> fieldType, int length, Signedness signedness, DataTypeMapper dataTypeMapper)
    Return Ghidra data type representing an array of primitive values.
    Parameters:
      `array_value` - java array object
      `fieldType` - class representing the java array type
      `length` - length of an element of the array, or -1
      `signedness` - `Signedness` enum
      `dataTypeMapper` - program level structure mapping context
    Returns:
      Ghdira `ArrayDataType` representing the specified java array type

  - ### getPrimitiveOutputDataType

    public static DataType getPrimitiveOutputDataType(Class<?> fieldType, int length, Signedness signedness, DataTypeMapper dataTypeMapper)

  - ### getPrimitiveSizeof

    public static int getPrimitiveSizeof(Class<?> fieldType)

  - ### hasStructureMapping

    public static boolean hasStructureMapping(Class<?> clazz)

  - ### getDataTypeSignedness

    public static Signedness getDataTypeSignedness(DataType dt)

  - ### getCommentMethod

    public static Method getCommentMethod(Class<?> clazz, String commentGetterName, String defaultGetterName)

  - ### requireGetter

    public static Method requireGetter(Class<?> clazz, String getterName)

  - ### findGetter

    public static Method findGetter(Class<?> structClass, String getterName)

  - ### findSetter

    public static Method findSetter(String fieldName, String setterNameOverride, Class<?> structClass, Class<?> valueClass)

  - ### getCtor

    public static <T> Constructor<T> getCtor(Class<T> clazz, Class<?>... paramTypes)

  - ### invokeMethods

    public static void invokeMethods(List<Method> methods, Object obj, Object... params) throws IOException
    Throws:
      `IOException`

  - ### createInstance

    public static <T, CTX> T createInstance(Class<T> targetClass, CTX optionalContext) throws IllegalArgumentException
    Creates an instance of the specified target class, using an optional context parameter to the constructor.
    Type Parameters:
      `T` - type of the class to be created
      `CTX` - type of the context to be passed to the constructor
    Parameters:
      `targetClass` - class to be created
      `optionalContext` - anything, or null
    Returns:
      new instance of type T
    Throws:
      `IllegalArgumentException` - if error creating instance

  - ### callCtor

    public static <T> T callCtor(Constructor<T> ctor, Object... params) throws IllegalArgumentException
    Throws:
      `IllegalArgumentException`

  - ### callGetter

    public static <T> Object callGetter(Method getterMethod, T obj) throws IOException
    Throws:
      `IOException`

  - ### callGetter

    public static <T, R> R callGetter(Method getterMethod, T obj, Class<R> expectedType) throws IOException
    Throws:
      `IOException`

  - ### callSetter

    public static <T> void callSetter(Object obj, Method setterMethod, T value) throws IOException
    Throws:
      `IOException`

  - ### getMarkedMethods

    public static List<Method> getMarkedMethods(Class<?> targetClass, Class<? extends Annotation> annotationClass, List<Method> methods, boolean includeParentClasses, Class<?>... paramClasses)
    Returns a list of methods that have been marked with a specific annotation.
    Parameters:
      `targetClass` - class to query
      `annotationClass` - annotation to search for
      `methods` - list to accumulate results into, or null to allocate new list. Also returned as the result of this function
      `includeParentClasses` - boolean flag, if true recurse into parent classes first
      `paramClasses` - list of parameters that the tagged methods should declare. Methods will be skipped if they don't match
    Returns:
      list of found methods that match the annotation and param list

  - ### getAnnotations

    public static <T extends Annotation> List<T> getAnnotations(Class<?> targetClass, Class<T> annotationClass, List<T> result)

  - ### getFieldValue

    public static <R> R getFieldValue(Object obj, Field field, Class<R> expectedType) throws IOException
    Throws:
      `IOException`