org.tromer.jie
Class InstrumTransform

java.lang.Object
  |
  +--org.tromer.jie.InstrumTransform

public class InstrumTransform
extends java.lang.Object

This class represents an instrumentation transformation, which is a single application of an instrumentation rule. The transformation may be composed of several code sections, each represented by an InstrumCode instance.

To add pieces of code to this instrumentation, use newCode(). A transformation uses two VisitContext objects:


Inner Class Summary
static interface InstrumTransform.MacroExpansionException
          Thrown when InstrumTransform encounters an invalid action template macro.
 
Field Summary
 java.lang.String macroPrefix
           
 java.lang.String macroSuffix
           
 
Constructor Summary
InstrumTransform(VisitContext transformContext, java.lang.String id, long actionHash)
          Creates a new InstrumTransform instance for a transformation that occurs in the neighbourhood of the specified node and in the specified context.
 
Method Summary
protected  void applyMacroContext()
           
 java.lang.String createHelperMethod(java.lang.String type, java.lang.String args, java.lang.String code)
          Add a uniquely named helper method to the class in which this transformation is carried out.
 java.lang.String createUniqueIdentifier()
          Create a uniquely named identifier.
 void doneCoding()
          Declares the code creation stage to be complete.
static java.lang.String encodeLong(long num)
          Performs a JIID-style base32 encoding of a 'long' value to 13 alphanumeric characters.
protected  java.lang.String expandMacro(java.lang.String macro)
          Expands a single macro, which must be stripped of macro prefix and suffix.
protected  java.lang.String expandMacrosIn(java.lang.String action)
          Expands all macros in the specified string and returns the expanded version.
 java.lang.String getJiid()
          Returns the JIID of this transform.
 java.util.Vector getPieces()
           
 java.lang.String getTransformId()
           
(package private) static long hashTogether(long x, int y)
          Hashes two long values together in a deterministic fashion.
 void instrumentAfterExpressionExec(Node expr, java.lang.String text, java.lang.String exprType)
           
 void instrumentAfterStatement(Node statement, java.lang.String text)
           
 void instrumentBeforeBooleanExpressionExec(Node expr, java.lang.String text)
          Specific to boolean expressions, but does not have the "possibly undefined variables" problems of instrumentBeforeExpressionExec.
 void instrumentBeforeExpressionExec(Node expr, java.lang.String text, java.lang.String exprType)
          May cause problems with "possibly undefined variables" in case the expression uses the assignment operator.
 void instrumentBeforeStatement(Node statement, java.lang.String text)
           
 boolean isKilled()
          True iff kill() was called.
 void kill()
          Remove this transformation.
 InstrumCode newCode(java.lang.String text)
          Adds a piece of code to this transformation.
 void setMacroContext(VisitContext macroContext, java.awt.Point macroPosition)
          Sets the context for macro expansion.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

macroPrefix

public final java.lang.String macroPrefix

macroSuffix

public final java.lang.String macroSuffix
Constructor Detail

InstrumTransform

public InstrumTransform(VisitContext transformContext,
                        java.lang.String id,
                        long actionHash)
Creates a new InstrumTransform instance for a transformation that occurs in the neighbourhood of the specified node and in the specified context.
Parameters:
transformContext - The context where the transformation occurs. This does not affect macro expansion.
actionHash - A hash of the action and opportunity data of the rule.
Method Detail

getPieces

public java.util.Vector getPieces()

getTransformId

public java.lang.String getTransformId()

createUniqueIdentifier

public java.lang.String createUniqueIdentifier()
Create a uniquely named identifier. For a given instance, this function never returns the same value. This value includes the unique transformation hash code, line and column info, and an instance-based serial number.

newCode

public InstrumCode newCode(java.lang.String text)
Adds a piece of code to this transformation. The new code object is returned, and should be attached to a PiggybackableNode to complete the effect. The text can include '${...}'-style macros, which are expanded according go the macro context (not the transform context).

doneCoding

public void doneCoding()
Declares the code creation stage to be complete. This allows the object to release references to some context information. After this call, newCode() may not be called.

kill

public void kill()
Remove this transformation. May be called only after doneCoding().

isKilled

public boolean isKilled()
True iff kill() was called.

getJiid

public java.lang.String getJiid()
Returns the JIID of this transform. Available only after doneCoding and applyMacroContext are called.

createHelperMethod

public java.lang.String createHelperMethod(java.lang.String type,
                                           java.lang.String args,
                                           java.lang.String code)
Add a uniquely named helper method to the class in which this transformation is carried out. The name of the new method is returned. The method will have the specified result type, arguments and code. Each InstrumTransform instance holds a pool of helper method, and if this method is requested again then the name of the existing method will be returned rather than creating a duplicate.

context.classNodeBody must be non-null, meaning we're in an actual class.


instrumentBeforeExpressionExec

public void instrumentBeforeExpressionExec(Node expr,
                                           java.lang.String text,
                                           java.lang.String exprType)
May cause problems with "possibly undefined variables" in case the expression uses the assignment operator.

instrumentBeforeBooleanExpressionExec

public void instrumentBeforeBooleanExpressionExec(Node expr,
                                                  java.lang.String text)
Specific to boolean expressions, but does not have the "possibly undefined variables" problems of instrumentBeforeExpressionExec.

instrumentAfterExpressionExec

public void instrumentAfterExpressionExec(Node expr,
                                          java.lang.String text,
                                          java.lang.String exprType)

instrumentBeforeStatement

public void instrumentBeforeStatement(Node statement,
                                      java.lang.String text)

instrumentAfterStatement

public void instrumentAfterStatement(Node statement,
                                     java.lang.String text)

setMacroContext

public void setMacroContext(VisitContext macroContext,
                            java.awt.Point macroPosition)
Sets the context for macro expansion. Must be called exactly once, either before of after doneCoding().

applyMacroContext

protected void applyMacroContext()

expandMacrosIn

protected java.lang.String expandMacrosIn(java.lang.String action)
Expands all macros in the specified string and returns the expanded version.

expandMacro

protected java.lang.String expandMacro(java.lang.String macro)
Expands a single macro, which must be stripped of macro prefix and suffix.

encodeLong

public static java.lang.String encodeLong(long num)
Performs a JIID-style base32 encoding of a 'long' value to 13 alphanumeric characters.

hashTogether

static long hashTogether(long x,
                         int y)
Hashes two long values together in a deterministic fashion.