Class ReflectionUtil


  • public class ReflectionUtil
    extends java.lang.Object
    Provide reflection utility methods for probes.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String OBJECT_SIG  
      static java.lang.String SIG_SEP  
      static java.lang.String STRING_SIG  
    • Constructor Summary

      Constructors 
      Constructor Description
      ReflectionUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object callMethod0​(java.lang.Class<?> aClass, java.lang.Object object, java.lang.String methodName, CallStatus callStatus)
      Invokes instance or static method with no parameters and any return type.
      static java.lang.Object callMethod0​(java.lang.Object object, java.lang.String methodName)
      Invokes instance method with no parameters and any return type.
      static java.lang.Object callMethod0​(java.lang.Object object, java.lang.String methodName, CallStatus callStatus)
      Invokes instance method with no parameters and any return type.
      static java.lang.Object callMethod1​(java.lang.Class<?> aClass, java.lang.Object object, java.lang.String methodNameAndSignature, java.lang.Object arg1, CallStatus callStatus)
      Invokes a method with one parameter and any return type.
      static long getFieldPrimValue​(java.lang.Class<?> aClass, java.lang.Object object, java.lang.String fieldName)
      Gets the value of a field of primitive type, either instance or static.
      static long getFieldPrimValue​(java.lang.Object object, java.lang.String fieldName)
      Gets the value of an instance field of primitive type.
      static <T> T getFieldValue​(java.lang.Class<?> aClass, java.lang.Object object, java.lang.String fieldName)
      Gets value of a reference field, either instance or static
      static <T> T getFieldValue​(java.lang.Class<?> aClass, java.lang.Object object, java.lang.String fieldName, CallStatus callStatus)
      Gets value of a reference field, either instance or static
      static <T> T getFieldValue​(java.lang.Object object, java.lang.String fieldName)  
      static void setFieldObjectValue​(java.lang.Class<?> aClass, java.lang.Object object, java.lang.String fieldName, java.lang.Object value)
      Sets value to a reference field, either instance or static
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ReflectionUtil

        public ReflectionUtil()
    • Method Detail

      • callMethod0

        @Nullable
        public static java.lang.Object callMethod0​(@NotNull
                                                   java.lang.Class<?> aClass,
                                                   @Nullable
                                                   java.lang.Object object,
                                                   @NotNull
                                                   java.lang.String methodName,
                                                   @Nullable
                                                   CallStatus callStatus)
        Invokes instance or static method with no parameters and any return type.
        Parameters:
        object - should be NULL for static method
        callStatus - if specified, allows to retrieve thrown exception if the call fails
        Returns:
        the method return value, or NULL if the method has thrown an exception or cannot be called (e.g. does not exist)
      • callMethod0

        @Nullable
        public static java.lang.Object callMethod0​(@NotNull
                                                   java.lang.Object object,
                                                   @NotNull
                                                   java.lang.String methodName,
                                                   @Nullable
                                                   CallStatus callStatus)
        Invokes instance method with no parameters and any return type.
        Parameters:
        callStatus - if specified, allows to retrieve thrown exception if the call fails
        Returns:
        the method return value, or NULL if the method has thrown an exception or cannot be called (e.g. does not exist)
      • callMethod0

        @Nullable
        public static java.lang.Object callMethod0​(@NotNull
                                                   java.lang.Object object,
                                                   @NotNull
                                                   java.lang.String methodName)
        Invokes instance method with no parameters and any return type.
        Returns:
        the method return value, or NULL if the method has thrown an exception or cannot be called (e.g. does not exist)
      • callMethod1

        @Nullable
        public static java.lang.Object callMethod1​(@NotNull
                                                   java.lang.Class<?> aClass,
                                                   @Nullable
                                                   java.lang.Object object,
                                                   @NotNull
                                                   java.lang.String methodNameAndSignature,
                                                   @Nullable
                                                   java.lang.Object arg1,
                                                   @Nullable
                                                   CallStatus callStatus)
        Invokes a method with one parameter and any return type.
        Parameters:
        object - should be NULL for static method
      • getFieldValue

        @Nullable
        public static <T> T getFieldValue​(@NotNull
                                          java.lang.Object object,
                                          @NotNull
                                          java.lang.String fieldName)
      • getFieldValue

        @Nullable
        public static <T> T getFieldValue​(@NotNull
                                          java.lang.Class<?> aClass,
                                          @Nullable
                                          java.lang.Object object,
                                          @NotNull
                                          java.lang.String fieldName,
                                          @Nullable
                                          CallStatus callStatus)
        Gets value of a reference field, either instance or static
      • getFieldValue

        @Nullable
        public static <T> T getFieldValue​(@NotNull
                                          java.lang.Class<?> aClass,
                                          @Nullable
                                          java.lang.Object object,
                                          @NotNull
                                          java.lang.String fieldName)
        Gets value of a reference field, either instance or static
      • setFieldObjectValue

        public static void setFieldObjectValue​(@NotNull
                                               java.lang.Class<?> aClass,
                                               @Nullable
                                               java.lang.Object object,
                                               @NotNull
                                               java.lang.String fieldName,
                                               @Nullable
                                               java.lang.Object value)
        Sets value to a reference field, either instance or static
      • getFieldPrimValue

        public static long getFieldPrimValue​(@NotNull
                                             java.lang.Class<?> aClass,
                                             @Nullable
                                             java.lang.Object object,
                                             @NotNull
                                             java.lang.String fieldName)
        Gets the value of a field of primitive type, either instance or static.
      • getFieldPrimValue

        public static long getFieldPrimValue​(@NotNull
                                             java.lang.Object object,
                                             @NotNull
                                             java.lang.String fieldName)
        Gets the value of an instance field of primitive type.