Class FieldInfo


  • public final class FieldInfo
    extends java.lang.Object
    field_info structure.

    The following code adds a public field width of int type:

     ClassFile cf = ...
     FieldInfo f = new FieldInfo(cf.getConstPool(), "width", "I");
     f.setAccessFlags(AccessFlag.PUBLIC);
     cf.addField(f);
     
    See Also:
    CtField.getFieldInfo()
    • Constructor Detail

      • FieldInfo

        public FieldInfo​(ConstPool cp,
                         java.lang.String fieldName,
                         java.lang.String desc)
        Constructs a field_info structure.
        Parameters:
        cp - a constant pool table
        fieldName - field name
        desc - field descriptor
        See Also:
        Descriptor
    • Method Detail

      • toString

        public java.lang.String toString()
        Returns a string representation of the object.
        Overrides:
        toString in class java.lang.Object
      • getConstPool

        public ConstPool getConstPool()
        Returns the constant pool table used by this field_info.
      • getName

        public java.lang.String getName()
        Returns the field name.
      • setName

        public void setName​(java.lang.String newName)
        Sets the field name.
      • getAccessFlags

        public int getAccessFlags()
        Returns the access flags.
        See Also:
        AccessFlag
      • setAccessFlags

        public void setAccessFlags​(int acc)
        Sets the access flags.
        See Also:
        AccessFlag
      • getDescriptor

        public java.lang.String getDescriptor()
        Returns the field descriptor.
        See Also:
        Descriptor
      • setDescriptor

        public void setDescriptor​(java.lang.String desc)
        Sets the field descriptor.
        See Also:
        Descriptor
      • getConstantValue

        public int getConstantValue()
        Finds a ConstantValue attribute and returns the index into the constant_pool table.
        Returns:
        0 if a ConstantValue attribute is not found.
      • getAttributes

        public java.util.List<AttributeInfo> getAttributes()
        Returns all the attributes. The returned List object is shared with this object. If you add a new attribute to the list, the attribute is also added to the field represented by this object. If you remove an attribute from the list, it is also removed from the field.
        Returns:
        a list of AttributeInfo objects.
        See Also:
        AttributeInfo
      • removeAttribute

        public AttributeInfo removeAttribute​(java.lang.String name)
        Removes an attribute with the specified name.
        Parameters:
        name - attribute name.
        Returns:
        the removed attribute or null.
        Since:
        3.21
      • addAttribute

        public void addAttribute​(AttributeInfo info)
        Appends an attribute. If there is already an attribute with the same name, the new one substitutes for it.
        See Also:
        getAttributes()