Class ClassInfo

java.lang.Object
org.apache.juneau.reflect.ClassInfo

public final class ClassInfo extends Object
Lightweight utility class for introspecting information about a class.

Provides various convenience methods for introspecting fields/methods/annotations that aren't provided by the standard Java reflection APIs.

Objects are designed to be lightweight to create and threadsafe.

Example:

// Wrap our class inside a ClassInfo. ClassInfo classInfo = ClassInfo.of(MyClass.class); // Get all methods in parent-to-child order, sorted alphabetically per class. for (MethodInfo methodInfo : classInfo.getAllMethods()) { // Do something with it. } // Get all class-level annotations in parent-to-child order. for (MyAnnotation annotation : classInfo.getAnnotations(MyAnnotation.class)) { // Do something with it. }

See Also:
  • Field Details

    • OBJECT

      public static final ClassInfo OBJECT
      Reusable ClassInfo for Object class.
  • Constructor Details

    • ClassInfo

      protected ClassInfo(Class<?> c, Type t)
      Constructor.
      Parameters:
      c - The class type.
      t - The generic type (if parameterized type).
  • Method Details

    • of

      public static ClassInfo of(Type t)
      Returns a class info wrapper around the specified class type.
      Parameters:
      t - The class type.
      Returns:
      The constructed class info, or null if the type was null.
    • of

      public static ClassInfo of(Class<?> c)
      Returns a class info wrapper around the specified class type.
      Parameters:
      c - The class type.
      Returns:
      The constructed class info, or null if the type was null.
    • of

      public static ClassInfo of(Class<?> c, Type t)
      Returns a class info wrapper around the specified class type.
      Parameters:
      c - The class type.
      t - The generic type (if parameterized type).
      Returns:
      The constructed class info, or null if the type was null.
    • of

      public static ClassInfo of(Object o)
      Same as using the constructor, but operates on an object instance.
      Parameters:
      o - The class instance.
      Returns:
      The constructed class info, or null if the object was null.
    • ofProxy

      public static ClassInfo ofProxy(Object o)
      Same as of(Object) but attempts to deproxify the object if it's wrapped in a CGLIB proxy.
      Parameters:
      o - The class instance.
      Returns:
      The constructed class info, or null if the object was null.
    • innerType

      public Type innerType()
      Returns the wrapped class as a Type.
      Returns:
      The wrapped class as a Type.
    • inner

      public <T> Class<T> inner()
      Returns the wrapped class as a Class.
      Type Parameters:
      T - The inner class type.
      Returns:
      The wrapped class as a Class, or null if it's not a class (e.g. it's a ParameterizedType).
    • unwrap

      public ClassInfo unwrap(Class<?>... wrapperTypes)
      Unwrap this class if it's a parameterized type of the specified type such as Value or Optional.
      Parameters:
      wrapperTypes - The parameterized types to unwrap if this class is one of those types.
      Returns:
      The class info on the unwrapped type, or just this type if this isn't one of the specified types.
    • getSuperclass

      Returns the parent class.
      Returns:
      The parent class, or null if the class has no parent.
    • getDeclaredInterfaces

      Returns a list of interfaces declared on this class.

      Does not include interfaces declared on parent classes.

      Results are in the same order as Class.getInterfaces().

      Returns:
      An unmodifiable list of interfaces declared on this class.
      Results are in the same order as Class.getInterfaces().
    • getInterfaces

      Returns a list of interfaces defined on this class and superclasses.

      Results are in child-to-parent order.

      Returns:
      An unmodifiable list of interfaces defined on this class and superclasses.
      Results are in child-to-parent order.
    • getParents

      Returns a list including this class and all parent classes.

      Does not include interfaces.

      Results are in child-to-parent order.

      Returns:
      An unmodifiable list including this class and all parent classes.
      Results are in child-to-parent order.
    • getAllParents

      Returns a list including this class and all parent classes and interfaces.

      Results are classes-before-interfaces, then child-to-parent order.

      Returns:
      An unmodifiable list including this class and all parent classes.
      Results are ordered child-to-parent order with classes listed before interfaces.
    • getAnyParent

      Returns the first matching parent class or interface.

      Results are classes-before-interfaces, then child-to-parent order.

      Parameters:
      filter - A predicate to apply to the entries to determine if value should be used. Can be null.
      Returns:
      The parent class or interface that matches the specified predicate.
    • getPublicMethods

      Returns all public methods on this class.

      Methods defined on the Object class are excluded from the results.

      Returns:
      All public methods on this class.
      Results are ordered alphabetically.
    • forEachPublicMethod

      Performs an action on all matching public methods on this class.
      Parameters:
      filter - A predicate to apply to the entries to determine if action should be performed. Can be null.
      action - An action to perform on the entry.
      Returns:
      This object.
    • getPublicMethod

      Returns the first matching public method on this class.
      Parameters:
      filter - A predicate to apply to the entries to determine if value should be used. Can be null.
      Returns:
      The first matching method, or null if no methods matched.
    • getDeclaredMethods

      Returns all methods declared on this class.
      Returns:
      All methods declared on this class.
      Results are ordered alphabetically.
      List is unmodifiable.
    • forEachDeclaredMethod

      Performs an action on all matching declared methods on this class.
      Parameters:
      filter - A predicate to apply to the entries to determine if action should be performed. Can be null.
      action - An action to perform on the entry.
      Returns:
      This object.
    • getDeclaredMethod

      Returns the first matching declared method on this class.
      Parameters:
      filter - A predicate to apply to the entries to determine if value should be used. Can be null.
      Returns:
      The first matching method, or null if no methods matched.
    • getMethods

      Returns all declared methods on this class and all parent classes.
      Returns:
      All declared methods on this class and all parent classes.
      Results are ordered child-to-parent, and then alphabetically per class.
      List is unmodifiable.
    • forEachMethod

      public final ClassInfo forEachMethod(Predicate<MethodInfo> filter, Consumer<MethodInfo> action)
      Performs an action on all matching methods on this class.
      Parameters:
      filter - A predicate to apply to the entries to determine if action should be performed. Can be null.
      action - An action to perform on the entry.
      Returns:
      This object.
    • getMethod

      Returns the first matching method on this class.
      Parameters:
      filter - A predicate to apply to the entries to determine if value should be used. Can be null.
      Returns:
      The first matching method, or null if no methods matched.
    • getAllMethodsParentFirst

      Returns all declared methods on this class and all parent classes.
      Returns:
      All declared methods on this class and all parent classes.
      Results are ordered parent-to-child, and then alphabetically per class.
      List is unmodifiable.
    • forEachAllMethodParentFirst

      Performs an action on all matching declared methods on this class and all parent classes.
      Parameters:
      filter - A predicate to apply to the entries to determine if action should be performed. Can be null.
      action - An action to perform on the entry.
      Returns:
      This object.
    • getPublicConstructors

      Returns all the public constructors defined on this class.
      Returns:
      All public constructors defined on this class.
    • forEachPublicConstructor

      Performs an action on all matching public constructors on this class.
      Parameters:
      filter - A predicate to apply to the entries to determine if action should be performed. Can be null.
      action - An action to perform on the entry.
      Returns:
      This object.
    • getPublicConstructor

      Returns the first matching public constructor on this class.
      Parameters:
      filter - A predicate to apply to the entries to determine if value should be used. Can be null.
      Returns:
      The public constructor that matches the specified predicate.
    • getDeclaredConstructors

      Returns all the constructors defined on this class.
      Returns:
      All constructors defined on this class.
      List is unmodifiable.
    • forEachDeclaredConstructor

      Performs an action on all matching declared constructors on this class.
      Parameters:
      filter - A predicate to apply to the entries to determine if action should be performed. Can be null.
      action - An action to perform on the entry.
      Returns:
      This object.
    • getDeclaredConstructor

      Returns the first matching declared constructor on this class.
      Parameters:
      filter - A predicate to apply to the entries to determine if value should be used. Can be null.
      Returns:
      The declared constructor that matches the specified predicate.
    • getNoArgConstructor

      Locates the no-arg constructor for this class.

      Constructor must match the visibility requirements specified by parameter 'v'. If class is abstract, always returns null. Note that this also returns the 1-arg constructor for non-static member classes.

      Parameters:
      v - The minimum visibility.
      Returns:
      The constructor, or null if no no-arg constructor exists with the required visibility.
    • getPublicFields

      Returns all public fields on this class.

      Hidden fields are excluded from the results.

      Returns:
      All public fields on this class.
      Results are in alphabetical order.
      List is unmodifiable.
    • forEachPublicField

      Performs an action on all matching public fields on this class.
      Parameters:
      filter - A predicate to apply to the entries to determine if action should be performed. Can be null.
      action - An action to perform on the entry.
      Returns:
      This object.
    • getPublicField

      Returns the first matching public field on this class.
      Parameters:
      filter - A predicate to apply to the entries to determine if value should be used. Can be null.
      Returns:
      The public field, or null if not found.
    • getDeclaredFields

      Returns all declared fields on this class.
      Returns:
      All declared fields on this class.
      Results are in alphabetical order.
      List is unmodifiable.
    • forEachDeclaredField

      Performs an action on all matching declared fields on this class.
      Parameters:
      filter - A predicate to apply to the entries to determine if action should be performed. Can be null.
      action - An action to perform on the entry.
      Returns:
      This object.
    • getDeclaredField

      Returns the first matching declared field on this class.
      Parameters:
      filter - A predicate to apply to the entries to determine if value should be used. Can be null.
      Returns:
      The declared field, or null if not found.
    • getAllFields

      Returns all fields on this class and all parent classes.

      Results are ordered parent-to-child, and then alphabetical per class.

      Returns:
      All declared fields on this class.
      List is unmodifiable.
    • forEachAllField

      Performs an action on all matching fields on this class and all parent classes.

      Results are ordered parent-to-child, and then alphabetical per class.

      Parameters:
      filter - A predicate to apply to the entries to determine if action should be performed. Can be null.
      action - An action to perform on the entry.
      Returns:
      This object.
    • getAnnotations

      public <A extends Annotation> List<A> getAnnotations(Class<A> type)
      Returns all annotations of the specified type defined on the specified class or parent classes/interfaces in parent-to-child order.
      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      type - The annotation type to look for.
      Returns:
      The matching annotations.
    • getAnnotations

      public <A extends Annotation> List<A> getAnnotations(AnnotationProvider annotationProvider, Class<A> type)
      Returns all annotations of the specified type defined on this or parent classes/interfaces.

      Returns the list in reverse (parent-to-child) order.

      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      annotationProvider - The annotation provider.
      type - The annotation type to look for.
      Returns:
      The matching annotations.
    • forEachAnnotation

      public <A extends Annotation> ClassInfo forEachAnnotation(Class<A> type, Predicate<A> filter, Consumer<A> action)
      Performs an action on all matching annotations on this class and superclasses/interfaces.
      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      type - The annotation to look for.
      filter - A predicate to apply to the entries to determine if action should be performed. Can be null.
      action - An action to perform on the entry.
      Returns:
      This object.
    • forEachAnnotation

      public <A extends Annotation> ClassInfo forEachAnnotation(AnnotationProvider annotationProvider, Class<A> type, Predicate<A> filter, Consumer<A> action)
      Performs an action on all matching annotations on this class and superclasses/interfaces.

      Annotations are appended in the following orders:

      1. On the package of this class.
      2. On interfaces ordered parent-to-child.
      3. On parent classes ordered parent-to-child.
      4. On this class.
      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      annotationProvider - The annotation provider.
      type - The annotation to look for.
      filter - A predicate to apply to the entries to determine if action should be performed. Can be null.
      action - An action to perform on the entry.
      Returns:
      This object.
    • firstAnnotation

      public <A extends Annotation> A firstAnnotation(Class<A> type, Predicate<A> filter)
      Returns the first matching annotation on this class and superclasses/interfaces.

      Annotations are searched in the following orders:

      1. On the package of this class.
      2. On interfaces ordered parent-to-child.
      3. On parent classes ordered parent-to-child.
      4. On this class.
      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      type - The annotation to look for.
      filter - A predicate to apply to the entries to determine if annotation should be returned. Can be null.
      Returns:
      This object.
    • firstAnnotation

      public <A extends Annotation> A firstAnnotation(AnnotationProvider annotationProvider, Class<A> type, Predicate<A> filter)
      Returns the first matching annotation on this class and superclasses/interfaces.

      Annotations are searched in the following orders:

      1. On the package of this class.
      2. On interfaces ordered parent-to-child.
      3. On parent classes ordered parent-to-child.
      4. On this class.
      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      annotationProvider - The annotation provider.
      type - The annotation to look for.
      filter - A predicate to apply to the entries to determine if annotation should be returned. Can be null.
      Returns:
      This object.
    • lastAnnotation

      public <A extends Annotation> A lastAnnotation(Class<A> type, Predicate<A> filter)
      Returns the last matching annotation on this class and superclasses/interfaces.

      Annotations are searched in the following orders:

      1. On this class.
      2. On parent classes ordered child-to-parent.
      3. On interfaces ordered child-to-parent.
      4. On the package of this class.
      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      type - The annotation to look for.
      filter - A predicate to apply to the entries to determine if annotation should be returned. Can be null.
      Returns:
      This object.
    • lastAnnotation

      public <A extends Annotation> A lastAnnotation(AnnotationProvider annotationProvider, Class<A> type, Predicate<A> filter)
      Returns the last matching annotation on this class and superclasses/interfaces.

      Annotations are searched in the following orders:

      1. On this class.
      2. On parent classes ordered child-to-parent.
      3. On interfaces ordered child-to-parent.
      4. On the package of this class.
      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      annotationProvider - The annotation provider.
      type - The annotation to look for.
      filter - A predicate to apply to the entries to determine if annotation should be returned. Can be null.
      Returns:
      This object.
    • getAnnotation

      public <A extends Annotation> A getAnnotation(Class<A> type)
      Finds the annotation of the specified type defined on this class or parent class/interface.

      If the annotation cannot be found on the immediate class, searches methods with the same signature on the parent classes or interfaces.
      The search is performed in child-to-parent order.

      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      type - The annotation to look for.
      Returns:
      The annotation if found, or null if not.
    • getAnnotation

      public <A extends Annotation> A getAnnotation(AnnotationProvider annotationProvider, Class<A> type)
      Finds the annotation of the specified type defined on this class or parent class/interface.

      If the annotation cannot be found on the immediate class, searches methods with the same signature on the parent classes or interfaces.
      The search is performed in child-to-parent order.

      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      annotationProvider - The annotation provider.
      type - The annotation to look for.
      Returns:
      The annotation if found, or null if not.
    • hasAnnotation

      public <A extends Annotation> boolean hasAnnotation(Class<A> type)
      Returns true if this class has the specified annotation.
      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      type - The annotation to look for.
      Returns:
      The true if annotation if found.
    • hasNoAnnotation

      public <A extends Annotation> boolean hasNoAnnotation(Class<A> type)
      Returns true if this class doesn't have the specified annotation.
      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      type - The annotation to look for.
      Returns:
      The true if annotation if not found.
    • hasAnnotation

      public <A extends Annotation> boolean hasAnnotation(AnnotationProvider annotationProvider, Class<A> type)
      Returns true if this class has the specified annotation.
      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      annotationProvider - The annotation provider.
      type - The annotation to look for.
      Returns:
      The true if annotation if found.
    • getPackageAnnotation

      public <A extends Annotation> A getPackageAnnotation(Class<A> type)
      Returns the specified annotation only if it's been declared on the package of this class.
      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      type - The annotation class.
      Returns:
      The annotation, or null if not found.
    • getAnnotation

      public <A extends Annotation> A getAnnotation(Class<A> type, Predicate<A> filter)
      Returns the first matching annotation of the specified type defined on the specified class or parent classes/interfaces in parent-to-child order.
      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      type - The annotation to look for.
      filter - A predicate to apply to the entries to determine if value should be used. Can be null.
      Returns:
      This object.
    • getAnnotationList

      Constructs an AnnotationList of all annotations found on this class.

      Annotations are appended in the following orders:

      1. On the package of this class.
      2. On interfaces ordered parent-to-child.
      3. On parent classes ordered parent-to-child.
      4. On this class.
      Returns:
      A new AnnotationList object on every call.
    • getAnnotationList

      Constructs an AnnotationList of all matching annotations on this class.

      Annotations are appended in the following orders:

      1. On the package of this class.
      2. On interfaces ordered parent-to-child.
      3. On parent classes ordered parent-to-child.
      4. On this class.
      Parameters:
      filter - A predicate to apply to the entries to determine if value should be used. Can be null.
      Returns:
      A new AnnotationList object on every call.
    • forEachAnnotationInfo

      Performs an action on all matching annotations on this class/parents/package.

      Annotations are consumed in the following order:

      1. On the package of this class.
      2. On interfaces ordered parent-to-child.
      3. On parent classes ordered parent-to-child.
      4. On this class.
      Parameters:
      filter - A predicate to apply to the entries to determine if action should be performed. Can be null.
      action - An action to perform on the entry.
      Returns:
      This object.
    • isAll

      public boolean isAll(ReflectFlags... flags)
      Returns true if all specified flags are applicable to this class.
      Parameters:
      flags - The flags to test for.
      Returns:
      true if all specified flags are applicable to this class.
    • isAny

      public boolean isAny(ReflectFlags... flags)
      Returns true if all specified flags are applicable to this class.
      Parameters:
      flags - The flags to test for.
      Returns:
      true if all specified flags are applicable to this class.
    • isDeprecated

      public boolean isDeprecated()
      Returns true if this class has the @Deprecated annotation on it.
      Returns:
      true if this class has the @Deprecated annotation on it.
    • isNotDeprecated

      public boolean isNotDeprecated()
      Returns true if this class doesn't have the @Deprecated annotation on it.
      Returns:
      true if this class doesn't have the @Deprecated annotation on it.
    • isPublic

      public boolean isPublic()
      Returns true if this class is public.
      Returns:
      true if this class is public.
    • isNotPublic

      public boolean isNotPublic()
      Returns true if this class is not public.
      Returns:
      true if this class is not public.
    • isStatic

      public boolean isStatic()
      Returns true if this class is public.

      Note that interfaces are always reported as static, and the static keyword on a member interface is meaningless.

      Returns:
      true if this class is public.
    • isNotStatic

      public boolean isNotStatic()
      Returns true if this class is not static.

      Note that interfaces are always reported as static, and the static keyword on a member interface is meaningless.

      Returns:
      true if this class is not static.
    • isAbstract

      public boolean isAbstract()
      Returns true if this class is abstract.

      Note that interfaces are always reported as abstract.

      Returns:
      true if this class is abstract.
    • isNotAbstract

      public boolean isNotAbstract()
      Returns true if this class is not abstract.

      Note that interfaces are always reported as abstract.

      Returns:
      true if this class is not abstract.
    • isMemberClass

      public boolean isMemberClass()
      Returns true if this class is a member class.
      Returns:
      true if this class is a member class.
    • isNotMemberClass

      public boolean isNotMemberClass()
      Returns true if this class is a member class.
      Returns:
      true if this class is a member class.
    • isNonStaticMemberClass

      public boolean isNonStaticMemberClass()
      Returns true if this class is a member class and not static.
      Returns:
      true if this class is a member class and not static.
    • isNotNonStaticMemberClass

      public boolean isNotNonStaticMemberClass()
      Returns false if this class is a member class and not static.
      Returns:
      false if this class is a member class and not static.
    • isLocalClass

      public boolean isLocalClass()
      Returns true if this class is a local class.
      Returns:
      true if this class is a local class.
    • isNotLocalClass

      public boolean isNotLocalClass()
      Returns true if this class is a local class.
      Returns:
      true if this class is a local class.
    • isVisible

      public boolean isVisible(Visibility v)
      Identifies if the specified visibility matches this constructor.
      Parameters:
      v - The visibility to validate against.
      Returns:
      true if this visibility matches the modifier attribute of this constructor.
    • isPrimitive

      public boolean isPrimitive()
      Returns true if this is a primitive class.
      Returns:
      true if this is a primitive class.
    • isNotPrimitive

      public boolean isNotPrimitive()
      Returns true if this is not a primitive class.
      Returns:
      true if this is not a primitive class.
    • isInterface

      public boolean isInterface()
      Returns true if this class is an interface.
      Returns:
      true if this class is an interface.
    • isClass

      public boolean isClass()
      Returns true if this class is not an interface.
      Returns:
      true if this class is not an interface.
    • isRuntimeException

      public boolean isRuntimeException()
      Returns true if this class is a RuntimeException.
      Returns:
      true if this class is a RuntimeException.
    • hasPrimitiveWrapper

      public boolean hasPrimitiveWrapper()
      Returns true if the getPrimitiveWrapper() method returns a value.
      Returns:
      true if the getPrimitiveWrapper() method returns a value.
    • getPrimitiveWrapper

      If this class is a primitive (e.g. int.class) returns it's wrapper class (e.g. Integer.class).
      Returns:
      The wrapper class, or null if class is not a primitive.
    • getPrimitiveForWrapper

      If this class is a primitive wrapper (e.g. Integer.class) returns it's primitive class (e.g. int.class).
      Returns:
      The primitive class, or null if class is not a primitive wrapper.
    • getWrapperIfPrimitive

      If this class is a primitive (e.g. int.class) returns it's wrapper class (e.g. Integer.class).
      Returns:
      The wrapper class if it's primitive, or the same class if class is not a primitive.
    • getWrapperInfoIfPrimitive

      Same as getWrapperIfPrimitive() but wraps it in a ClassInfo.
      Returns:
      The wrapper class if it's primitive, or the same class if class is not a primitive.
    • getPrimitiveDefault

      Returns the default value for this primitive class.
      Returns:
      The default value, or null if this is not a primitive class.
    • getFullName

      public String getFullName()
      Returns the full name of this class.
      Examples:
      • "com.foo.MyClass" - Normal class
      • "com.foo.MyClass[][]" - Array.
      • "com.foo.MyClass$InnerClass" - Inner class.
      • "com.foo.MyClass$InnerClass[][]" - Inner class array.
      • "int" - Primitive class.
      • "int[][]" - Primitive class class.
      • "java.util.Map<java.lang.String,java.lang.Object>" - Parameterized type.
      • "java.util.AbstractMap<K,V>" - Parameterized generic type.
      • "V" - Parameterized generic type argument.
      Returns:
      The underlying class name.
    • getNames

      public String[] getNames()
      Returns all possible names for this class.
      Returns:
      An array consisting of:
    • appendFullName

      Same as getFullName() but appends to an existing string builder.
      Parameters:
      sb - The string builder to append to.
      Returns:
      The same string builder.
    • getShortName

      public String getShortName()
      Returns the short name of the underlying class.

      Similar to getSimpleName() but also renders local or member class name prefixes.

      Returns:
      The short name of the underlying class.
    • appendShortName

      Same as getShortName() but appends to an existing string builder.
      Parameters:
      sb - The string builder to append to.
      Returns:
      The same string builder.
    • getSimpleName

      Returns the simple name of the underlying class.

      Returns either Class.getSimpleName() or Type.getTypeName() depending on whether this is a class or type.

      Returns:
      The simple name of the underlying class;
    • getName

      public String getName()
      Returns the name of the underlying class.
      Returns:
      The name of the underlying class.
    • getReadableName

      Same as getSimpleName() but uses "Array" instead of "[]".
      Returns:
      The readable name for this class.
    • isParentOf

      public boolean isParentOf(Class<?> child)
      Returns true if this class is a parent or the same as child.
      Parameters:
      child - The child class.
      Returns:
      true if this class is a parent or the same as child.
    • isParentOfFuzzyPrimitives

      public boolean isParentOfFuzzyPrimitives(Class<?> child)
      Returns true if this class is a parent or the same as child.

      Primitive classes are converted to wrapper classes and compared.

      Examples:

      ClassInfo.of(String.class).isParentOfFuzzyPrimitives(String.class); // true ClassInfo.of(CharSequence.class).isParentOfFuzzyPrimitives(String.class); // true ClassInfo.of(String.class).isParentOfFuzzyPrimitives(CharSequence.class); // false ClassInfo.of(int.class).isParentOfFuzzyPrimitives(Integer.class); // true ClassInfo.of(Integer.class).isParentOfFuzzyPrimitives(int.class); // true ClassInfo.of(Number.class).isParentOfFuzzyPrimitives(int.class); // true ClassInfo.of(int.class).isParentOfFuzzyPrimitives(Number.class); // false ClassInfo.of(int.class).isParentOfFuzzyPrimitives(long.class); // false

      Parameters:
      child - The child class.
      Returns:
      true if this class is a parent or the same as child.
    • canAcceptArg

      public boolean canAcceptArg(Object child)
      Returns true if this type can be used as a parameter for the specified object.
      Parameters:
      child - The argument to check.
      Returns:
      true if this type can be used as a parameter for the specified object.
    • isParentOfFuzzyPrimitives

      public boolean isParentOfFuzzyPrimitives(ClassInfo child)
      Parameters:
      child - The child class.
      Returns:
      true if this class is a parent or the same as child.
    • isParentOf

      public boolean isParentOf(Type child)
      Returns true if this class is a parent or the same as child.
      Parameters:
      child - The child class.
      Returns:
      true if this class is a parent or the same as child.
    • isParentOfFuzzyPrimitives

      public boolean isParentOfFuzzyPrimitives(Type child)
      Returns true if this class is a parent or the same as child.
      Parameters:
      child - The child class.
      Returns:
      true if this class is a parent or the same as child.
    • isStrictChildOf

      public boolean isStrictChildOf(Class<?> parent)
      Returns true if this class is a child of parent.
      Parameters:
      parent - The parent class.
      Returns:
      true if this class is a parent of child.
    • isChildOf

      public boolean isChildOf(Class<?> parent)
      Returns true if this class is a child or the same as parent.
      Parameters:
      parent - The parent class.
      Returns:
      true if this class is a child or the same as parent.
    • isChildOfAny

      public boolean isChildOfAny(Class<?>... parents)
      Returns true if this class is a child or the same as any of the parents.
      Parameters:
      parents - The parents class.
      Returns:
      true if this class is a child or the same as any of the parents.
    • isChildOf

      public boolean isChildOf(Type parent)
      Returns true if this class is a child or the same as parent.
      Parameters:
      parent - The parent class.
      Returns:
      true if this class is a parent or the same as parent.
    • isChildOf

      public boolean isChildOf(ClassInfo parent)
      Returns true if this class is a child or the same as parent.
      Parameters:
      parent - The parent class.
      Returns:
      true if this class is a parent or the same as parent.
    • is

      public boolean is(Class<?> c)
      Checks for equality with the specified class.
      Parameters:
      c - The class to check equality with.
      Returns:
      true if the specified class is the same as this one.
    • is

      public boolean is(ClassInfo c)
      Checks for equality with the specified class.
      Parameters:
      c - The class to check equality with.
      Returns:
      true if the specified class is the same as this one.
    • isInstance

      public boolean isInstance(Object value)
      Returns true if the specified value is an instance of this class.
      Parameters:
      value - The value to check.
      Returns:
      true if the specified value is an instance of this class.
    • isAny

      public boolean isAny(Class<?>... types)
      Returns true if this class is any of the specified types.
      Parameters:
      types - The types to check against.
      Returns:
      true if this class is any of the specified types.
    • is

      public boolean is(ReflectFlags... flags)
      Returns true if all specified flags are applicable to this field.
      Parameters:
      flags - The flags to test for.
      Returns:
      true if all specified flags are applicable to this field.
    • getPackage

      public Package getPackage()
      Returns the package of this class.
      Returns:
      The package of this class.
    • hasPackage

      public boolean hasPackage()
      Returns true if this class is not in the root package.
      Returns:
      true if this class is not in the root package.
    • getDimensions

      public int getDimensions()
      Returns the number of dimensions if this is an array type.
      Returns:
      The number of dimensions if this is an array type, or 0 if it is not.
    • getComponentType

      Returns the base component type of this class if it's an array.
      Returns:
      The base component type of this class if it's an array, or this object if it's not.
    • isEnum

      public boolean isEnum()
      Returns true if this class is an enum.
      Returns:
      true if this class is an enum.
    • isRepeatedAnnotation

      public boolean isRepeatedAnnotation()
      Returns true if this is a repeated annotation class.

      A repeated annotation has a single value() method that returns an array of annotations who themselves are marked with the @Repeatable annotation of this class.

      Returns:
      true if this is a repeated annotation class.
    • getRepeatedAnnotationMethod

      Returns the repeated annotation method on this class.

      The repeated annotation method is the value() method that returns an array of annotations who themselves are marked with the @Repeatable annotation of this class.

      Returns:
      The repeated annotation method on this class, or null if it doesn't exist.
    • isArray

      public boolean isArray()
      Returns true if this class is an array.
      Returns:
      true if this class is an array.
    • isAnnotation

      public boolean isAnnotation()
      Returns true if this class is an annotation.
      Returns:
      true if this class is an annotation.
    • isCollectionOrArray

      public boolean isCollectionOrArray()
      Returns true if this class is a Collection or an array.
      Returns:
      true if this class is a Collection or an array.
    • newInstance

      Shortcut for calling Class.getDeclaredConstructor().newInstance() on the underlying class.
      Returns:
      A new instance of the underlying class
      Throws:
      ExecutableException - Exception occurred on invoked constructor/method/field.
    • getParameterType

      public Class<?> getParameterType(int index, Class<?> pt)
      Finds the real parameter type of this class.
      Parameters:
      index - The zero-based index of the parameter to resolve.
      pt - The parameterized type class containing the parameterized type to resolve (e.g. HashMap).
      Returns:
      The resolved real class.
    • matches

      public boolean matches(Predicate<ClassInfo> test)
      Returns true if this object passes the specified predicate test.
      Parameters:
      test - The test to perform.
      Returns:
      true if this object passes the specified predicate test.
    • accept

      Performs an action on this object if the specified predicate test passes.
      Parameters:
      test - A test to apply to determine if action should be executed. Can be null.
      action - An action to perform on this object.
      Returns:
      This object.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object