public final class FieldInfo extends Object implements AnnotationTarget
Thread-Safety
This class is immutable and can be shared between threads without safe publication.AnnotationTarget.Kind| Modifier and Type | Method and Description |
|---|---|
AnnotationInstance |
annotation(DotName name)
Returns the annotation instance with given name declared on this field or any type within its signature.
|
List<AnnotationInstance> |
annotations()
Returns the annotation instances declared on this field or any type within its signature.
|
List<AnnotationInstance> |
annotations(DotName name)
Returns the annotation instances with given name declared on this field or any type within its signature.
|
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 a
ClassInfo if it is of kind CLASS |
FieldInfo |
asField()
Casts and returns this target as a
FieldInfo if it is of kind FIELD |
MethodInfo |
asMethod()
Casts and returns this target as a
MethodInfo if it is of kind METHOD |
MethodParameterInfo |
asMethodParameter()
Casts and returns this target as a
MethodParameterInfo if it is of kind METHOD_PARAMETER |
RecordComponentInfo |
asRecordComponent()
Casts and returns this target as a
RecordComponentInfo if it is of kind RECORD_COMPONENT |
TypeTarget |
asType()
Casts and returns this target as a
TypeTarget if it is of kind TYPE |
static FieldInfo |
create(ClassInfo clazz,
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.
|
List<AnnotationInstance> |
declaredAnnotations()
Returns the annotation instances declared on this field.
|
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 field
|
int |
enumConstantOrdinal()
Returns an ordinal of this enum constant, that is, the zero-based position in the enum declaration.
|
boolean |
equals(Object o) |
short |
flags()
Returns the access fields of this field.
|
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.
|
String |
name()
Returns the local name of the field
|
String |
toString()
Returns a string representation describing this field.
|
Type |
type()
Returns the
Type declared on this field. |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitannotation, annotation, annotations, annotations, annotationsWithRepeatable, annotationsWithRepeatable, declaredAnnotation, declaredAnnotation, declaredAnnotationsWithRepeatable, declaredAnnotationsWithRepeatable, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotationpublic static FieldInfo create(ClassInfo clazz, String name, Type type, short flags)
clazz - the class declaring the fieldname - the name of the fieldtype - the Java field typeflags - the field attributespublic final String name()
public final ClassInfo declaringClass()
public final Type type()
Type declared on this field. This may be an array, a primitive, or a generic type definition.public final AnnotationTarget.Kind kind()
AnnotationTargetkind in interface AnnotationTargetpublic final boolean hasAnnotation(DotName name)
hasAnnotation in interface AnnotationTargetname - name of the annotation type to look for, must not be nulltrue if the annotation is present, false otherwiseannotation(DotName)public final AnnotationInstance annotation(DotName name)
target() 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.
annotation in interface AnnotationTargetname - name of the annotation type to look for, must not be nullnull if not foundannotations(DotName)public final List<AnnotationInstance> annotations(DotName name)
target() 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;
annotations in interface AnnotationTargetname - name of the annotation type, must not be nullnullannotationsWithRepeatable(DotName, IndexView),
annotations()public final List<AnnotationInstance> annotationsWithRepeatable(DotName name, IndexView index)
target() 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.
annotationsWithRepeatable in interface AnnotationTargetname - name of the annotation type, must not be nullindex - index used to obtain the annotation type, must not be nullnullIllegalArgumentException - if the index is null, if the index does not contain the annotation type
or if name does not identify an annotation typeannotations(DotName),
annotations()public final List<AnnotationInstance> annotations()
target() 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;
annotations in interface AnnotationTargetnullpublic final boolean hasDeclaredAnnotation(DotName name)
Unlike hasAnnotation(DotName), this method ignores annotations declared on
types within the field signature.
hasDeclaredAnnotation in interface AnnotationTargetname - name of the annotation type to look for, must not be nulltrue if the annotation is present, false otherwisehasAnnotation(DotName)public final AnnotationInstance declaredAnnotation(DotName name)
Unlike annotation(DotName), this method doesn't return annotations declared on types
within the field signature.
declaredAnnotation in interface AnnotationTargetname - name of the annotation type to look for, must not be nullnull if not foundannotation(DotName)public final List<AnnotationInstance> declaredAnnotationsWithRepeatable(DotName name, IndexView index)
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.
declaredAnnotationsWithRepeatable in interface AnnotationTargetname - name of the annotation type, must not be nullindex - index used to obtain the annotation type, must not be nullnullIllegalArgumentException - if the index is null, if the index does not contain the annotation type
or if name does not identify an annotation typeannotationsWithRepeatable(DotName, IndexView)public final List<AnnotationInstance> declaredAnnotations()
Unlike annotations(), this method doesn't return annotations declared on types
within the field signature.
declaredAnnotations in interface AnnotationTargetnullannotations()public final boolean isEnumConstant()
Field.isEnumConstant()public final short flags()
Modifier can be used on this value.public final boolean isSynthetic()
true if this field is a synthetic fieldpublic int enumConstantOrdinal()
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.
public String toString()
public final ClassInfo asClass()
AnnotationTargetClassInfo if it is of kind CLASSasClass in interface AnnotationTargetpublic final FieldInfo asField()
AnnotationTargetFieldInfo if it is of kind FIELDasField in interface AnnotationTargetpublic final MethodInfo asMethod()
AnnotationTargetMethodInfo if it is of kind METHODasMethod in interface AnnotationTargetpublic final MethodParameterInfo asMethodParameter()
AnnotationTargetMethodParameterInfo if it is of kind METHOD_PARAMETERasMethodParameter in interface AnnotationTargetpublic final TypeTarget asType()
AnnotationTargetTypeTarget if it is of kind TYPEasType in interface AnnotationTargetpublic final RecordComponentInfo asRecordComponent()
AnnotationTargetRecordComponentInfo if it is of kind RECORD_COMPONENTasRecordComponent in interface AnnotationTargetCopyright © 2018–2022. All rights reserved.