Class FieldInfo
- java.lang.Object
-
- org.jboss.jandex.FieldInfo
-
- All Implemented Interfaces:
AnnotationTarget
,Declaration
,Descriptor
,GenericSignature
public final class FieldInfo extends java.lang.Object implements Declaration, Descriptor, GenericSignature
Represents a field.Thread-Safety
This class is immutable and can be shared between threads without safe publication.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jboss.jandex.AnnotationTarget
AnnotationTarget.Kind
-
-
Field Summary
Fields Modifier and Type Field Description private ClassInfo
clazz
private FieldInternal
internal
-
Fields inherited from interface org.jboss.jandex.Descriptor
NO_SUBSTITUTION
-
Fields inherited from interface org.jboss.jandex.GenericSignature
NO_SUBSTITUTION
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AnnotationInstance
annotation(DotName name)
Returns the annotation instance with given name declared on this field or any type within its signature.java.util.List<AnnotationInstance>
annotations()
Returns the annotation instances declared on this field or any type within its signature.java.util.List<AnnotationInstance>
annotations(DotName name)
Returns the annotation instances with given name declared on this field or any type within its signature.java.util.List<AnnotationInstance>
annotationsWithRepeatable(DotName name, IndexView index)
Returns the annotation instances with given name declared on this field or any type within its signature.ClassInfo
asClass()
Casts and returns this target as aClassInfo
if it is of kindCLASS
FieldInfo
asField()
Casts and returns this target as aFieldInfo
if it is of kindFIELD
MethodInfo
asMethod()
Casts and returns this target as aMethodInfo
if it is of kindMETHOD
MethodParameterInfo
asMethodParameter()
Casts and returns this target as aMethodParameterInfo
if it is of kindMETHOD_PARAMETER
RecordComponentInfo
asRecordComponent()
Casts and returns this target as aRecordComponentInfo
if it is of kindRECORD_COMPONENT
TypeTarget
asType()
Casts and returns this target as aTypeTarget
if it is of kindTYPE
static FieldInfo
create(ClassInfo clazz, java.lang.String name, Type type, short flags)
Construct a new mock Field instance.AnnotationInstance
declaredAnnotation(DotName name)
Returns the annotation instance with given name declared on this field.java.util.List<AnnotationInstance>
declaredAnnotations()
Returns the annotation instances declared on this field.java.util.List<AnnotationInstance>
declaredAnnotationsWithRepeatable(DotName name, IndexView index)
Returns the annotation instances with given name declared on this field.ClassInfo
declaringClass()
Returns the class which declared the fieldjava.lang.String
descriptor(java.util.function.Function<java.lang.String,Type> typeVariableSubstitution)
Returns a bytecode descriptor of this field.int
enumConstantOrdinal()
Returns an ordinal of this enum constant, that is, the zero-based position in the enum declaration.boolean
equals(java.lang.Object o)
(package private) FieldInternal
fieldInternal()
short
flags()
Returns the access fields of this field.java.lang.String
genericSignature(java.util.function.Function<java.lang.String,Type> typeVariableSubstitution)
Returns a generic signature of this field, possibly without any generic-related information.boolean
hasAnnotation(DotName name)
Returns whether an annotation instance with given name is declared on this field or any type within its signature.boolean
hasDeclaredAnnotation(DotName name)
Returns whether an annotation instance with given name is declared on this field.int
hashCode()
boolean
isEnumConstant()
Returns whether this field is declared as an element of an enum.boolean
isSynthetic()
AnnotationTarget.Kind
kind()
Returns the kind of object this target represents.java.lang.String
name()
Returns the local name of the fieldboolean
requiresGenericSignature()
Returns whether this field must have a generic signature.(package private) void
setAnnotations(java.util.List<AnnotationInstance> annotations)
(package private) void
setClassInfo(ClassInfo clazz)
(package private) void
setFieldInternal(FieldInternal internal)
(package private) void
setType(Type type)
java.lang.String
toString()
Returns a string representation describing this field.Type
type()
Returns theType
declared on this field.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jboss.jandex.AnnotationTarget
annotation, annotation, annotations, annotations, annotationsWithRepeatable, annotationsWithRepeatable, declaredAnnotation, declaredAnnotation, declaredAnnotationsWithRepeatable, declaredAnnotationsWithRepeatable, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotation
-
Methods inherited from interface org.jboss.jandex.Declaration
asDeclaration, isDeclaration
-
Methods inherited from interface org.jboss.jandex.Descriptor
descriptor
-
Methods inherited from interface org.jboss.jandex.GenericSignature
genericSignature, genericSignatureIfRequired, genericSignatureIfRequired
-
-
-
-
Field Detail
-
clazz
private ClassInfo clazz
-
internal
private FieldInternal internal
-
-
Constructor Detail
-
FieldInfo
FieldInfo()
-
FieldInfo
FieldInfo(ClassInfo clazz, FieldInternal internal)
-
-
Method Detail
-
create
public static FieldInfo create(ClassInfo clazz, java.lang.String name, Type type, short flags)
Construct a new mock Field instance.- Parameters:
clazz
- the class declaring the fieldname
- the name of the fieldtype
- the Java field typeflags
- the field attributes- Returns:
- a mock field
-
name
public final java.lang.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 theType
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 interfaceAnnotationTarget
- Returns:
- the target kind.
-
hasAnnotation
public final boolean hasAnnotation(DotName name)
Returns whether an annotation instance with given name is declared on this field or any type within its signature.- Specified by:
hasAnnotation
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type to look for, must not benull
- Returns:
true
if the annotation is present,false
otherwise- See Also:
annotation(DotName)
-
annotation
public final AnnotationInstance annotation(DotName name)
Returns the annotation instance with given name declared on this field or any type within its signature. Thetarget()
method of the returned annotation instance may be used to determine the exact location of the annotation instance.The following is a non-exhaustive list of examples of annotations returned by this method:
@MyFieldAnnotation public String foo; public List<@MyTypeAnnotation String> bar;
In case an annotation with given name occurs more than once, the result of this method is not deterministic. For such situations,
annotations(DotName)
is preferable.- Specified by:
annotation
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type to look for, must not benull
- Returns:
- the annotation instance, or
null
if not found - See Also:
annotations(DotName)
-
annotations
public final java.util.List<AnnotationInstance> annotations(DotName name)
Returns the annotation instances with given name declared on this field or any type within its signature. Thetarget()
method of the returned annotation instances may be used to determine the exact location of the respective annotation instance.The following is a non-exhaustive list of examples of annotations returned by this method:
@MyFieldAnnotation public String foo; public List<@MyTypeAnnotation String> bar;
- Specified by:
annotations
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type, must not benull
- Returns:
- immutable list of annotation instances, never
null
- See Also:
annotationsWithRepeatable(DotName, IndexView)
,annotations()
-
annotationsWithRepeatable
public final java.util.List<AnnotationInstance> annotationsWithRepeatable(DotName name, IndexView index)
Returns the annotation instances with given name declared on this field or any type within its signature. Thetarget()
method of the returned annotation instances may be used to determine the exact location of the respective annotation instance.If the specified annotation is repeatable, the result also contains all values from the container annotation instance. In this case, the
AnnotationInstance.target()
returns the target of the container annotation instance.- Specified by:
annotationsWithRepeatable
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type, must not benull
index
- index used to obtain the annotation type, must not benull
- Returns:
- immutable list of annotation instances, never
null
- Throws:
java.lang.IllegalArgumentException
- if the index isnull
, if the index does not contain the annotation type or ifname
does not identify an annotation type- See Also:
annotations(DotName)
,annotations()
-
annotations
public final java.util.List<AnnotationInstance> annotations()
Returns the annotation instances declared on this field or any type within its signature. Thetarget()
method of the returned annotation instances may be used to determine the exact location of the respective annotation instance.The following is a non-exhaustive list of examples of annotations returned by this method:
@MyFieldAnnotation public String foo; public List<@MyTypeAnnotation String> bar;
- Specified by:
annotations
in interfaceAnnotationTarget
- Returns:
- collection of annotation instances, never
null
-
hasDeclaredAnnotation
public final boolean hasDeclaredAnnotation(DotName name)
Returns whether an annotation instance with given name is declared on this field.Unlike
hasAnnotation(DotName)
, this method ignores annotations declared on types within the field signature.- Specified by:
hasDeclaredAnnotation
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type to look for, must not benull
- Returns:
true
if the annotation is present,false
otherwise- Since:
- 3.0
- See Also:
hasAnnotation(DotName)
-
declaredAnnotation
public final AnnotationInstance declaredAnnotation(DotName name)
Returns the annotation instance with given name declared on this field.Unlike
annotation(DotName)
, this method doesn't return annotations declared on types within the field signature.- Specified by:
declaredAnnotation
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type to look for, must not benull
- Returns:
- the annotation instance, or
null
if not found - Since:
- 3.0
- See Also:
annotation(DotName)
-
declaredAnnotationsWithRepeatable
public final java.util.List<AnnotationInstance> declaredAnnotationsWithRepeatable(DotName name, IndexView index)
Returns the annotation instances with given name declared on this field.If the specified annotation is repeatable, the result also contains all values from the container annotation instance. In this case, the
AnnotationInstance.target()
returns the target of the container annotation instance.Unlike
annotationsWithRepeatable(DotName, IndexView)
, this method doesn't return annotations declared on types within the field signature.- Specified by:
declaredAnnotationsWithRepeatable
in interfaceAnnotationTarget
- Parameters:
name
- name of the annotation type, must not benull
index
- index used to obtain the annotation type, must not benull
- Returns:
- list of annotation instances, never
null
- Throws:
java.lang.IllegalArgumentException
- if the index isnull
, if the index does not contain the annotation type or ifname
does not identify an annotation type- Since:
- 3.0
- See Also:
annotationsWithRepeatable(DotName, IndexView)
-
declaredAnnotations
public final java.util.List<AnnotationInstance> declaredAnnotations()
Returns the annotation instances declared on this field.Unlike
annotations()
, this method doesn't return annotations declared on types within the field signature.- Specified by:
declaredAnnotations
in interfaceAnnotationTarget
- Returns:
- list of annotation instances, never
null
- Since:
- 3.0
- See Also:
annotations()
-
isEnumConstant
public final boolean isEnumConstant()
Returns whether 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:
Field.isEnumConstant()
-
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
-
enumConstantOrdinal
public int enumConstantOrdinal()
Returns an ordinal of this enum constant, that is, the zero-based position in the enum declaration. This is currently very inefficient (requires traversing fields of the declaring class), but may be improved in the future.If this field is not an enum constant, returns -1.
Note that for the result to actually be the ordinal value, the index must be produced by at least Jandex 2.4. Previous Jandex versions do not store field positions. At most 256 fields may be present in the class; if there's more, outcome is undefined. This also assumes that the bytecode order corresponds to declaration order, which is not guaranteed, but practically always holds.
- Returns:
- ordinal of this enum constant, or -1 if this field is not an enum constant
- Since:
- 3.0.1
-
requiresGenericSignature
public boolean requiresGenericSignature()
Returns whether this field must have a generic signature. That is, whether the Java compiler when compiling this field had to emit theSignature
bytecode attribute.- Specified by:
requiresGenericSignature
in interfaceGenericSignature
- Returns:
- whether this field must have a generic signature
-
genericSignature
public java.lang.String genericSignature(java.util.function.Function<java.lang.String,Type> typeVariableSubstitution)
Returns a generic signature of this field, possibly without any generic-related information. That is, produces a correct generic signature even if this field does not use any type variables.Signatures of type variables are substituted for signatures of types provided by the substitution function
typeVariableSubstitution
. If the substitution function returnsnull
for some type variable identifier, no substitution happens and the type variable signature is used unmodified.Note that the return value does not come directly from bytecode. Jandex does not store the signature strings. Instead, the return value is reconstructed from the Jandex object model.
- Specified by:
genericSignature
in interfaceGenericSignature
- Parameters:
typeVariableSubstitution
- a substitution function from type variable identifiers to types- Returns:
- a generic signature of this field with type variables substituted, never
null
-
descriptor
public java.lang.String descriptor(java.util.function.Function<java.lang.String,Type> typeVariableSubstitution)
Returns a bytecode descriptor of this field.Descriptors of type variables are substituted for descriptors of types provided by the substitution function
typeVariableSubstitution
. If the substitution function returnsnull
for some type variable identifier, or if it returns the type variable itself, no substitution happens and the type variable descriptor is used unmodified.Note that the return value does not come directly from bytecode. Jandex does not store the descriptor strings. Instead, the return value is reconstructed from the Jandex object model.
- Specified by:
descriptor
in interfaceDescriptor
- Parameters:
typeVariableSubstitution
- a substitution function from type variable identifiers to types- Returns:
- the bytecode descriptor of this field
-
toString
public java.lang.String toString()
Returns a string representation describing this field. It is similar although not necessarily identical to a Java source code declaration of this field.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation of this field
-
asClass
public final ClassInfo asClass()
Description copied from interface:AnnotationTarget
Casts and returns this target as aClassInfo
if it is of kindCLASS
- Specified by:
asClass
in interfaceAnnotationTarget
- Returns:
- this instance cast to a class
-
asField
public final FieldInfo asField()
Description copied from interface:AnnotationTarget
Casts and returns this target as aFieldInfo
if it is of kindFIELD
- Specified by:
asField
in interfaceAnnotationTarget
- Returns:
- this instance cast to a field
-
asMethod
public final MethodInfo asMethod()
Description copied from interface:AnnotationTarget
Casts and returns this target as aMethodInfo
if it is of kindMETHOD
- Specified by:
asMethod
in interfaceAnnotationTarget
- Returns:
- this instance cast to a method
-
asMethodParameter
public final MethodParameterInfo asMethodParameter()
Description copied from interface:AnnotationTarget
Casts and returns this target as aMethodParameterInfo
if it is of kindMETHOD_PARAMETER
- Specified by:
asMethodParameter
in interfaceAnnotationTarget
- Returns:
- this instance cast to a method parameter
-
asType
public final TypeTarget asType()
Description copied from interface:AnnotationTarget
Casts and returns this target as aTypeTarget
if it is of kindTYPE
- Specified by:
asType
in interfaceAnnotationTarget
- Returns:
- this instance cast to a type target
-
asRecordComponent
public final RecordComponentInfo asRecordComponent()
Description copied from interface:AnnotationTarget
Casts and returns this target as aRecordComponentInfo
if it is of kindRECORD_COMPONENT
- Specified by:
asRecordComponent
in interfaceAnnotationTarget
- Returns:
- this instance cast to a record component
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
setType
void setType(Type type)
-
setAnnotations
void setAnnotations(java.util.List<AnnotationInstance> annotations)
-
fieldInternal
FieldInternal fieldInternal()
-
setFieldInternal
void setFieldInternal(FieldInternal internal)
-
setClassInfo
void setClassInfo(ClassInfo clazz)
-
-