Top Description Fields Constructors Methods
javassist.tools

public abstract Class Callback

extends Object
Class Inheritance
Imports
java.util.HashMap, .Map, .UUID, javassist.CannotCompileException, .CtBehavior

Creates bytecode that when executed calls back to the instance's result method.

Example of how to create and insert a callback:

ctMethod.insertAfter(new Callback("Thread.currentThread()") {
    public void result(Object[] objects) {
        Thread thread = (Thread) objects[0];
        // do something with thread...
    }
}.sourceCode());

Contains utility methods for inserts callbacks in CtBehaviour, example:

insertAfter(ctBehaviour, new Callback("Thread.currentThread(), dummyString") {
    public void result(Object[] objects) {
        Thread thread = (Thread) objects[0];
        // do something with thread...
    }
});
Authors
Marten Hedborg, Shigeru Chiba

Field Summary

Modifier and TypeField and Description
public static Map<String, Callback>
private final String

Constructor Summary

AccessConstructor and Description
public
Callback(String
The source code representing the inserted callback bytecode. Can be one or many single statements each returning one object. If many single statements are used they must be comma separated.
src
)

Constructs a new Callback object.

Method Summary

Modifier and TypeMethod and Description
public static void
insertAfter(CtBehavior
The behaviour to insert callback in
behavior
,
Callback
The callback
callback
)

Utility method to inserts callback at the end of the body.

public static void
insertAfter(CtBehavior
The behaviour to insert callback in
behavior
,
Callback
The callback representing the inserted.
callback
,
boolean
True if the inserted is executed Not only when the control normally returns but also when an exception is thrown. If this parameter is true, the inserted code cannot access local variables.
asFinally
)

Utility method to inserts callback at the end of the body.

public static int

Returns:

The line number at which the callback has been inserted.
insertAt
(CtBehavior
The behaviour to insert callback in
behavior
,
Callback
The callback representing.
callback
,
int
The line number. The callback is inserted at the beginning of the code at the line specified by this line number.
lineNum
)

Utility method to inserts callback at the specified line in the body.

public static void
insertBefore(CtBehavior behavior, Callback
The callback
callback
)

Utility method to insert callback at the beginning of the body.

public abstract void
result(Object[]
Objects that the bytecode in callback returns
objects
)

Gets called when bytecode is executed

public String
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

callbacksback to summary
public static Map<String, Callback> callbacks
sourceCodeback to summary
private final String sourceCode

Constructor Detail

Callbackback to summary
public Callback(String src)

Constructs a new Callback object.

Parameters
src:String

The source code representing the inserted callback bytecode. Can be one or many single statements each returning one object. If many single statements are used they must be comma separated.

Method Detail

insertAfterback to summary
public static void insertAfter(CtBehavior behavior, Callback callback) throws CannotCompileException

Utility method to inserts callback at the end of the body. The callback is inserted just before every return instruction. It is not executed when an exception is thrown.

Parameters
behavior:CtBehavior

The behaviour to insert callback in

callback:Callback

The callback

See Also
CtBehavior#insertAfter(String, boolean)
insertAfterback to summary
public static void insertAfter(CtBehavior behavior, Callback callback, boolean asFinally) throws CannotCompileException

Utility method to inserts callback at the end of the body. The callback is inserted just before every return instruction. It is not executed when an exception is thrown.

Parameters
behavior:CtBehavior

The behaviour to insert callback in

callback:Callback

The callback representing the inserted.

asFinally:boolean

True if the inserted is executed Not only when the control normally returns but also when an exception is thrown. If this parameter is true, the inserted code cannot access local variables.

See Also
CtBehavior#insertAfter(String, boolean)
insertAtback to summary
public static int insertAt(CtBehavior behavior, Callback callback, int lineNum) throws CannotCompileException

Utility method to inserts callback at the specified line in the body.

Parameters
behavior:CtBehavior

The behaviour to insert callback in

callback:Callback

The callback representing.

lineNum:int

The line number. The callback is inserted at the beginning of the code at the line specified by this line number.

Returns:int

The line number at which the callback has been inserted.

See Also
CtBehavior#insertAt(int, String)
insertBeforeback to summary
public static void insertBefore(CtBehavior behavior, Callback callback) throws CannotCompileException

Utility method to insert callback at the beginning of the body.

Parameters
callback:Callback

The callback

See Also
CtBehavior#insertBefore(String)
resultback to summary
public abstract void result(Object[] objects)

Gets called when bytecode is executed

Parameters
objects:Object[]

Objects that the bytecode in callback returns

sourceCodeback to summary
public String sourceCode()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override