Class ClassInfo
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:
See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionPerforms an action on this object if the specified predicate test passes.Same asgetFullName()
but appends to an existing string builder.Same asgetShortName()
but appends to an existing string builder.boolean
canAcceptArg
(Object child) Returnstrue if this type can be used as a parameter for the specified object.boolean
<A extends Annotation>
AfirstAnnotation
(Class<A> type, Predicate<A> filter) Returns the first matching annotation on this class and superclasses/interfaces.<A extends Annotation>
AfirstAnnotation
(AnnotationProvider annotationProvider, Class<A> type, Predicate<A> filter) Returns the first matching annotation on this class and superclasses/interfaces.forEachAllField
(Predicate<FieldInfo> filter, Consumer<FieldInfo> action) Performs an action on all matching fields on this class and all parent classes.forEachAllMethodParentFirst
(Predicate<MethodInfo> filter, Consumer<MethodInfo> action) Performs an action on all matching declared methods on this class and all parent classes.<A extends Annotation>
ClassInfoforEachAnnotation
(Class<A> type, Predicate<A> filter, Consumer<A> action) Performs an action on all matching annotations on this class and superclasses/interfaces.<A extends Annotation>
ClassInfoforEachAnnotation
(AnnotationProvider annotationProvider, Class<A> type, Predicate<A> filter, Consumer<A> action) Performs an action on all matching annotations on this class and superclasses/interfaces.forEachAnnotationInfo
(Predicate<AnnotationInfo<?>> filter, Consumer<AnnotationInfo<?>> action) Performs an action on all matching annotations on this class/parents/package.forEachDeclaredConstructor
(Predicate<ConstructorInfo> filter, Consumer<ConstructorInfo> action) Performs an action on all matching declared constructors on this class.forEachDeclaredField
(Predicate<FieldInfo> filter, Consumer<FieldInfo> action) Performs an action on all matching declared fields on this class.forEachDeclaredMethod
(Predicate<MethodInfo> filter, Consumer<MethodInfo> action) Performs an action on all matching declared methods on this class.forEachMethod
(Predicate<MethodInfo> filter, Consumer<MethodInfo> action) Performs an action on all matching methods on this class.forEachPublicConstructor
(Predicate<ConstructorInfo> filter, Consumer<ConstructorInfo> action) Performs an action on all matching public constructors on this class.forEachPublicField
(Predicate<FieldInfo> filter, Consumer<FieldInfo> action) Performs an action on all matching public fields on this class.forEachPublicMethod
(Predicate<MethodInfo> filter, Consumer<MethodInfo> action) Performs an action on all matching public methods on this class.Returns all fields on this class and all parent classes.Returns all declared methods on this class and all parent classes.Returns a list including this class and all parent classes and interfaces.<A extends Annotation>
AgetAnnotation
(Class<A> type) Finds the annotation of the specified type defined on this class or parent class/interface.<A extends Annotation>
AgetAnnotation
(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.<A extends Annotation>
AgetAnnotation
(AnnotationProvider annotationProvider, Class<A> type) Finds the annotation of the specified type defined on this class or parent class/interface.Constructs anAnnotationList
of all annotations found on this class.getAnnotationList
(Predicate<AnnotationInfo<?>> filter) Constructs anAnnotationList
of all matching annotations on this class.<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.<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.getAnyParent
(Predicate<ClassInfo> filter) Returns the first matching parent class or interface.Returns the base component type of this class if it's an array.Returns the first matching declared constructor on this class.Returns all the constructors defined on this class.getDeclaredField
(Predicate<FieldInfo> filter) Returns the first matching declared field on this class.Returns all declared fields on this class.Returns a list of interfaces declared on this class.getDeclaredMethod
(Predicate<MethodInfo> filter) Returns the first matching declared method on this class.Returns all methods declared on this class.int
Returns the number of dimensions if this is an array type.Returns the full name of this class.Returns a list of interfaces defined on this class and superclasses.getMethod
(Predicate<MethodInfo> filter) Returns the first matching method on this class.Returns all declared methods on this class and all parent classes.getName()
Returns the name of the underlying class.String[]
getNames()
Returns all possible names for this class.Locates the no-arg constructor for this class.Returns the package of this class.<A extends Annotation>
AgetPackageAnnotation
(Class<A> type) Returns the specified annotation only if it's been declared on the package of this class.Class<?>
getParameterType
(int index, Class<?> pt) Finds the real parameter type of this class.Returns a list including this class and all parent classes.Returns the default value for this primitive class.Class<?>
If this class is a primitive wrapper (e.g.Class<?>
If this class is a primitive (e.g.getPublicConstructor
(Predicate<ConstructorInfo> filter) Returns the first matching public constructor on this class.Returns all the public constructors defined on this class.getPublicField
(Predicate<FieldInfo> filter) Returns the first matching public field on this class.Returns all public fields on this class.getPublicMethod
(Predicate<MethodInfo> filter) Returns the first matching public method on this class.Returns all public methods on this class.Returns the repeated annotation method on this class.Returns the short name of the underlying class.Returns the simple name of the underlying class.Returns the parent class.Class<?>
If this class is a primitive (e.g.Same asgetWrapperIfPrimitive()
but wraps it in aClassInfo
.<A extends Annotation>
booleanhasAnnotation
(Class<A> type) Returnstrue if this class has the specified annotation.<A extends Annotation>
booleanhasAnnotation
(AnnotationProvider annotationProvider, Class<A> type) Returnstrue if this class has the specified annotation.int
hashCode()
<A extends Annotation>
booleanhasNoAnnotation
(Class<A> type) Returnstrue if this class doesn't have the specified annotation.boolean
Returnstrue if this class is not in the root package.boolean
Returnstrue if thegetPrimitiveWrapper()
method returns a value.<T> Class<T>
inner()
Returns the wrapped class as aClass
.Returns the wrapped class as aType
.boolean
Checks for equality with the specified class.boolean
Checks for equality with the specified class.boolean
is
(ReflectFlags... flags) Returnstrue if all specified flags are applicable to this field.boolean
Returnstrue if this class is abstract.boolean
isAll
(ReflectFlags... flags) Returnstrue if all specified flags are applicable to this class.boolean
Returnstrue if this class is an annotation.boolean
Returnstrue if this class is any of the specified types.boolean
isAny
(ReflectFlags... flags) Returnstrue if all specified flags are applicable to this class.boolean
isArray()
Returnstrue if this class is an array.boolean
Returnstrue if this class is a child or the same asparent .boolean
Returnstrue if this class is a child or the same asparent .boolean
Returnstrue if this class is a child or the same asparent .boolean
isChildOfAny
(Class<?>... parents) Returnstrue if this class is a child or the same as any of theparents .boolean
isClass()
Returnstrue if this class is not an interface.boolean
Returnstrue if this class is aCollection
or an array.boolean
Returnstrue if this class has the@Deprecated
annotation on it.boolean
isEnum()
Returnstrue if this class is an enum.boolean
isInstance
(Object value) Returnstrue if the specified value is an instance of this class.boolean
Returnstrue if this class is an interface.boolean
Returnstrue if this class is a local class.boolean
Returnstrue if this class is a member class.boolean
Returnstrue if this class is a member class and not static.boolean
Returnstrue if this class is not abstract.boolean
Returnstrue if this class doesn't have the@Deprecated
annotation on it.boolean
Returnstrue if this class is a local class.boolean
Returnstrue if this class is a member class.boolean
Returnsfalse if this class is a member class and not static.boolean
Returnstrue if this is not a primitive class.boolean
Returnstrue if this class is not public.boolean
Returnstrue if this class is not static.boolean
isParentOf
(Class<?> child) Returnstrue if this class is a parent or the same aschild .boolean
isParentOf
(Type child) Returnstrue if this class is a parent or the same aschild .boolean
isParentOfFuzzyPrimitives
(Class<?> child) Returnstrue if this class is a parent or the same aschild .boolean
isParentOfFuzzyPrimitives
(Type child) Returnstrue if this class is a parent or the same aschild .boolean
Same asisParentOfFuzzyPrimitives(Class)
but takes in aClassInfo
.boolean
Returnstrue if this is a primitive class.boolean
isPublic()
Returnstrue if this class is public.boolean
Returnstrue if this is a repeated annotation class.boolean
Returnstrue if this class is aRuntimeException
.boolean
isStatic()
Returnstrue if this class is public.boolean
isStrictChildOf
(Class<?> parent) Returnstrue if this class is a child ofparent .boolean
Identifies if the specified visibility matches this constructor.<A extends Annotation>
AlastAnnotation
(Class<A> type, Predicate<A> filter) Returns the last matching annotation on this class and superclasses/interfaces.<A extends Annotation>
AlastAnnotation
(AnnotationProvider annotationProvider, Class<A> type, Predicate<A> filter) Returns the last matching annotation on this class and superclasses/interfaces.boolean
Returnstrue if this object passes the specified predicate test.Shortcut for callingClass.getDeclaredConstructor().newInstance() on the underlying class.static ClassInfo
Returns a class info wrapper around the specified class type.static ClassInfo
Returns a class info wrapper around the specified class type.static ClassInfo
Same as using the constructor, but operates on an object instance.static ClassInfo
Returns a class info wrapper around the specified class type.static ClassInfo
Same asof(Object)
but attempts to deproxify the object if it's wrapped in a CGLIB proxy.toString()
-
Field Details
-
OBJECT
Reusable ClassInfo for Object class.
-
-
Constructor Details
-
ClassInfo
Constructor.- Parameters:
c
- The class type.t
- The generic type (if parameterized type).
-
-
Method Details
-
of
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 wasnull .
-
of
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 wasnull .
-
of
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 wasnull .
-
of
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 wasnull .
-
ofProxy
Same asof(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 wasnull .
-
innerType
Returns the wrapped class as aType
.- Returns:
- The wrapped class as a
Type
.
-
inner
Returns the wrapped class as aClass
.- Type Parameters:
T
- The inner class type.- Returns:
- The wrapped class as a
Class
, ornull if it's not a class (e.g. it's aParameterizedType
).
-
unwrap
- 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 asClass.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 benull .- 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 benull .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 benull .- 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 benull .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 benull .- 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
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 benull .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 benull .- 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
public ClassInfo forEachAllMethodParentFirst(Predicate<MethodInfo> filter, Consumer<MethodInfo> action) 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 benull .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
public ClassInfo forEachPublicConstructor(Predicate<ConstructorInfo> filter, Consumer<ConstructorInfo> action) 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 benull .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 benull .- 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
public ClassInfo forEachDeclaredConstructor(Predicate<ConstructorInfo> filter, Consumer<ConstructorInfo> action) 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 benull .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 benull .- 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 benull .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 benull .- 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 benull .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 benull .- 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 benull .action
- An action to perform on the entry.- Returns:
- This object.
-
getAnnotations
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 benull .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:
- On the package of this class.
- On interfaces ordered parent-to-child.
- On parent classes ordered parent-to-child.
- 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 benull .action
- An action to perform on the entry.- Returns:
- This object.
-
firstAnnotation
Returns the first matching annotation on this class and superclasses/interfaces.Annotations are searched in the following orders:
- On the package of this class.
- On interfaces ordered parent-to-child.
- On parent classes ordered parent-to-child.
- 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 benull .- 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:
- On the package of this class.
- On interfaces ordered parent-to-child.
- On parent classes ordered parent-to-child.
- 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 benull .- Returns:
- This object.
-
lastAnnotation
Returns the last matching annotation on this class and superclasses/interfaces.Annotations are searched in the following orders:
- On this class.
- On parent classes ordered child-to-parent.
- On interfaces ordered child-to-parent.
- 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 benull .- 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:
- On this class.
- On parent classes ordered child-to-parent.
- On interfaces ordered child-to-parent.
- 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 benull .- Returns:
- This object.
-
getAnnotation
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
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
Returnstrue 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
Returnstrue 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) Returnstrue 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
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
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 benull .- Returns:
- This object.
-
getAnnotationList
Constructs anAnnotationList
of all annotations found on this class.Annotations are appended in the following orders:
- On the package of this class.
- On interfaces ordered parent-to-child.
- On parent classes ordered parent-to-child.
- On this class.
- Returns:
- A new
AnnotationList
object on every call.
-
getAnnotationList
Constructs anAnnotationList
of all matching annotations on this class.Annotations are appended in the following orders:
- On the package of this class.
- On interfaces ordered parent-to-child.
- On parent classes ordered parent-to-child.
- On this class.
- Parameters:
filter
- A predicate to apply to the entries to determine if value should be used. Can benull .- Returns:
- A new
AnnotationList
object on every call.
-
forEachAnnotationInfo
public ClassInfo forEachAnnotationInfo(Predicate<AnnotationInfo<?>> filter, Consumer<AnnotationInfo<?>> action) Performs an action on all matching annotations on this class/parents/package.Annotations are consumed in the following order:
- On the package of this class.
- On interfaces ordered parent-to-child.
- On parent classes ordered parent-to-child.
- On this class.
- Parameters:
filter
- A predicate to apply to the entries to determine if action should be performed. Can benull .action
- An action to perform on the entry.- Returns:
- This object.
-
isAll
Returnstrue 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
Returnstrue 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
Returnstrue if this class has the@Deprecated
annotation on it.- Returns:
true if this class has the@Deprecated
annotation on it.
-
isNotDeprecated
Returnstrue 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
Returnstrue if this class is public.- Returns:
true if this class is public.
-
isNotPublic
Returnstrue if this class is not public.- Returns:
true if this class is not public.
-
isStatic
Returnstrue 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
Returnstrue 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
Returnstrue if this class is abstract.Note that interfaces are always reported as abstract.
- Returns:
true if this class is abstract.
-
isNotAbstract
Returnstrue if this class is not abstract.Note that interfaces are always reported as abstract.
- Returns:
true if this class is not abstract.
-
isMemberClass
Returnstrue if this class is a member class.- Returns:
true if this class is a member class.
-
isNotMemberClass
Returnstrue if this class is a member class.- Returns:
true if this class is a member class.
-
isNonStaticMemberClass
Returnstrue if this class is a member class and not static.- Returns:
true if this class is a member class and not static.
-
isNotNonStaticMemberClass
Returnsfalse if this class is a member class and not static.- Returns:
false if this class is a member class and not static.
-
isLocalClass
Returnstrue if this class is a local class.- Returns:
true if this class is a local class.
-
isNotLocalClass
Returnstrue if this class is a local class.- Returns:
true if this class is a local class.
-
isVisible
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
Returnstrue if this is a primitive class.- Returns:
true if this is a primitive class.
-
isNotPrimitive
Returnstrue if this is not a primitive class.- Returns:
true if this is not a primitive class.
-
isInterface
Returnstrue if this class is an interface.- Returns:
true if this class is an interface.
-
isClass
Returnstrue if this class is not an interface.- Returns:
true if this class is not an interface.
-
isRuntimeException
Returnstrue if this class is aRuntimeException
.- Returns:
true if this class is aRuntimeException
.
-
hasPrimitiveWrapper
Returnstrue if thegetPrimitiveWrapper()
method returns a value.- Returns:
true if thegetPrimitiveWrapper()
method returns a value.
-
getPrimitiveWrapper
If this class is a primitive (e.g.
) returns it's wrapper class (e.g.int .class Integer.
).class - Returns:
- The wrapper class, or
null if class is not a primitive.
-
getPrimitiveForWrapper
If this class is a primitive wrapper (e.g.
) returns it's primitive class (e.g.Integer .class int.
).class - Returns:
- The primitive class, or
null if class is not a primitive wrapper.
-
getWrapperIfPrimitive
If this class is a primitive (e.g.
) returns it's wrapper class (e.g.int .class Integer.
).class - Returns:
- The wrapper class if it's primitive, or the same class if class is not a primitive.
-
getWrapperInfoIfPrimitive
Same asgetWrapperIfPrimitive()
but wraps it in aClassInfo
.- 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
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
Returns all possible names for this class.- Returns:
- An array consisting of:
getFullName()
Class.getName()
- Note that this might be a dup.getShortName()
getSimpleName()
-
appendFullName
Same asgetFullName()
but appends to an existing string builder.- Parameters:
sb
- The string builder to append to.- Returns:
- The same string builder.
-
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 asgetShortName()
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()
orType.getTypeName()
depending on whether this is a class or type.- Returns:
- The simple name of the underlying class;
-
getName
Returns the name of the underlying class.- Returns:
- The name of the underlying class.
-
getReadableName
- Returns:
- The readable name for this class.
-
isParentOf
Returnstrue if this class is a parent or the same aschild .- Parameters:
child
- The child class.- Returns:
true if this class is a parent or the same aschild .
-
isParentOfFuzzyPrimitives
Returnstrue if this class is a parent or the same aschild .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 aschild .
-
canAcceptArg
Returnstrue 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
Same asisParentOfFuzzyPrimitives(Class)
but takes in aClassInfo
.- Parameters:
child
- The child class.- Returns:
true if this class is a parent or the same aschild .
-
isParentOf
Returnstrue if this class is a parent or the same aschild .- Parameters:
child
- The child class.- Returns:
true if this class is a parent or the same aschild .
-
isParentOfFuzzyPrimitives
Returnstrue if this class is a parent or the same aschild .- Parameters:
child
- The child class.- Returns:
true if this class is a parent or the same aschild .
-
isStrictChildOf
Returnstrue if this class is a child ofparent .- Parameters:
parent
- The parent class.- Returns:
true if this class is a parent ofchild .
-
isChildOf
Returnstrue if this class is a child or the same asparent .- Parameters:
parent
- The parent class.- Returns:
true if this class is a child or the same asparent .
-
isChildOfAny
Returnstrue if this class is a child or the same as any of theparents .- Parameters:
parents
- The parents class.- Returns:
true if this class is a child or the same as any of theparents .
-
isChildOf
Returnstrue if this class is a child or the same asparent .- Parameters:
parent
- The parent class.- Returns:
true if this class is a parent or the same asparent .
-
isChildOf
Returnstrue if this class is a child or the same asparent .- Parameters:
parent
- The parent class.- Returns:
true if this class is a parent or the same asparent .
-
is
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
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
Returnstrue 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
Returnstrue 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
Returnstrue 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
Returns the package of this class.- Returns:
- The package of this class.
-
hasPackage
Returnstrue if this class is not in the root package.- Returns:
true if this class is not in the root package.
-
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
Returnstrue if this class is an enum.- Returns:
true if this class is an enum.
-
isRepeatedAnnotation
Returnstrue 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
Returnstrue if this class is an array.- Returns:
true if this class is an array.
-
isAnnotation
Returnstrue if this class is an annotation.- Returns:
true if this class is an annotation.
-
isCollectionOrArray
Returnstrue if this class is aCollection
or an array.- Returns:
true if this class is aCollection
or an array.
-
newInstance
Shortcut for callingClass.getDeclaredConstructor().newInstance() on the underlying class.- Returns:
- A new instance of the underlying class
- Throws:
ExecutableException
- Exception occurred on invoked constructor/method/field.
-
getParameterType
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
Returnstrue 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 benull .action
- An action to perform on this object.- Returns:
- This object.
-
toString
-
hashCode
-
equals
-