Java 类net.sf.cglib.proxy.FixedValue 实例源码

项目:byte-buddy    文件:ClassByImplementationBenchmark.java   
/**
 * Performs a benchmark of an interface implementation using cglib.
 *
 * @return The created instance, in order to avoid JIT removal.
 */
@Benchmark
public ExampleInterface benchmarkCglib() {
    Enhancer enhancer = new Enhancer();
    enhancer.setUseCache(false);
    enhancer.setClassLoader(newClassLoader());
    enhancer.setSuperclass(baseClass);
    CallbackHelper callbackHelper = new CallbackHelper(Object.class, new Class[]{baseClass}) {
        @Override
        protected Object getCallback(Method method) {
            if (method.getDeclaringClass() == baseClass) {
                return new FixedValue() {
                    @Override
                    public Object loadObject() throws Exception {
                        return null;
                    }
                };
            } else {
                return NoOp.INSTANCE;
            }
        }
    };
    enhancer.setCallbackFilter(callbackHelper);
    enhancer.setCallbacks(callbackHelper.getCallbacks());
    return (ExampleInterface) enhancer.create();
}
项目:reflection-util    文件:ClassUtilsTest.java   
private static <T> T createCglibProxy(T object) {
    Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(object.getClass());
    enhancer.setCallback((FixedValue) () -> null);
    @SuppressWarnings("unchecked")
    T proxy = (T) enhancer.create();
    return proxy;
}
项目:graphql-spqr    文件:ProxyDetectionTest.java   
@Test
public void testCglibProxy() {
    Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(Person.class);
    enhancer.setCallback((FixedValue) () -> null);
    Person proxyObject = (Person) enhancer.create();
    assertTrue(ClassUtils.isProxy(proxyObject.getClass()));
}