Class FieldInfo
- All Implemented Interfaces:
AnnotationTarget,Declaration,Descriptor,GenericSignature
Thread-Safety
This class is immutable and can be shared between threads without safe publication.- Author:
- Jason T. Greene
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jboss.jandex.AnnotationTarget
AnnotationTarget.Kind -
Field Summary
Fields inherited from interface org.jboss.jandex.Descriptor
NO_SUBSTITUTIONFields inherited from interface org.jboss.jandex.GenericSignature
NO_SUBSTITUTION -
Method Summary
Modifier and TypeMethodDescriptionfinal AnnotationInstanceannotation(DotName name) Returns the annotation instance with given name declared on this field or any type within its signature.final List<AnnotationInstance>Returns the annotation instances declared on this field or any type within its signature.final List<AnnotationInstance>annotations(DotName name) Returns the annotation instances with given name declared on this field or any type within its signature.final List<AnnotationInstance>annotationsWithRepeatable(DotName name, IndexView index) Returns the annotation instances with given name declared on this field or any type within its signature.final ClassInfoasClass()Casts and returns this target as aClassInfoif it is of kindCLASSfinal FieldInfoasField()Casts and returns this target as aFieldInfoif it is of kindFIELDfinal MethodInfoasMethod()Casts and returns this target as aMethodInfoif it is of kindMETHODfinal MethodParameterInfoCasts and returns this target as aMethodParameterInfoif it is of kindMETHOD_PARAMETERfinal RecordComponentInfoCasts and returns this target as aRecordComponentInfoif it is of kindRECORD_COMPONENTfinal TypeTargetasType()Casts and returns this target as aTypeTargetif it is of kindTYPEstatic FieldInfoConstruct a new mock Field instance.final AnnotationInstancedeclaredAnnotation(DotName name) Returns the annotation instance with given name declared on this field.final List<AnnotationInstance>Returns the annotation instances declared on this field.final List<AnnotationInstance>declaredAnnotationsWithRepeatable(DotName name, IndexView index) Returns the annotation instances with given name declared on this field.final ClassInfoReturns the class which declared the fielddescriptor(Function<String, Type> typeVariableSubstitution) Returns a bytecode descriptor of this field.intReturns an ordinal of this enum constant, that is, the zero-based position in the enum declaration.booleanfinal shortflags()Returns the access fields of this field.genericSignature(Function<String, Type> typeVariableSubstitution) Returns a generic signature of this field, possibly without any generic-related information.final booleanhasAnnotation(DotName name) Returns whether an annotation instance with given name is declared on this field or any type within its signature.final booleanhasDeclaredAnnotation(DotName name) Returns whether an annotation instance with given name is declared on this field.inthashCode()final booleanReturns whether this field is declared as an element of an enum.final booleanfinal AnnotationTarget.Kindkind()Returns the kind of object this target represents.final Stringname()Returns the local name of the fieldbooleanReturns whether this field must have a generic signature.toString()Returns a string representation describing this field.final Typetype()Returns theTypedeclared on this field.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jboss.jandex.AnnotationTarget
annotation, annotation, annotations, annotations, annotationsWithRepeatable, annotationsWithRepeatable, declaredAnnotation, declaredAnnotation, declaredAnnotationsWithRepeatable, declaredAnnotationsWithRepeatable, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotationMethods inherited from interface org.jboss.jandex.Declaration
asDeclaration, isDeclarationMethods inherited from interface org.jboss.jandex.Descriptor
descriptorMethods inherited from interface org.jboss.jandex.GenericSignature
genericSignature, genericSignatureIfRequired, genericSignatureIfRequired
-
Method Details
-
create
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
Returns the local name of the field- Returns:
- the local name of the field
-
declaringClass
Returns the class which declared the field- Returns:
- the declaring class
-
type
Returns theTypedeclared on this field. This may be an array, a primitive, or a generic type definition.- Returns:
- the type of this field
-
kind
Description copied from interface:AnnotationTargetReturns the kind of object this target represents.- Specified by:
kindin interfaceAnnotationTarget- Returns:
- the target kind.
-
hasAnnotation
Returns whether an annotation instance with given name is declared on this field or any type within its signature.- Specified by:
hasAnnotationin interfaceAnnotationTarget- Parameters:
name- name of the annotation type to look for, must not benull- Returns:
trueif the annotation is present,falseotherwise- See Also:
-
annotation
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:
annotationin interfaceAnnotationTarget- Parameters:
name- name of the annotation type to look for, must not benull- Returns:
- the annotation instance, or
nullif not found - See Also:
-
annotations
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:
annotationsin interfaceAnnotationTarget- Parameters:
name- name of the annotation type, must not benull- Returns:
- immutable list of annotation instances, never
null - See Also:
-
annotationsWithRepeatable
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:
annotationsWithRepeatablein interfaceAnnotationTarget- Parameters:
name- name of the annotation type, must not benullindex- index used to obtain the annotation type, must not benull- Returns:
- immutable list of annotation instances, never
null - Throws:
IllegalArgumentException- if the index isnull, if the index does not contain the annotation type or ifnamedoes not identify an annotation type- See Also:
-
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:
annotationsin interfaceAnnotationTarget- Returns:
- collection of annotation instances, never
null
-
hasDeclaredAnnotation
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:
hasDeclaredAnnotationin interfaceAnnotationTarget- Parameters:
name- name of the annotation type to look for, must not benull- Returns:
trueif the annotation is present,falseotherwise- Since:
- 3.0
- See Also:
-
declaredAnnotation
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:
declaredAnnotationin interfaceAnnotationTarget- Parameters:
name- name of the annotation type to look for, must not benull- Returns:
- the annotation instance, or
nullif not found - Since:
- 3.0
- See Also:
-
declaredAnnotationsWithRepeatable
public final 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:
declaredAnnotationsWithRepeatablein interfaceAnnotationTarget- Parameters:
name- name of the annotation type, must not benullindex- index used to obtain the annotation type, must not benull- Returns:
- list of annotation instances, never
null - Throws:
IllegalArgumentException- if the index isnull, if the index does not contain the annotation type or ifnamedoes not identify an annotation type- Since:
- 3.0
- See Also:
-
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:
declaredAnnotationsin interfaceAnnotationTarget- Returns:
- list of annotation instances, never
null - Since:
- 3.0
- See Also:
-
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:
-
flags
public final short flags()Returns the access fields of this field.Modifiercan be used on this value.- Returns:
- the access flags of this field
-
isSynthetic
public final boolean isSynthetic()- Returns:
trueif 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 theSignaturebytecode attribute.- Specified by:
requiresGenericSignaturein interfaceGenericSignature- Returns:
- whether this field must have a generic signature
-
genericSignature
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 returnsnullfor 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:
genericSignaturein 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
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 returnsnullfor 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:
descriptorin interfaceDescriptor- Parameters:
typeVariableSubstitution- a substitution function from type variable identifiers to types- Returns:
- the bytecode descriptor of this field
-
toString
Returns a string representation describing this field. It is similar although not necessarily identical to a Java source code declaration of this field. -
asClass
Description copied from interface:AnnotationTargetCasts and returns this target as aClassInfoif it is of kindCLASS- Specified by:
asClassin interfaceAnnotationTarget- Returns:
- this instance cast to a class
-
asField
Description copied from interface:AnnotationTargetCasts and returns this target as aFieldInfoif it is of kindFIELD- Specified by:
asFieldin interfaceAnnotationTarget- Returns:
- this instance cast to a field
-
asMethod
Description copied from interface:AnnotationTargetCasts and returns this target as aMethodInfoif it is of kindMETHOD- Specified by:
asMethodin interfaceAnnotationTarget- Returns:
- this instance cast to a method
-
asMethodParameter
Description copied from interface:AnnotationTargetCasts and returns this target as aMethodParameterInfoif it is of kindMETHOD_PARAMETER- Specified by:
asMethodParameterin interfaceAnnotationTarget- Returns:
- this instance cast to a method parameter
-
asType
Description copied from interface:AnnotationTargetCasts and returns this target as aTypeTargetif it is of kindTYPE- Specified by:
asTypein interfaceAnnotationTarget- Returns:
- this instance cast to a type target
-
asRecordComponent
Description copied from interface:AnnotationTargetCasts and returns this target as aRecordComponentInfoif it is of kindRECORD_COMPONENT- Specified by:
asRecordComponentin interfaceAnnotationTarget- Returns:
- this instance cast to a record component
-
hashCode
public int hashCode() -
equals
-