Class CBPs
- java.lang.Object
-
- org.zeroturnaround.javarebel.integration.support.CBPs
-
public abstract class CBPs extends Object
This class provides a fluent API for processing classes. It can be used to create two types of processors: direct and delayed. Adirect processortakes aClassPooland aCtClassand performs all the proccessing directly on the givenCtClassinstance. Adelayed processorgathers a bunch of processing commands, and can later execute them all on a givenCtClass. A delayed processor is also aJavassistClassBytecodeProcessor.The
processmethod is used to create a direct processor. Methods likeimplement(Class)andimplement(String)are used to create delayed processors.Here is how one would use a direct processor:
Here is how one could use a delayed processor in a plugin class to implement simple one method interfaces: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));" + "}");integration.addIntegrationProcessor( "com.ibm.ws.jaxws.webcontainer.LibertyJaxWsServlet", CBPs.implement(JrLibertyJaxWsServlet.class) .withMethod("" + "public void setWsEndpointInfo(Object epInfo) {" + " endpoint.setEndpointInfo(epInfo);" + "}"));
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCBPs.DelayedProcessorstatic interfaceCBPs.DirectProcessor
-
Constructor Summary
Constructors Constructor Description CBPs()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CBPs.DelayedProcessorimplement(Class<?> intf)static CBPs.DelayedProcessorimplement(String intfName)static CBPs.DirectProcessorprocess(org.zeroturnaround.bundled.javassist.ClassPool cp, org.zeroturnaround.bundled.javassist.CtClass ctClass)static org.zeroturnaround.bundled.javassist.expr.ExprEditorreplaceMethodCall(String methodName, String src)Creates anExprEditorthat replaces a method call with given source code.
-
-
-
Method Detail
-
implement
public static CBPs.DelayedProcessor implement(String intfName)
-
implement
public static CBPs.DelayedProcessor implement(Class<?> intf)
-
process
public static CBPs.DirectProcessor process(org.zeroturnaround.bundled.javassist.ClassPool cp, org.zeroturnaround.bundled.javassist.CtClass ctClass)
-
replaceMethodCall
public static org.zeroturnaround.bundled.javassist.expr.ExprEditor replaceMethodCall(String methodName, String src)
Creates anExprEditorthat replaces a method call with given source code. Example usage:CBPs.process(cp, ctClass) .instrument("createPersistentAutomaticTimers", CBPs.replaceMethodCall("existsTaskGroup", "$_ = false;"))
-
-