TechTrader Bytecode Toolkit

com.techtrader.modules.tools.bytecode
Class BCEntity

java.lang.Object
  |
  +--com.techtrader.modules.tools.bytecode.BCEntity
Direct Known Subclasses:
Attribute, BCClass, BCField, BCMethod

public abstract class BCEntity
extends Object
implements VisitAcceptor

Abstract superclass for all complex bytecode entities. All bytecode entities contain attributes and are able to access the constant pool.

Author:
Abe White

Constructor Summary
BCEntity()
           
 
Method Summary
 Attribute addAttribute(String name)
          Add an attribute of the given type.
 void clearAttributes()
          Clear all attributes from this entity.
 Attribute getAttribute(String name)
          Return the attribute with the given name.
 Attribute[] getAttributes()
          Get all the attributes owned by this entity.
 Attribute[] getAttributes(String name)
          Returns all attributes with the given name.
abstract  ConstantPool getPool()
          Return the constant pool for the current class.
 Attribute importAttribute(Attribute attr)
          Import an attribute from another entity, or make a copy of one on this entity.
 void importAttributes(BCEntity other)
          Import all attributes from another entity.
protected  void readAttributes(DataInput in)
          Clears the attribute list and rebuilds it from the given stream.
 boolean removeAttribute(Attribute attribute)
          Remove the given attribute.
 boolean removeAttribute(String name)
          Remove all attributes with the given name from the list.
 void visitAttributes(BCVisitor visit)
          Convenience method to be called by BCEntities when being visited by a BCVisitor; this method will allow the visitor to visit all attributes of this entity.
protected  void writeAttributes(DataOutput out)
          Writes all the owned attributes to the given stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BCEntity

public BCEntity()
Method Detail

getPool

public abstract ConstantPool getPool()
Return the constant pool for the current class.

getAttributes

public Attribute[] getAttributes()
Get all the attributes owned by this entity.
Returns:
all owned attributes, or empty array if none

getAttribute

public Attribute getAttribute(String name)
Return the attribute with the given name. If multiple attributes share the name, which is returned is undefined.

getAttributes

public Attribute[] getAttributes(String name)
Returns all attributes with the given name.
Returns:
the matching attributes, or empty array if none

importAttribute

public Attribute importAttribute(Attribute attr)
Import an attribute from another entity, or make a copy of one on this entity.

importAttributes

public void importAttributes(BCEntity other)
Import all attributes from another entity.

addAttribute

public Attribute addAttribute(String name)
Add an attribute of the given type.

clearAttributes

public void clearAttributes()
Clear all attributes from this entity.

removeAttribute

public boolean removeAttribute(String name)
Remove all attributes with the given name from the list.
Returns:
true if an attribute was removed, false otherwise

removeAttribute

public boolean removeAttribute(Attribute attribute)
Remove the given attribute. After being removed, the given Attribute is invalid, and the result of any operations on it are undefined.
Returns:
true if the attribute was removed, false otherwise

readAttributes

protected void readAttributes(DataInput in)
                       throws IOException
Clears the attribute list and rebuilds it from the given stream. Relies on the ability of attributes to read themselves, and requires access to the constant pool, which must already by read.

writeAttributes

protected void writeAttributes(DataOutput out)
                        throws IOException
Writes all the owned attributes to the given stream. Relies on the ability of attributes to write themselves.

visitAttributes

public void visitAttributes(BCVisitor visit)
Convenience method to be called by BCEntities when being visited by a BCVisitor; this method will allow the visitor to visit all attributes of this entity.

TechTrader Bytecode Toolkit