Package javassist.bytecode
Class FieldInfo
- java.lang.Object
-
- javassist.bytecode.FieldInfo
-
public final class FieldInfo extends java.lang.Object
field_info
structure.The following code adds a public field
width
ofint
type:ClassFile cf = ... FieldInfo f = new FieldInfo(cf.getConstPool(), "width", "I"); f.setAccessFlags(AccessFlag.PUBLIC); cf.addField(f);
- See Also:
CtField.getFieldInfo()
-
-
Field Summary
Fields Modifier and Type Field Description (package private) int
accessFlags
(package private) java.util.List<AttributeInfo>
attribute
(package private) java.lang.String
cachedName
(package private) java.lang.String
cachedType
(package private) ConstPool
constPool
(package private) int
descriptor
(package private) int
name
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAttribute(AttributeInfo info)
Appends an attribute.(package private) void
compact(ConstPool cp)
Copies all constant pool items to a given new constant pool and replaces the original items with the new ones.int
getAccessFlags()
Returns the access flags.AttributeInfo
getAttribute(java.lang.String name)
Returns the attribute with the specified name.java.util.List<AttributeInfo>
getAttributes()
Returns all the attributes.int
getConstantValue()
Finds a ConstantValue attribute and returns the index into theconstant_pool
table.ConstPool
getConstPool()
Returns the constant pool table used by thisfield_info
.java.lang.String
getDescriptor()
Returns the field descriptor.java.lang.String
getName()
Returns the field name.(package private) void
prune(ConstPool cp)
private void
read(java.io.DataInputStream in)
AttributeInfo
removeAttribute(java.lang.String name)
Removes an attribute with the specified name.void
setAccessFlags(int acc)
Sets the access flags.void
setDescriptor(java.lang.String desc)
Sets the field descriptor.void
setName(java.lang.String newName)
Sets the field name.java.lang.String
toString()
Returns a string representation of the object.(package private) void
write(java.io.DataOutputStream out)
-
-
-
Field Detail
-
constPool
ConstPool constPool
-
accessFlags
int accessFlags
-
name
int name
-
cachedName
java.lang.String cachedName
-
cachedType
java.lang.String cachedType
-
descriptor
int descriptor
-
attribute
java.util.List<AttributeInfo> attribute
-
-
Constructor Detail
-
FieldInfo
private FieldInfo(ConstPool cp)
-
FieldInfo
public FieldInfo(ConstPool cp, java.lang.String fieldName, java.lang.String desc)
Constructs afield_info
structure.- Parameters:
cp
- a constant pool tablefieldName
- field namedesc
- field descriptor- See Also:
Descriptor
-
FieldInfo
FieldInfo(ConstPool cp, java.io.DataInputStream in) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
toString
public java.lang.String toString()
Returns a string representation of the object.- Overrides:
toString
in classjava.lang.Object
-
compact
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
- the destination
-
prune
void prune(ConstPool cp)
-
getConstPool
public ConstPool getConstPool()
Returns the constant pool table used by thisfield_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 theconstant_pool
table.- Returns:
- 0 if a ConstantValue attribute is not found.
-
getAttributes
public java.util.List<AttributeInfo> getAttributes()
Returns all the attributes. The returnedList
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
-
getAttribute
public AttributeInfo getAttribute(java.lang.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
orAnnotationsAttribute.invisibleTag
.- Parameters:
name
- attribute name- See Also:
getAttributes()
-
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()
-
read
private void read(java.io.DataInputStream in) throws java.io.IOException
- Throws:
java.io.IOException
-
write
void write(java.io.DataOutputStream out) throws java.io.IOException
- Throws:
java.io.IOException
-
-