Module xl.core

Class Reflection

java.lang.Object
de.grogra.reflect.Reflection

public final class Reflection extends Object
  • Method Details

    • getJVMTypeId

      public static int getJVMTypeId(Type type)
    • getJVMPrefix

      public static char getJVMPrefix(int typeId)
    • getJVMPrefix

      public static char getJVMPrefix(Type type)
    • getJVMStackSize

      public static int getJVMStackSize(Type type)
      Returns the number of stack elements which are needed for the storage of values of the given type within the Java virtual machine.
      Parameters:
      type - a type
      Returns:
      the required size in terms of stack elements
    • getJVMStackSize

      public static int getJVMStackSize(Type[] types)
    • getDimensionCount

      public static int getDimensionCount(Type type)
    • getDeclaredFields

      public static Field[] getDeclaredFields(Type type)
    • getDeclaredMethods

      public static Method[] getDeclaredMethods(Type type)
    • getDeclaredInterfaces

      public static Type[] getDeclaredInterfaces(Type type)
    • getDeclaredTypes

      public static Type[] getDeclaredTypes(Type type)
    • getExceptions

      public static Type[] getExceptions(Method method)
    • getParameterTypes

      public static Type[] getParameterTypes(Signature m)
    • getParameterType

      public static Type getParameterType(Signature m, int index, boolean varArity)
    • membersEqual

      public static boolean membersEqual(Member m1, Member m2, boolean ignoreDeclaringType)
    • find

      public static Member find(Member[] members, String nameOrDescriptor)
    • getSyntheticName

      public static String getSyntheticName(Member[] members, String name)
    • modifiersToString

      public static String modifiersToString(int mods)
    • isStatic

      public static boolean isStatic(Member m)
    • isFinal

      public static boolean isFinal(Member m)
    • isPrivate

      public static boolean isPrivate(Member m)
    • isProtected

      public static boolean isProtected(Member m)
    • isPublic

      public static boolean isPublic(Member m)
    • hasDefaultAccess

      public static boolean hasDefaultAccess(Member m)
    • isAbstract

      public static boolean isAbstract(Member m)
    • isInner

      public static boolean isInner(Type m)
    • isMoreVisible

      public static boolean isMoreVisible(int mods1, int mods2)
    • equal

      public static boolean equal(Signature s1, Signature s2)
    • getDescription

      public static String getDescription(Member m)
    • getMethodDescriptor

      public static String getMethodDescriptor(String name, Type returnType, Type[] parameterTypes)
    • getFieldDescriptor

      public static String getFieldDescriptor(String name, Type type)
    • get

      public static Object get(Object object, Field field) throws IllegalAccessException
      Throws:
      IllegalAccessException
    • set

      public static void set(Object object, Field field, Object value) throws IllegalAccessException
      Throws:
      IllegalAccessException
    • toString

      public static String toString(Field field)
    • getDescriptor

      public static String getDescriptor(Type[] types)
    • getTopLevelType

      public static Type getTopLevelType(Type type)
    • isMember

      public static boolean isMember(Member member, Type type)
      Returns true iff member is a member of type. This is the case if member is declared in type or one of its supertypes.
      Parameters:
      member - a member
      type - a type
      Returns:
      true iff member is a member of type
    • getEnclosingType

      public static Type getEnclosingType(Type inner, Member member)
      Returns the innermost of the enclosing types of inner of which member is a member. May be inner itself. Returns null if no such type can be found.
      Parameters:
      inner - a type
      member - a member
      Returns:
      innermost enclosing type of inner which has member as member
    • getDeclaredType

      public static Type getDeclaredType(Type type, String nameOrDescriptor)
    • overlaps

      public static boolean overlaps(FieldChain a, int[] aindices, FieldChain b, int[] bindices)
    • getDeclaredField

      public static Field getDeclaredField(Type type, String nameOrDescriptor)
    • getDeclaredMethod

      public static Method getDeclaredMethod(Type type, String nameOrDescriptor)
    • getDeclaredMethod

      public static Method getDeclaredMethod(Type type, String nameOrDescriptor, Boolean requiresPublic)
    • getElementMethod

      public static Method getElementMethod(Type type, String element)
    • getMostSpecificPublicConstructor

      public static Method getMostSpecificPublicConstructor(Type type, Object value)
    • getDefaultConstructor

      public static Method getDefaultConstructor(Type type)
    • findMethodInClasses

      public static Method findMethodInClasses(Type type, String name)
    • findMethodWithPrefixInTypes

      public static Method findMethodWithPrefixInTypes(Type type, String descriptorPrefix, boolean includeInterfaces, boolean publicOnly)
    • findFieldInClasses

      public static Field findFieldInClasses(Type type, String nameOrDescriptor)
    • getDeclaredAnnotation

      public static <T extends Annotation> Annotation<T> getDeclaredAnnotation(Member member, Class<T> cls)
    • findFirst

      public static Type findFirst(Type[] types, Type type)
    • getType

      public static Type getType(int typeId)
    • getType

      public static final Type getType(Object object)
    • getTypeName

      public static String getTypeName(int typeId)
    • getTypeSuffix

      public static String getTypeSuffix(int typeId)
    • isSuperclassOrSame

      public static boolean isSuperclassOrSame(Type sup, Type type)
    • isSuperclassOrSame

      public static boolean isSuperclassOrSame(Class sup, Type type)
    • isSupertypeOrSame

      public static boolean isSupertypeOrSame(Type sup, Type type)
    • isSupertypeOrSame

      public static boolean isSupertypeOrSame(Class sup, Type type)
    • isSuperclassOrSame

      public static boolean isSuperclassOrSame(String sup, Type type)
    • isSupertypeOrSame

      public static boolean isSupertypeOrSame(String sup, Type type)
    • isSupertype

      public static boolean isSupertype(Type sup, Type type)
    • isAssignableFrom

      public static boolean isAssignableFrom(Type target, Type source)
    • incompatibleReturnTypesExist

      public static boolean incompatibleReturnTypesExist(Type t1, Type t2)
    • getBinaryType

      public static Type<?> getBinaryType(Type<?> type)
    • isCastableFrom

      public static boolean isCastableFrom(Type target, Type source)
    • equal

      public static boolean equal(Type t1, Type t2)
    • equal

      public static boolean equal(Class t1, Type t2)
    • toString

      public static String toString(Type t)
    • isWideningConversion

      public static boolean isWideningConversion(int src, int dest)
    • isWideningConversion

      public static boolean isWideningConversion(Type src, Type dest)
    • toType

      public static Object toType(Object v, Type t)
    • getPublicType

      public static Type getPublicType(Type[] types)
    • getType

      public static Type getType(String type, ClassLoader loader)
    • getType

      public static Type getType(Class cls)
    • isIntegral

      public static boolean isIntegral(Type type)
    • isPrimitive

      public static boolean isPrimitive(Type type)
    • isInterface

      public static boolean isInterface(Type type)
    • isArray

      public static boolean isArray(Type type)
    • isCtor

      public static boolean isCtor(Method m)
      Returns true if the method m is a constructor, otherwise returns false.
      Parameters:
      m - a method
      Returns:
      true iff m is a constructor
    • isPrimitiveOrVoid

      public static boolean isPrimitiveOrVoid(Type type)
    • isPrimitiveOrString

      public static boolean isPrimitiveOrString(Type type)
    • hasCategory2

      public static boolean hasCategory2(int typeId)
    • getWrapperClass

      public static Class getWrapperClass(int typeId)
    • getUnwrappedType

      public static Type getUnwrappedType(Type type)
      If the input type is one of the wrapper classes (Boolean, Byte, Short, Integer, Long, Float, Double, Character), return the matching unwrapped type (boolean, byte, short, int, long, float, double, char), otherwise return Type.INVALID instead.
      Parameters:
      type -
      Returns:
      unwrapped type
    • isAccessible

      public static boolean isAccessible(Member m, Type instance, Type scope)
      Determines if member m is accessible on instance in the context scope. instance is only needed for instance methods and fields and denotes the instance on which these members are accessed. scope defines the type in whose declaration the access of m occurs.
      NOTE: This method does not check if the declaring type of m is accessible.
      Parameters:
      m - a member
      instance - instance for instance methods and fields
      scope - type in whose declaration m is accessed
      Returns:
      true iff the access is permitted
    • canLoad

      public static boolean canLoad(ClassLoader loader, Class cls)
    • isAncestorOrSame

      public static boolean isAncestorOrSame(ClassLoader a, ClassLoader b)
    • isInvalid

      public static boolean isInvalid(Type type)