MethodTransformer implements LightClassFileTransformer { @Override public byte[] transform(ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) { if (!filter.allow(classLoader, className)) { return classfileBuffer; } ClassNodeWrapper classNodeWrapper = new ClassNodeWrapper(); ClassReader reader = new ClassReaderWrapper(classfileBuffer); reader.accept(new ClassVisitor(Opcodes.ASM5, classNodeWrapper) { @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions); return new MethodAdapter(access, name, desc, mv, isStatic(access)); } }, ClassReader.EXPAND_FRAMES); if (classNodeWrapper.isInterface()) { return classfileBuffer; } return ASMUtil.toBytes(classNodeWrapper); } MethodTransformer(TraceRegisterBinder traceRegisterBinder, TraceContext traceContext);  MethodTransformer(TraceRegisterBinder traceRegisterBinder,
                             TraceContext traceContext,
                             TraceRepository traceRepository);  MethodTransformer(TraceRegisterBinder traceRegisterBinder,
                             TraceContext traceContext,
                             TraceRepository traceRepository,
                             String ownerClassName,
                             String begin,
                             String beginDescriptor,
                             String end,
                             String endDescriptor);  MethodTransformer(TraceRegisterBinder traceRegisterBinder,
                             TraceContext traceContext,
                             String ownerClassName,
                             String begin,
                             String beginDescriptor,
                             String end,
                             String endDescriptor); @Override byte[] transform(ClassLoader classLoader,
                            String className,
                            Class<?> classBeingRedefined,
                            ProtectionDomain protectionDomain,
                            byte[] classfileBuffer); @Override ClassNodeWrapper transform(ClassLoader classLoader,
                                      Class<?> classBeingRedefined,
                                      byte[] classfileBuffer,
                                      ClassNodeWrapper classNodeWrapper);  }
@Test public void testTransform() throws Exception { String className = TestMethods.class.getName(); byte[] original = TestUtil.load(className); ClassNodeWrapper classNodeWrapper = ASMUtil.parse(original); LightClassFileTransformer transformer = new MethodTransformer(new DefaultTraceRegisterBinder(), new AgentTraceContext(ProfilerConfig.load(getClass().getClassLoader(), "light.conf"))); transformer.transform(getClass().getClassLoader(), null, original, classNodeWrapper); byte[] transform = ASMUtil.toBytes(classNodeWrapper); assertThat(original, not(transform)); TestClassLoader classLoader = new TestClassLoader(getClass().getClassLoader()); Class<?> clazz = classLoader.findClass(className, transform); assertThat(clazz, notNullValue()); assertThat(clazz.getName(), is(className)); Method method = clazz.getMethod("doWithObject", String.class); assertThat((String) method.invoke(clazz.newInstance(), "s"), is("s")); }