private MethodInvoker createMethodInvoker(final Method method) { // We can't use FastMethod if the method is private. int modifiers = method.getModifiers(); if (!Modifier.isPrivate(modifiers) && !Modifier.isProtected(modifiers)) { /*if[AOP]*/ try { final net.sf.cglib.reflect.FastMethod fastMethod = BytecodeGen.newFastClass(method.getDeclaringClass(), Visibility.forMember(method)) .getMethod(method); return new MethodInvoker() { public Object invoke(Object target, Object... parameters) throws IllegalAccessException, InvocationTargetException { return fastMethod.invoke(target, parameters); } }; } catch (net.sf.cglib.core.CodeGenerationException e) {/* fall-through */} /*end[AOP]*/ } if (!Modifier.isPublic(modifiers) || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) { method.setAccessible(true); } return new MethodInvoker() { public Object invoke(Object target, Object... parameters) throws IllegalAccessException, InvocationTargetException { return method.invoke(target, parameters); } }; }
@SuppressWarnings("unchecked") // the constructor promises to construct 'T's ProxyConstructor(Enhancer enhancer, InjectionPoint injectionPoint, Callback[] callbacks, ImmutableMap<Method, List<MethodInterceptor>> methodInterceptors) { this.enhanced = enhancer.createClass(); // this returns a cached class if possible this.injectionPoint = injectionPoint; this.constructor = (Constructor<T>) injectionPoint.getMember(); this.callbacks = callbacks; this.methodInterceptors = methodInterceptors; FastClass fastClass = newFastClass(enhanced, BytecodeGen.Visibility.forMember(constructor)); this.fastConstructor = fastClass.getConstructor(constructor.getParameterTypes()); }
= BytecodeGen.newFastClass(classToConstruct, Visibility.forMember(constructor)) .getConstructor(constructor);