Package io.github.classgraph
Class FieldInfo
- java.lang.Object
-
- io.github.classgraph.ScanResultObject
-
- io.github.classgraph.ClassMemberInfo
-
- io.github.classgraph.FieldInfo
-
public class FieldInfo extends ClassMemberInfo implements java.lang.Comparable<FieldInfo>
Holds metadata about fields of a class encountered during a scan. All values are taken directly out of the classfile for the class.
-
-
Field Summary
Fields Modifier and Type Field Description private ObjectTypedValueWrapperconstantInitializerValueThe constant initializer value for the field, if any.private java.util.List<Classfile.TypeAnnotationDecorator>typeAnnotationDecoratorsThe type annotation decorators for theTypeSignatureinstance of this field.private TypeSignaturetypeDescriptorThe parsed type descriptor.private TypeSignaturetypeSignatureThe parsed type signature.-
Fields inherited from class io.github.classgraph.ClassMemberInfo
annotationInfo, declaringClassName, modifiers, name, typeDescriptorStr, typeSignatureStr
-
Fields inherited from class io.github.classgraph.ScanResultObject
classRef, scanResult
-
-
Constructor Summary
Constructors Constructor Description FieldInfo()Default constructor for deserialization.FieldInfo(java.lang.String definingClassName, java.lang.String fieldName, int modifiers, java.lang.String typeDescriptorStr, java.lang.String typeSignatureStr, java.lang.Object constantInitializerValue, AnnotationInfoList annotationInfo, java.util.List<Classfile.TypeAnnotationDecorator> typeAnnotationDecorators)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description intcompareTo(FieldInfo other)Sort in order of class name then field name.booleanequals(java.lang.Object obj)Use class name and field name for equals().protected voidfindReferencedClassInfo(java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo, java.util.Set<ClassInfo> refdClassInfo, LogNode log)GetClassInfoobjects for any classes referenced in the type descriptor or type signature.java.lang.ObjectgetConstantInitializerValue()Returns the constant initializer value of a field.java.lang.StringgetModifiersStr()Get the field modifiers as a string, e.g.java.lang.StringgetModifierStr()Deprecated.UsegetModifiersStr()instead.TypeSignaturegetTypeDescriptor()Returns the parsed type descriptor for the field, which will not include type parameters.TypeSignaturegetTypeSignature()Returns the parsed type signature for the field, possibly including type parameters.TypeSignaturegetTypeSignatureOrTypeDescriptor()Returns the type signature for the field, possibly including type parameters.(package private) voidhandleRepeatableAnnotations(java.util.Set<java.lang.String> allRepeatableAnnotationNames)HandleRepeatableannotations.inthashCode()Use hash code of class name and field name.booleanisEnum()Returns true if this field is an enum constant.booleanisTransient()Returns true if this field is a transient field.java.lang.reflect.FieldloadClassAndGetField()Load the class this field is associated with, and get theFieldreference for this field.(package private) voidsetScanResult(ScanResult scanResult)Set ScanResult backreferences in info objects after scan has completed.(package private) voidtoString(boolean includeModifiers, boolean useSimpleNames, java.lang.StringBuilder buf)protected voidtoString(boolean useSimpleNames, java.lang.StringBuilder buf)Render to string.-
Methods inherited from class io.github.classgraph.ClassMemberInfo
getAnnotationInfo, getAnnotationInfo, getAnnotationInfo, getAnnotationInfoRepeatable, getAnnotationInfoRepeatable, getClassInfo, getClassName, getModifiers, getName, getTypeDescriptorStr, getTypeSignatureOrTypeDescriptorStr, getTypeSignatureStr, hasAnnotation, hasAnnotation, isFinal, isPrivate, isProtected, isPublic, isStatic, isSynthetic
-
Methods inherited from class io.github.classgraph.ScanResultObject
findReferencedClassInfo, loadClass, loadClass, loadClass, loadClass, toString, toString, toStringWithSimpleNames
-
-
-
-
Field Detail
-
typeSignature
private transient TypeSignature typeSignature
The parsed type signature.
-
typeDescriptor
private transient TypeSignature typeDescriptor
The parsed type descriptor.
-
constantInitializerValue
private ObjectTypedValueWrapper constantInitializerValue
The constant initializer value for the field, if any.
-
typeAnnotationDecorators
private transient java.util.List<Classfile.TypeAnnotationDecorator> typeAnnotationDecorators
The type annotation decorators for theTypeSignatureinstance of this field.
-
-
Constructor Detail
-
FieldInfo
FieldInfo()
Default constructor for deserialization.
-
FieldInfo
FieldInfo(java.lang.String definingClassName, java.lang.String fieldName, int modifiers, java.lang.String typeDescriptorStr, java.lang.String typeSignatureStr, java.lang.Object constantInitializerValue, AnnotationInfoList annotationInfo, java.util.List<Classfile.TypeAnnotationDecorator> typeAnnotationDecorators)Constructor.- Parameters:
definingClassName- The class the field is defined within.fieldName- The name of the field.modifiers- The field modifiers.typeDescriptorStr- The field type descriptor.typeSignatureStr- The field type signature.constantInitializerValue- The static constant value the field is initialized to, if any.annotationInfo-AnnotationInfofor any annotations on the field.
-
-
Method Detail
-
getModifierStr
@Deprecated public java.lang.String getModifierStr()
Deprecated.UsegetModifiersStr()instead.Deprecated -- usegetModifiersStr()instead.- Returns:
- The field modifiers, as a string.
-
getModifiersStr
public java.lang.String getModifiersStr()
Get the field modifiers as a string, e.g. "public static final". For the modifier bits, call getModifiers().- Specified by:
getModifiersStrin classClassMemberInfo- Returns:
- The field modifiers, as a string.
-
isTransient
public boolean isTransient()
Returns true if this field is a transient field.- Returns:
- True if the field is transient.
-
isEnum
public boolean isEnum()
Returns true if this field is an enum constant.- Returns:
- True if the field is an enum constant.
-
getTypeDescriptor
public TypeSignature getTypeDescriptor()
Returns the parsed type descriptor for the field, which will not include type parameters. If you need generic type parameters, callgetTypeSignature()instead.- Specified by:
getTypeDescriptorin classClassMemberInfo- Returns:
- The parsed type descriptor string for the field.
-
getTypeSignature
public TypeSignature getTypeSignature()
Returns the parsed type signature for the field, possibly including type parameters. If this returns null, indicating that no type signature information is available for this field, callgetTypeDescriptor()instead.- Specified by:
getTypeSignaturein classClassMemberInfo- Returns:
- The parsed type signature for the field, or null if not available.
- Throws:
java.lang.IllegalArgumentException- if the field type signature cannot be parsed (this should only be thrown in the case of classfile corruption, or a compiler bug that causes an invalid type signature to be written to the classfile).
-
getTypeSignatureOrTypeDescriptor
public TypeSignature getTypeSignatureOrTypeDescriptor()
Returns the type signature for the field, possibly including type parameters. If the type signature is null, indicating that no type signature information is available for this field, returns the type descriptor instead.- Specified by:
getTypeSignatureOrTypeDescriptorin classClassMemberInfo- Returns:
- The parsed type signature for the field, or if not available, the parsed type descriptor for the field.
-
getConstantInitializerValue
public java.lang.Object getConstantInitializerValue()
Returns the constant initializer value of a field. RequiresClassGraph.enableStaticFinalFieldConstantInitializerValues()to have been called. Will only return non-null for fields that have constant initializers, which is usually only fields of primitive type, or String constants. Also note that it is up to the compiler as to whether or not a constant-valued field is assigned as a constant in the field definition itself, or whether it is assigned manually in static or non-static class initializer blocks or the constructor -- so your mileage may vary in being able to extract constant initializer values.- Returns:
- The initializer value, if this field has a constant initializer value, or null if none.
-
loadClassAndGetField
public java.lang.reflect.Field loadClassAndGetField() throws java.lang.IllegalArgumentExceptionLoad the class this field is associated with, and get theFieldreference for this field.- Returns:
- The
Fieldreference for this field. - Throws:
java.lang.IllegalArgumentException- if the class can't be loaded or the field does not exist.
-
handleRepeatableAnnotations
void handleRepeatableAnnotations(java.util.Set<java.lang.String> allRepeatableAnnotationNames)
HandleRepeatableannotations.- Parameters:
allRepeatableAnnotationNames- the names of all repeatable annotations
-
setScanResult
void setScanResult(ScanResult scanResult)
Description copied from class:ScanResultObjectSet ScanResult backreferences in info objects after scan has completed.- Overrides:
setScanResultin classScanResultObject- Parameters:
scanResult- the scan result
-
findReferencedClassInfo
protected void findReferencedClassInfo(java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo, java.util.Set<ClassInfo> refdClassInfo, LogNode log)
GetClassInfoobjects for any classes referenced in the type descriptor or type signature.- Overrides:
findReferencedClassInfoin classScanResultObject- Parameters:
classNameToClassInfo- the map from class name toClassInfo.refdClassInfo- the referenced class infolog- the log
-
equals
public boolean equals(java.lang.Object obj)
Use class name and field name for equals().- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object to compare to- Returns:
- true if equal
-
hashCode
public int hashCode()
Use hash code of class name and field name.- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hashcode
-
compareTo
public int compareTo(FieldInfo other)
Sort in order of class name then field name.- Specified by:
compareToin interfacejava.lang.Comparable<FieldInfo>- Parameters:
other- the other FieldInfo object to compare to.- Returns:
- the result of comparison.
-
toString
void toString(boolean includeModifiers, boolean useSimpleNames, java.lang.StringBuilder buf)
-
toString
protected void toString(boolean useSimpleNames, java.lang.StringBuilder buf)Description copied from class:ScanResultObjectRender to string.- Specified by:
toStringin classScanResultObject- Parameters:
useSimpleNames- if true, use just the simple name of each class.buf- the buf
-
-