Class Reflector

java.lang.Object
overit.geocall.util.Reflector

public class Reflector extends Object
Utility class that have utility routine to facilitate the java reflection.
  • Constructor Details

    • Reflector

      public Reflector()
  • Method Details

    • getStaticInt

      public static int getStaticInt(Class c, String name, int def)
      Returns the static int
      Parameters:
      c - The Class to get the int
      name - The name of the field
      def - The default value
      Returns:
      The static int of the class with the corrisponding name, if not found returns def
    • getStaticLong

      public static Long getStaticLong(Class c, String name, Long def)
      Returns the static long
      Parameters:
      c - The Class to get the long
      name - The name of the field
      def - The default value
      Returns:
      The static long of the class with the corrisponding name, if not found returns def
    • getAccessibleField

      public static Field getAccessibleField(String name, Class cc, Class superexcluded) throws NoSuchFieldException
      Returns the accessible field
      Parameters:
      name - The name of the declared field
      cc - The Class to get the field
      superexcluded - The Class to exclude
      Returns:
      The accessible Field
      Throws:
      NoSuchFieldException - if there is no such filed
    • getAccessibleFields

      public static ArrayList<Field> getAccessibleFields(Class cc, Class superexcluded)
      Returns the accessible field
      Parameters:
      cc - The Class to get the field
      superexcluded - The Class to exclude
      Returns:
      An arraylist with the Field
    • getAllMethods

      public static Method[] getAllMethods(Class c, String name, boolean sub, Class... params)
      Returns all the methods of a class
      Parameters:
      c - The Class to get the methods
      name - The name of the method to not include
      sub - Boolean indicating if the class is a sub class of params
      params - The Class used to match the methods
      Returns:
      An array of all the Method
    • matchMethod

      public static boolean matchMethod(Method m, String name, boolean sub, Class... params)
      Returns if the method match
      Parameters:
      m - The Method used to match
      name - The name of the method to not include
      sub - Boolean indicating if the class is a sub class of params
      params - The Class used to match the methods
      Returns:
      true if the method match, false otherwise
    • getSuperGenericClass

      public static Class<?> getSuperGenericClass(Class<?> c, int n, Class<?> def)
      query for the nth generic type of the parent of a class. This method perform a lookup only to the direct super class (if any)
      Parameters:
      c - the class to be queried
      n - the nth generic to be looked for
      def - the default class returned when the nth generic type is not a class (for example it is a variable) or if the parent has no generics
      Returns:
      the Class type of the generic
    • findSuperGenericClass

      public static Class<?> findSuperGenericClass(Class<?> c, int n, Class<?> def)
      query for the nth generic type of the parent of a class. This method perform a lookup over the super classes hierarchy
      Parameters:
      c - the class to be queried
      n - the nth generic to be looked for
      def - the default class returned when the nth generic type is not a class (for example it is a variable) or if the parent has no generics
      Returns:
      the Class type of the generic