Class FieldInfo

All Implemented Interfaces:
HasName, Comparable<FieldInfo>

public class FieldInfo extends ClassMemberInfo implements 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 Details

    • 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 List<Classfile.TypeAnnotationDecorator> typeAnnotationDecorators
      The type annotation decorators for the TypeSignature instance of this field.
  • Constructor Details

    • FieldInfo

      FieldInfo()
      Default constructor for deserialization.
    • FieldInfo

      FieldInfo(String definingClassName, String fieldName, int modifiers, String typeDescriptorStr, String typeSignatureStr, Object constantInitializerValue, AnnotationInfoList annotationInfo, 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 - AnnotationInfo for any annotations on the field.
  • Method Details

    • getModifierStr

      @Deprecated public String getModifierStr()
      Deprecated.
      Use getModifiersStr() instead.
      Deprecated -- use getModifiersStr() instead.
      Returns:
      The field modifiers, as a string.
    • getModifiersStr

      public String getModifiersStr()
      Get the field modifiers as a string, e.g. "public static final". For the modifier bits, call getModifiers().
      Specified by:
      getModifiersStr in class ClassMemberInfo
      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, call getTypeSignature() instead.
      Specified by:
      getTypeDescriptor in class ClassMemberInfo
      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, call getTypeDescriptor() instead.
      Specified by:
      getTypeSignature in class ClassMemberInfo
      Returns:
      The parsed type signature for the field, or null if not available.
      Throws:
      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:
      getTypeSignatureOrTypeDescriptor in class ClassMemberInfo
      Returns:
      The parsed type signature for the field, or if not available, the parsed type descriptor for the field.
    • getConstantInitializerValue

      public Object getConstantInitializerValue()
      Returns the constant initializer value of a field. Requires ClassGraph.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 Field loadClassAndGetField() throws IllegalArgumentException
      Load the class this field is associated with, and get the Field reference for this field.
      Returns:
      The Field reference for this field.
      Throws:
      IllegalArgumentException - if the field does not exist.
    • handleRepeatableAnnotations

      void handleRepeatableAnnotations(Set<String> allRepeatableAnnotationNames)
      Handle Repeatable annotations.
      Parameters:
      allRepeatableAnnotationNames - the names of all repeatable annotations
    • setScanResult

      void setScanResult(ScanResult scanResult)
      Description copied from class: ScanResultObject
      Set ScanResult backreferences in info objects after scan has completed.
      Overrides:
      setScanResult in class ScanResultObject
      Parameters:
      scanResult - the scan result
    • findReferencedClassInfo

      protected void findReferencedClassInfo(Map<String,ClassInfo> classNameToClassInfo, Set<ClassInfo> refdClassInfo, LogNode log)
      Get ClassInfo objects for any classes referenced in the type descriptor or type signature.
      Overrides:
      findReferencedClassInfo in class ScanResultObject
      Parameters:
      classNameToClassInfo - the map from class name to ClassInfo.
      refdClassInfo - the referenced class info
      log - the log
    • equals

      public boolean equals(Object obj)
      Use class name and field name for equals().
      Overrides:
      equals in class 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:
      hashCode in class Object
      Returns:
      the hashcode
    • compareTo

      public int compareTo(FieldInfo other)
      Sort in order of class name then field name.
      Specified by:
      compareTo in interface Comparable<FieldInfo>
      Parameters:
      other - the other FieldInfo object to compare to.
      Returns:
      the result of comparison.
    • toString

      void toString(boolean includeModifiers, boolean useSimpleNames, StringBuilder buf)
    • toString

      protected void toString(boolean useSimpleNames, StringBuilder buf)
      Description copied from class: ScanResultObject
      Render to string.
      Specified by:
      toString in class ScanResultObject
      Parameters:
      useSimpleNames - if true, use just the simple name of each class.
      buf - the buf