public abstract class Callback
extends java.lang.Object
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... } });
Modifier and Type | Field and Description |
---|---|
static java.util.HashMap<java.lang.String,Callback> |
callbacks |
Constructor and Description |
---|
Callback(java.lang.String src)
Constructs a new
Callback object. |
Modifier and Type | Method and Description |
---|---|
static void |
insertAfter(CtBehavior behavior,
Callback callback)
Utility method to inserts callback at the end of the body.
|
static void |
insertAfter(CtBehavior behavior,
Callback callback,
boolean asFinally)
Utility method to inserts callback at the end of the body.
|
static int |
insertAt(CtBehavior behavior,
Callback callback,
int lineNum)
Utility method to inserts callback at the specified line in the body.
|
static void |
insertBefore(CtBehavior behavior,
Callback callback)
Utility method to insert callback at the beginning of the body.
|
abstract void |
result(java.lang.Object... objects)
Gets called when bytecode is executed
|
java.lang.String |
sourceCode() |
java.lang.String |
toString() |
public static java.util.HashMap<java.lang.String,Callback> callbacks
public Callback(java.lang.String src)
Callback
object.src
- 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.public abstract void result(java.lang.Object... objects)
objects
- Objects that the bytecode in callback returnspublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String sourceCode()
public static void insertBefore(CtBehavior behavior, Callback callback) throws CannotCompileException
callback
- The callbackCannotCompileException
CtBehavior.insertBefore(String)
public static void insertAfter(CtBehavior behavior, Callback callback) throws CannotCompileException
behavior
- The behaviour to insert callback incallback
- The callbackCannotCompileException
CtBehavior.insertAfter(String, boolean)
public static void insertAfter(CtBehavior behavior, Callback callback, boolean asFinally) throws CannotCompileException
behavior
- The behaviour to insert callback incallback
- The callback representing the inserted.asFinally
- 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.CannotCompileException
CtBehavior.insertAfter(String, boolean)
public static int insertAt(CtBehavior behavior, Callback callback, int lineNum) throws CannotCompileException
behavior
- The behaviour to insert callback incallback
- The callback representing.lineNum
- The line number. The callback is inserted at the
beginning of the code at the line specified by this
line number.CannotCompileException
CtBehavior.insertAt(int, String)
Javassist, a Java-bytecode translator toolkit.
Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.