Class RecordComponentInfo

  • All Implemented Interfaces:
    AnnotationTarget

    public final class RecordComponentInfo
    extends java.lang.Object
    implements AnnotationTarget
    Represents an individual Java record component that was annotated.

    Thread-Safety

    This class is immutable and can be shared between threads without safe publication.
    • Constructor Detail

      • RecordComponentInfo

        RecordComponentInfo()
      • RecordComponentInfo

        RecordComponentInfo​(ClassInfo clazz,
                            byte[] name,
                            Type type)
    • Method Detail

      • create

        public static RecordComponentInfo create​(ClassInfo clazz,
                                                 java.lang.String name,
                                                 Type type)
        Constructs a new mock record component info
        Parameters:
        clazz - the (record) class declaring this record component
        name - the name of this record component
        type - the type of this record component
        Returns:
        the new mock record component info
      • declaringClass

        public final ClassInfo declaringClass()
        Returns the (record) class declaring this record component.
        Returns:
        the (record) class declaring this record component
      • field

        public final FieldInfo field()
        Returns the component field corresponding to this record component.
        Returns:
        the component field
      • accessor

        public final MethodInfo accessor()
        Returns the accessor method corresponding to this record component.
        Returns:
        the accessor method
      • name

        public final java.lang.String name()
        Returns the name of this record component.
        Returns:
        the name of this record component
      • type

        public Type type()
        Returns the type of this record component.
        Returns:
        the type of this record component
      • annotations

        public java.util.List<AnnotationInstance> annotations()
        Returns the list of annotation instances declared on this record component. It may be empty, but never null.
        Returns:
        the list of annotations on this record component
      • 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 java.util.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:
        java.lang.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:
        annotations(), annotation(DotName)
      • toString

        public java.lang.String toString()
        Returns a string representation describing this record component.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of this record component
      • 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
      • 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
      • hashCode

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

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • setType

        void setType​(Type type)
      • setClassInfo

        void setClassInfo​(ClassInfo clazz)