public abstract class CBPs extends Object
direct processor takes a ClassPool and a CtClass and performs all
the proccessing directly on the given CtClass instance. A delayed processor gathers
a bunch of processing commands, and can later execute them all on a given CtClass. A delayed processor is
also a JavassistClassBytecodeProcessor.
The process method is used to create a direct processor. Methods like implement(Class) and implement(String) are used to create delayed processors.
Here is how one would use a direct processor:
CBPs.process(cp, ctClass)
.importPackage("org.zeroturnaround.javarebel")
.importPackage("org.zeroturnaround.javarebel.integration.util")
.addInterface(ClassEventListener.class)
.addLoggerField("jrLog", "MyPlugin")
.addMethod("" +
"public void onClassEvent(int eventType, Class klass) {" +
" jrLog.info(\"Class reload event received for \" + klass);" +
"}")
.addMethod("" +
"public int priority() {" +
" return PRIORITY_DEFAULT;" +
"}")
.insertAfterLeafCtors("{" +
" ReloaderFactory.getInstance().addClassReloadListener(WeakUtil.weakCEL(this));" +
"}");
Here is how one could use a delayed processor in a plugin class to implement simple one method interfaces:
integration.addIntegrationProcessor(
"com.ibm.ws.jaxws.webcontainer.LibertyJaxWsServlet",
CBPs.implement(JrLibertyJaxWsServlet.class)
.withMethod("" +
"public void setWsEndpointInfo(Object epInfo) {" +
" endpoint.setEndpointInfo(epInfo);" +
"}"));
| Modifier and Type | Class and Description |
|---|---|
static class |
CBPs.DelayedProcessor |
static interface |
CBPs.DirectProcessor |
| Constructor and Description |
|---|
CBPs() |
| Modifier and Type | Method and Description |
|---|---|
static CBPs.DelayedProcessor |
implement(Class intf) |
static CBPs.DelayedProcessor |
implement(String intfName) |
static CBPs.DirectProcessor |
process(org.zeroturnaround.bundled.javassist.ClassPool cp,
org.zeroturnaround.bundled.javassist.CtClass ctClass) |
static org.zeroturnaround.bundled.javassist.expr.ExprEditor |
replaceMethodCall(String methodName,
String src)
Creates an
ExprEditor that replaces a method call with given source code. |
public static CBPs.DelayedProcessor implement(String intfName)
public static CBPs.DelayedProcessor implement(Class intf)
public static CBPs.DirectProcessor process(org.zeroturnaround.bundled.javassist.ClassPool cp, org.zeroturnaround.bundled.javassist.CtClass ctClass)
public static org.zeroturnaround.bundled.javassist.expr.ExprEditor replaceMethodCall(String methodName, String src)
ExprEditor that replaces a method call with given source code. Example usage:
CBPs.process(cp, ctClass)
.instrument("createPersistentAutomaticTimers",
CBPs.replaceMethodCall("existsTaskGroup", "$_ = false;"))
Copyright © 2016. All rights reserved.