Class FieldInfo

java.lang.Object
org.apache.juneau.reflect.FieldInfo
All Implemented Interfaces:
Comparable<FieldInfo>

public final class FieldInfo extends Object implements Comparable<FieldInfo>
Lightweight utility class for introspecting information about a field.
See Also:
  • Constructor Details

    • FieldInfo

      protected FieldInfo(ClassInfo declaringClass, Field f)
      Constructor.
      Parameters:
      declaringClass - The class that declares this method.
      f - The field being wrapped.
  • Method Details

    • of

      public static FieldInfo of(ClassInfo declaringClass, Field f)
      Convenience method for instantiating a FieldInfo;
      Parameters:
      declaringClass - The class that declares this method.
      f - The field being wrapped.
      Returns:
      A new FieldInfo object, or null if the field was null.
    • of

      public static FieldInfo of(Field f)
      Convenience method for instantiating a FieldInfo;
      Parameters:
      f - The field being wrapped.
      Returns:
      A new FieldInfo object, or null if the field was null.
    • inner

      public Field inner()
      Returns the wrapped field.
      Returns:
      The wrapped field.
    • getDeclaringClass

      Returns metadata about the declaring class.
      Returns:
      Metadata about the declaring class.
    • getAnnotation

      public <A extends Annotation> A getAnnotation(Class<A> type)
      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

      public <A extends Annotation> A getAnnotation(AnnotationProvider annotationProvider, Class<A> type)
      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

      public <A extends Annotation> boolean hasAnnotation(Class<A> type)
      Returns true 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

      public <A extends Annotation> boolean hasNoAnnotation(Class<A> type)
      Returns true 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)
      Returns true 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)
      Returns true 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

      public boolean isAll(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.
    • isAny

      public boolean isAny(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.
    • 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.
    • isDeprecated

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

      public boolean isNotDeprecated()
      Returns true 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

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

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

      public boolean isStatic()
      Returns true if this field is static.
      Returns:
      true if this field is static.
    • isNotStatic

      public boolean isNotStatic()
      Returns true if this field is not static.
      Returns:
      true if this field is not static.
    • isTransient

      public boolean isTransient()
      Returns true if this field is transient.
      Returns:
      true if this field is transient.
    • isNotTransient

      public boolean isNotTransient()
      Returns true if this field is not transient.
      Returns:
      true if this field is not transient.
    • hasName

      public boolean hasName(String name)
      Returns true 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 call x.setAccessible(true) and quietly ignores security exceptions.
      Returns:
      This object.
    • setAccessible

      public boolean setAccessible()
      Attempts to call x.setAccessible(true) and quietly ignores security exceptions.
      Returns:
      true if call was successful.
    • isVisible

      public boolean isVisible(Visibility v)
      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

      public boolean matches(Predicate<FieldInfo> 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.
    • getType

      public ClassInfo getType()
      Returns the type of this field.
      Returns:
      The type of this field.
    • toString

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

      public int compareTo(FieldInfo o)
      Specified by:
      compareTo in interface Comparable<FieldInfo>
    • getName

      public String getName()
      Returns the name of this field.
      Returns:
      The name of this field.
    • getFullName

      public String getFullName()
      Returns the full name of this field.
      Examples:
      • "com.foo.MyClass.myField" - Method.
      Returns:
      The underlying executable name.
    • get

      public <T> T get(Object o) throws BeanRuntimeException
      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

      public <T> Optional<T> getOptional(Object o) throws BeanRuntimeException
      Same as get(Object) but wraps the results in an Optional.
      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

      public void set(Object o, Object value) throws BeanRuntimeException
      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

      public void setIfNull(Object o, Object value)
      Sets the field value on the specified object if the value is null.
      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.