harpoon.ClassFile
Class HCode<HCE extends HCodeElement>

java.lang.Object
  extended by harpoon.ClassFile.HCode<HCE>
Direct Known Subclasses:
Code, Code, Code, Code

public abstract class HCode<HCE extends HCodeElement>
extends Object

HCode is an abstract class that all views of a particular method's executable code should extend.

An HCode corresponds roughly to a "list of instructions".

Version:
$Id: HCode.java,v 1.18 2004/02/08 01:58:03 cananian Exp $
Author:
C. Scott Ananian <cananian@alumni.princeton.edu>
See Also:
HMethod, HCodeElement, Code, Instr

Nested Class Summary
static class HCode.PrintCallback<HCE extends HCodeElement>
          Callback interface for annotating pretty-prints of HCodes.
 
Constructor Summary
HCode()
           
 
Method Summary
 HCode<HCE> clone()
          Clone this HCode and all associated HCodeElements.
 HCodeAndMaps<HCE> clone(HMethod newMethod)
          Clone this HCode, possibly moving it to a different method.
abstract  ArrayFactory<HCE> elementArrayFactory()
          Return an ArrayFactory for the HCodeElements composing this HCode.
 Indexer elementIndexer()
          Return an Indexer for the HCodeElements composing this HCode.
 HCE[] getElements()
          Deprecated. use getElementsL() instead.
 Iterator<HCE> getElementsI()
          Return an Iterator over the component objects making up this code view.
 List<HCE> getElementsL()
          Return an ordered Collection (a List) of the component objects making up this code view.
 HCE[] getLeafElements()
          Return the 'leaves' of this code view; that is, the elements with no successors.
abstract  HMethod getMethod()
          Return the HMethod to which this HCode belongs.
abstract  String getName()
          Return the name of this code view.
 HCE getRootElement()
          Return the 'root' element of this code view.
 void print(PrintWriter pw)
          Pretty-print this code view using an empty callback.
 void print(PrintWriter pw, HCode.PrintCallback<HCE> callback)
          Pretty-print this code view using the specified callback.
 String toString()
          Returns a human-readable representation of this HCode.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HCode

public HCode()
Method Detail

getMethod

public abstract HMethod getMethod()
Return the HMethod to which this HCode belongs.


getName

public abstract String getName()
Return the name of this code view. The default bytecode view is named "bytecode". It is suggested that additional views be named in a similarly human-friendly fashion.


getElements

public HCE[] getElements()
Deprecated. use getElementsL() instead.

Return an ordered list of the component objects making up this code view. If there is a 'root' to the code view, it should occupy index 0 of the HCodeElement array.

See Also:
Instr

getElementsL

public List<HCE> getElementsL()
Return an ordered Collection (a List) of the component objects making up this code view. If there is a 'root' to the code view, it should be the first element in the List. Note that the object returned need not be static; i.e. the contents of the List may (or may not) change as the underlying representation is modified. If you need a static view, see SnapshotIterator; if you need a dynamic view, don't cache the returned List.

The getElementsI() method must have been implemented for the default implementation to work properly.


getElementsI

public Iterator<HCE> getElementsI()
Return an Iterator over the component objects making up this code view. If there is a 'root' to the code view, it should be the first element enumerated.

Subclasses must override the default implementation of at least one of getElementsL() or getElementsI() in order to work properly.


getRootElement

public HCE getRootElement()
Return the 'root' element of this code view.

Returns:
root of the code view, or null if this notion is not applicable.

getLeafElements

public HCE[] getLeafElements()
Return the 'leaves' of this code view; that is, the elements with no successors.

Returns:
leaves of the code view, or null if this notion is not applicable.

elementArrayFactory

public abstract ArrayFactory<HCE> elementArrayFactory()
Return an ArrayFactory for the HCodeElements composing this HCode.


elementIndexer

public Indexer elementIndexer()
Return an Indexer for the HCodeElements composing this HCode. The default Indexer returned does not implement Indexer.getByID().


clone

public HCodeAndMaps<HCE> clone(HMethod newMethod)
                                             throws CloneNotSupportedException
Clone this HCode, possibly moving it to a different method. Throws CloneNotSupportedException if not overridden.

Throws:
CloneNotSupportedException - if it is not possible to clone this HCode.

clone

public HCode<HCE> clone()
                                      throws CloneNotSupportedException
Clone this HCode and all associated HCodeElements. Calls clone(getMethod()).

Overrides:
clone in class Object
Throws:
CloneNotSupportedException

print

public final void print(PrintWriter pw)
Pretty-print this code view using an empty callback.


print

public void print(PrintWriter pw,
                  HCode.PrintCallback<HCE> callback)
Pretty-print this code view using the specified callback.


toString

public String toString()
Returns a human-readable representation of this HCode.

Overrides:
toString in class Object