Top Description Fields Constructors Methods
javassist.bytecode

public final Class FieldInfo

extends Object
Class Inheritance
Imports
java.io.DataInputStream, .DataOutputStream, .IOException, java.util.ArrayList, .List

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
javassist.CtField#getFieldInfo()

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv List<AttributeInfo>
pack-priv String
pack-priv String
pack-priv ConstPool
pack-priv int
pack-priv int

Constructor Summary

AccessConstructor and Description
private
public
FieldInfo(ConstPool
a constant pool table
cp
,
String
field name
fieldName
,
String
field descriptor
desc
)

Constructs a field_info structure.

pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
addAttribute(AttributeInfo info)

Appends an attribute.

pack-priv void
compact(ConstPool
the destination
cp
)

Copies all constant pool items to a given new constant pool and replaces the original items with the new ones.

public int
getAccessFlags()

Returns the access flags.

public AttributeInfo
getAttribute(String
attribute name
name
)

Returns the attribute with the specified name.

public List<AttributeInfo>

Returns:

a list of AttributeInfo objects.
getAttributes
()

Returns all the attributes.

public int

Returns:

0 if a ConstantValue attribute is not found.
getConstantValue
()

Finds a ConstantValue attribute and returns the index into the constant_pool table.

public ConstPool
getConstPool()

Returns the constant pool table used by this field_info.

public String
getDescriptor()

Returns the field descriptor.

public String
getName()

Returns the field name.

pack-priv void
private void
public AttributeInfo

Returns:

the removed attribute or null.
removeAttribute
(String
attribute name.
name
)

Removes an attribute with the specified name.

public void
setAccessFlags(int acc)

Sets the access flags.

public void
setDescriptor(String desc)

Sets the field descriptor.

public void
setName(String newName)

Sets the field name.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

accessFlagsback to summary
pack-priv int accessFlags
attributeback to summary
pack-priv List<AttributeInfo> attribute
cachedNameback to summary
pack-priv String cachedName
cachedTypeback to summary
pack-priv String cachedType
constPoolback to summary
pack-priv ConstPool constPool
descriptorback to summary
pack-priv int descriptor
nameback to summary
pack-priv int name

Constructor Detail

FieldInfoback to summary
private FieldInfo(ConstPool cp)
FieldInfoback to summary
public FieldInfo(ConstPool cp, String fieldName, String desc)

Constructs a field_info structure.

Parameters
cp:ConstPool

a constant pool table

fieldName:String

field name

desc:String

field descriptor

See Also
Descriptor
FieldInfoback to summary
pack-priv FieldInfo(ConstPool cp, DataInputStream in) throws IOException

Method Detail

addAttributeback to summary
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()
compactback to summary
pack-priv void compact(ConstPool cp)

Copies all constant pool items to a given new constant pool and replaces the original items with the new ones. This is used for garbage collecting the items of removed fields and methods.

Parameters
cp:ConstPool

the destination

getAccessFlagsback to summary
public int getAccessFlags()

Returns the access flags.

See Also
AccessFlag
getAttributeback to summary
public AttributeInfo getAttribute(String name)

Returns the attribute with the specified name. It returns null if the specified attribute is not found.

An attribute name can be obtained by, for example, AnnotationsAttribute#visibleTag or AnnotationsAttribute#invisibleTag.

Parameters
name:String

attribute name

See Also
getAttributes()
getAttributesback to summary
public 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:List<AttributeInfo>

a list of AttributeInfo objects.

See Also
AttributeInfo
getConstantValueback to summary
public int getConstantValue()

Finds a ConstantValue attribute and returns the index into the constant_pool table.

Returns:int

0 if a ConstantValue attribute is not found.

getConstPoolback to summary
public ConstPool getConstPool()

Returns the constant pool table used by this field_info.

getDescriptorback to summary
public String getDescriptor()

Returns the field descriptor.

See Also
Descriptor
getNameback to summary
public String getName()

Returns the field name.

pruneback to summary
pack-priv void prune(ConstPool cp)
readback to summary
private void read(DataInputStream in) throws IOException
removeAttributeback to summary
public AttributeInfo removeAttribute(String name)

Removes an attribute with the specified name.

Parameters
name:String

attribute name.

Returns:AttributeInfo

the removed attribute or null.

Since
3.21
setAccessFlagsback to summary
public void setAccessFlags(int acc)

Sets the access flags.

See Also
AccessFlag
setDescriptorback to summary
public void setDescriptor(String desc)

Sets the field descriptor.

See Also
Descriptor
setNameback to summary
public void setName(String newName)

Sets the field name.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

Annotations
@Override
writeback to summary
pack-priv void write(DataOutputStream out) throws IOException