Class FieldInfo

java.lang.Object
org.jboss.jandex.FieldInfo
All Implemented Interfaces:
AnnotationTarget

public final class FieldInfo extends Object implements AnnotationTarget
Represents a field.

Thread-Safety

This class is immutable and can be shared between threads without safe publication.
  • Field Details

  • Constructor Details

  • Method Details

    • create

      public static FieldInfo create(ClassInfo clazz, String name, Type type, short flags)
      Construct a new mock Field instance.
      Parameters:
      clazz - the class declaring the field
      name - the name of the field
      type - the Java field type
      flags - the field attributes
      Returns:
      a mock field
    • name

      public final String name()
      Returns the local name of the field
      Returns:
      the local name of the field
    • declaringClass

      public final ClassInfo declaringClass()
      Returns the class which declared the field
      Returns:
      the declaring class
    • type

      public final Type type()
      Returns the Type declared on this field. This may be an array, a primitive, or a generic type definition.
      Returns:
      the type of this field
    • kind

      public final AnnotationTarget.Kind kind()
      Description copied from interface: AnnotationTarget
      Returns the kind of object this target represents.
      Specified by:
      kind in interface AnnotationTarget
      Returns:
      the target kind.
    • annotations

      public List<AnnotationInstance> annotations()
      Returns the list of annotation instances declared on this field. It may be empty, but never null.
      Returns:
      the list of annotations on this field
    • annotation

      public final AnnotationInstance annotation(DotName name)
      Retrieves an annotation instance declared on this field. If an annotation by that name is not present, null will be returned.
      Parameters:
      name - the name of the annotation to locate on this field
      Returns:
      the annotation if found, otherwise, null
    • annotationsWithRepeatable

      public final List<AnnotationInstance> annotationsWithRepeatable(DotName name, IndexView index)
      Retrieves annotation instances declared on this field, by the name of the annotation. If the specified annotation is repeatable (JLS 9.6), the result also contains all values from the container annotation instance.
      Parameters:
      name - the name of the annotation
      index - the index used to obtain the annotation class
      Returns:
      the annotation instances declared on this field, or an empty list if none
      Throws:
      IllegalArgumentException - If the index does not contain the annotation definition or if it does not represent an annotation type
    • hasAnnotation

      public final boolean hasAnnotation(DotName name)
      Returns whether or not the annotation instance with the given name occurs on this field
      Parameters:
      name - the name of the annotation to look for
      Returns:
      true if the annotation is present, false otherwise
      See Also:
    • isEnumConstant

      public boolean isEnumConstant()
      Returns whether or not this field is declared as an element of an enum.
      Returns:
      true if the field is declared as an element of an enum, false otherwise.
      See Also:
    • flags

      public final short flags()
      Returns the access fields of this field. Modifier can be used on this value.
      Returns:
      the access flags of this field
    • isSynthetic

      public final boolean isSynthetic()
      Returns:
      true if this field is a synthetic field
    • toString

      public String toString()
      Returns a string representation describing this field. It is similar although not necessarily equivalent to a Java source code expression representing this field.
      Overrides:
      toString in class Object
      Returns:
      a string representation for this field
    • asClass

      public final ClassInfo asClass()
      Description copied from interface: AnnotationTarget
      Casts and returns this target as a ClassInfo if it is of kind CLASS
      Specified by:
      asClass in interface AnnotationTarget
      Returns:
      this instance cast to a class
    • asField

      public final FieldInfo asField()
      Description copied from interface: AnnotationTarget
      Casts and returns this target as a FieldInfo if it is of kind FIELD
      Specified by:
      asField in interface AnnotationTarget
      Returns:
      this instance cast to a field
    • asMethod

      public final MethodInfo asMethod()
      Description copied from interface: AnnotationTarget
      Casts and returns this target as a MethodInfo if it is of kind METHOD
      Specified by:
      asMethod in interface AnnotationTarget
      Returns:
      this instance cast to a method
    • asMethodParameter

      public final MethodParameterInfo asMethodParameter()
      Description copied from interface: AnnotationTarget
      Casts and returns this target as a MethodParameterInfo if it is of kind METHOD_PARAMETER
      Specified by:
      asMethodParameter in interface AnnotationTarget
      Returns:
      this instance cast to a method parameter
    • asType

      public final TypeTarget asType()
      Description copied from interface: AnnotationTarget
      Casts and returns this target as a TypeTarget if it is of kind TYPE
      Specified by:
      asType in interface AnnotationTarget
      Returns:
      this instance cast to a type target
    • asRecordComponent

      public RecordComponentInfo asRecordComponent()
      Description copied from interface: AnnotationTarget
      Casts and returns this target as a RecordComponentInfo if it is of kind RECORD_COMPONENT
      Specified by:
      asRecordComponent in interface AnnotationTarget
      Returns:
      this instance cast to a record component
    • hashCode

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

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

      void setType(Type type)
    • setAnnotations

      void setAnnotations(List<AnnotationInstance> annotations)
    • fieldInternal

      FieldInternal fieldInternal()
    • setFieldInternal

      void setFieldInternal(FieldInternal internal)
    • setClassInfo

      void setClassInfo(ClassInfo clazz)