Package org.apache.juneau.reflect
Class FieldInfo
java.lang.Object
org.apache.juneau.reflect.FieldInfo
- All Implemented Interfaces:
Comparable<FieldInfo>
Lightweight utility class for introspecting information about a field.
See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionPerforms an action on this object if the specified predicate test passes.Attempts to callx.setAccessible(
and quietly ignores security exceptions.true )int
<T> T
Returns the field value on the specified object.<A extends Annotation>
AgetAnnotation
(Class<A> type) Returns the specified annotation on this field.<A extends Annotation>
AgetAnnotation
(AnnotationProvider annotationProvider, Class<A> type) Returns the specified annotation on this field.Returns metadata about the declaring class.Returns the full name of this field.getName()
Returns the name of this field.<T> Optional<T>
Same asget(Object)
but wraps the results in anOptional
.getType()
Returns the type of this field.<A extends Annotation>
booleanhasAnnotation
(Class<A> type) Returnstrue if the specified annotation is present.<A extends Annotation>
booleanhasAnnotation
(AnnotationProvider annotationProvider, Class<A> type) Returnstrue if the specified annotation is present.boolean
Returnstrue if the field has the specified name.<A extends Annotation>
booleanhasNoAnnotation
(Class<A> type) Returnstrue if the specified annotation is not present on this field.<A extends Annotation>
booleanhasNoAnnotation
(AnnotationProvider annotationProvider, Class<A> type) Returnstrue if the specified annotation is not present.inner()
Returns the wrapped field.boolean
is
(ReflectFlags... flags) Returnstrue if all specified flags are applicable to this field.boolean
isAll
(ReflectFlags... flags) Returnstrue if all specified flags are applicable to this field.boolean
isAny
(ReflectFlags... flags) Returnstrue if all specified flags are applicable to this field.boolean
Returnstrue if this field has the@Deprecated
annotation on it.boolean
Returnstrue if this field doesn't have the@Deprecated
annotation on it.boolean
Returnstrue if this field is not public.boolean
Returnstrue if this field is not static.boolean
Returnstrue if this field is not transient.boolean
isPublic()
Returnstrue if this field is public.boolean
isStatic()
Returnstrue if this field is static.boolean
Returnstrue if this field is transient.boolean
Identifies if the specified visibility matches this field.boolean
Returnstrue if this object passes the specified predicate test.static FieldInfo
Convenience method for instantiating aFieldInfo
;static FieldInfo
Convenience method for instantiating aFieldInfo
;void
Sets the field value on the specified object.boolean
Attempts to callx.setAccessible(
and quietly ignores security exceptions.true )void
Sets the field value on the specified object if the value isnull .toString()
-
Constructor Details
-
FieldInfo
Constructor.- Parameters:
declaringClass
- The class that declares this method.f
- The field being wrapped.
-
-
Method Details
-
of
Convenience method for instantiating aFieldInfo
;- Parameters:
declaringClass
- The class that declares this method.f
- The field being wrapped.- Returns:
- A new
FieldInfo
object, ornull if the field was null.
-
of
Convenience method for instantiating aFieldInfo
;- Parameters:
f
- The field being wrapped.- Returns:
- A new
FieldInfo
object, ornull if the field was null.
-
inner
Returns the wrapped field.- Returns:
- The wrapped field.
-
getDeclaringClass
Returns metadata about the declaring class.- Returns:
- Metadata about the declaring class.
-
getAnnotation
Returns the specified annotation on this field.- Type Parameters:
A
- The annotation type to look for.- Parameters:
type
- The annotation to look for.- Returns:
- The annotation, or
null if not found.
-
getAnnotation
Returns the specified annotation on this field.- Type Parameters:
A
- The annotation type to look for.- Parameters:
annotationProvider
- The annotation provider.type
- The annotation to look for.- Returns:
- The annotation, or
null if not found.
-
hasAnnotation
Returnstrue if the specified annotation is present.- Type Parameters:
A
- The annotation type to look for.- Parameters:
type
- The annotation to look for.- Returns:
true if the specified annotation is present.
-
hasNoAnnotation
Returnstrue if the specified annotation is not present on this field.- Type Parameters:
A
- The annotation type to look for.- Parameters:
type
- The annotation to look for.- Returns:
true if the specified annotation is not present on this field.
-
hasAnnotation
public <A extends Annotation> boolean hasAnnotation(AnnotationProvider annotationProvider, Class<A> type) Returnstrue if the specified annotation is present.- Type Parameters:
A
- The annotation type to look for.- Parameters:
annotationProvider
- The annotation provider.type
- The annotation to look for.- Returns:
true if the specified annotation is present.
-
hasNoAnnotation
public <A extends Annotation> boolean hasNoAnnotation(AnnotationProvider annotationProvider, Class<A> type) Returnstrue if the specified annotation is not present.- Type Parameters:
A
- The annotation type to look for.- Parameters:
annotationProvider
- The annotation provider.type
- The annotation to look for.- Returns:
true if the specified annotation is not present.
-
isAll
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.
-
isAny
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.
-
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.
-
isDeprecated
Returnstrue if this field has the@Deprecated
annotation on it.- Returns:
true if this field has the@Deprecated
annotation on it.
-
isNotDeprecated
Returnstrue if this field doesn't have the@Deprecated
annotation on it.- Returns:
true if this field doesn't have the@Deprecated
annotation on it.
-
isPublic
Returnstrue if this field is public.- Returns:
true if this field is public.
-
isNotPublic
Returnstrue if this field is not public.- Returns:
true if this field is not public.
-
isStatic
Returnstrue if this field is static.- Returns:
true if this field is static.
-
isNotStatic
Returnstrue if this field is not static.- Returns:
true if this field is not static.
-
isTransient
Returnstrue if this field is transient.- Returns:
true if this field is transient.
-
isNotTransient
Returnstrue if this field is not transient.- Returns:
true if this field is not transient.
-
hasName
Returnstrue if the field has the specified name.- Parameters:
name
- The name to compare against.- Returns:
true if the field has the specified name.
-
accessible
Attempts to callx.setAccessible(
and quietly ignores security exceptions.true )- Returns:
- This object.
-
setAccessible
Attempts to callx.setAccessible(
and quietly ignores security exceptions.true )- Returns:
true if call was successful.
-
isVisible
Identifies if the specified visibility matches this field.- Parameters:
v
- The visibility to validate against.- Returns:
true if this visibility matches the modifier attribute of this field.
-
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.
-
getType
Returns the type of this field.- Returns:
- The type of this field.
-
toString
-
compareTo
- Specified by:
compareTo
in interfaceComparable<FieldInfo>
-
getName
Returns the name of this field.- Returns:
- The name of this field.
-
getFullName
Returns the full name of this field.Examples:
"com.foo.MyClass.myField" - Method.
- Returns:
- The underlying executable name.
-
get
Returns the field value on the specified object.- Type Parameters:
T
- The object type to retrieve.- Parameters:
o
- The object containing the field.- Returns:
- The field value.
- Throws:
BeanRuntimeException
- Field was not accessible or field does not belong to object.
-
getOptional
Same asget(Object)
but wraps the results in anOptional
.- Type Parameters:
T
- The object type to retrieve.- Parameters:
o
- The object containing the field.- Returns:
- The field value.
- Throws:
BeanRuntimeException
- Field was not accessible or field does not belong to object.
-
set
Sets the field value on the specified object.- Parameters:
o
- The object containing the field.value
- The new field value.- Throws:
BeanRuntimeException
- Field was not accessible or field does not belong to object.
-
setIfNull
Sets the field value on the specified object if the value isnull .- Parameters:
o
- The object containing the field.value
- The new field value.- Throws:
BeanRuntimeException
- Field was not accessible or field does not belong to object.
-