public static Object newInstance(Class type) { return newInstance(type, Constants.EMPTY_CLASS_ARRAY, null); }
protected Object firstInstance(Class type) { return ReflectUtils.newInstance(type); }
public static Object newInstance(Class type) { return newInstance(type, Constants.EMPTY_CLASS_ARRAY, null); }
protected Object firstInstance(Class type) { return ReflectUtils.newInstance(type); }
public static Object newInstance(Class type, Class[] parameterTypes, Object[] args) { return newInstance(getConstructor(type, parameterTypes), args); }
/** * Instantiates a proxy instance and assigns callback values. * Implementation detail: java.lang.reflect instances are not cached, so this method should not * be used on a hot path. * This method is used when {@link #setUseCache(boolean)} is set to {@code false}. * @param type class to instantiate * @return newly created instance */ private Object createUsingReflection(Class type) { setThreadCallbacks(type, callbacks); try { if (argumentTypes != null) { return ReflectUtils.newInstance(type, argumentTypes, arguments); } else { return ReflectUtils.newInstance(type); } } finally { // clear thread callbacks to allow them to be gc'd setThreadCallbacks(type, null); } }
/** * Creates proxy instance for given argument types, and assigns the callbacks. * Ideally, for each proxy class, just one set of argument types should be used, * otherwise it would have to spend time on constructor lookup. * Technically, it is a re-implementation of {@link Enhancer#createUsingReflection(Class)}, * with "cache {@link #setThreadCallbacks} and {@link #primaryConstructor}" * @param argumentTypes constructor argument types * @param arguments constructor arguments * @param callbacks callbacks to set for the new instance * @return newly created proxy * @see #createUsingReflection(Class) */ public Object newInstance(Class[] argumentTypes, Object[] arguments, Callback[] callbacks) { setThreadCallbacks(callbacks); try { // Explicit reference equality is added here just in case Arrays.equals does not have one if (primaryConstructorArgTypes == argumentTypes || Arrays.equals(primaryConstructorArgTypes, argumentTypes)) { // If we have relevant Constructor instance at hand, just call it // This skips "get constructors" machinery return ReflectUtils.newInstance(primaryConstructor, arguments); } // Take a slow path if observing unexpected argument types return ReflectUtils.newInstance(generatedClass, argumentTypes, arguments); } finally { // clear thread callbacks to allow them to be gc'd setThreadCallbacks(null); } }
public static Object newInstance(Class type, Class[] parameterTypes, Object[] args) { return newInstance(getConstructor(type, parameterTypes), args); }
/** * Instantiates a proxy instance and assigns callback values. * Implementation detail: java.lang.reflect instances are not cached, so this method should not * be used on a hot path. * This method is used when {@link #setUseCache(boolean)} is set to {@code false}. * @param type class to instantiate * @return newly created instance */ private Object createUsingReflection(Class type) { setThreadCallbacks(type, callbacks); try { if (argumentTypes != null) { return ReflectUtils.newInstance(type, argumentTypes, arguments); } else { return ReflectUtils.newInstance(type); } } finally { // clear thread callbacks to allow them to be gc'd setThreadCallbacks(type, null); } }
/** * Creates proxy instance for given argument types, and assigns the callbacks. * Ideally, for each proxy class, just one set of argument types should be used, * otherwise it would have to spend time on constructor lookup. * Technically, it is a re-implementation of {@link Enhancer#createUsingReflection(Class)}, * with "cache {@link #setThreadCallbacks} and {@link #primaryConstructor}" * @param argumentTypes constructor argument types * @param arguments constructor arguments * @param callbacks callbacks to set for the new instance * @return newly created proxy * @see #createUsingReflection(Class) */ public Object newInstance(Class[] argumentTypes, Object[] arguments, Callback[] callbacks) { setThreadCallbacks(callbacks); try { // Explicit reference equality is added here just in case Arrays.equals does not have one if (primaryConstructorArgTypes == argumentTypes || Arrays.equals(primaryConstructorArgTypes, argumentTypes)) { // If we have relevant Constructor instance at hand, just call it // This skips "get constructors" machinery return ReflectUtils.newInstance(primaryConstructor, arguments); } // Take a slow path if observing unexpected argument types return ReflectUtils.newInstance(generatedClass, argumentTypes, arguments); } finally { // clear thread callbacks to allow them to be gc'd setThreadCallbacks(null); } }
public static Object newInstance(Class type) { return newInstance(type, Constants.EMPTY_CLASS_ARRAY, null); }
protected Object firstInstance(Class type) { return ReflectUtils.newInstance(type); }
@Override protected Object firstInstance(Class type) { return ReflectUtils.newInstance(type); }
protected Object firstInstance(Class type) { return ReflectUtils.newInstance(type); }
/** * 通过监听器类型解析得到事件类型解决器 * * @param clazz 监听器类型 */ public static EventTypeResolver parseEventTypeResolver(Class<? extends ListenerType> clazz) { ListenerType listenerType = (ListenerType) ReflectUtils.newInstance(clazz); return listenerType.getResolver(); }
/** * 通过监听器类型解析得到事件类型解决器 * * @param clazz 监听器类型 */ public static EventTypeResolver parseEventTypeResolver(Class<? extends ListenerType> clazz) { ListenerType listenerType = (ListenerType) ReflectUtils.newInstance(clazz); return listenerType.getResolver(); }
public static Object newInstance(Class type, Class[] parameterTypes, Object[] args) { return newInstance(getConstructor(type, parameterTypes), args); }
private Object newResult(String service) { ServiceExecutor serviceExecutor = servicesHolder.getRequiredServiceExecutor(service); return ReflectUtils.newInstance(serviceExecutor.getResultClass()); }
private Object newResult(String service) { ServiceExecutor serviceExecutor = servicesHolder.getRequiredServiceExecutor(service); return ReflectUtils.newInstance(serviceExecutor.getResultClass()); }
private static ListenExecutor parseListen(Listen listenAnnotation, Method method) { logger.debug("解析监听方法:{}", method); // 校验方法类型 if (!Modifier.isPublic(method.getModifiers())) { throw new IllegalArgumentException("监听方法" + ClassUtils.getQualifiedMethodName(method) + "必须是public类型"); } // 校验返回类型 if (method.getReturnType() != void.class) { throw new IllegalArgumentException("监听方法" + ClassUtils.getQualifiedMethodName(method) + "的返回必须是void"); } // 创建监听解决器 ListenResolver resolver = (ListenResolver) ReflectUtils.newInstance(listenAnnotation.resolver()); resolver.init(method); return new ListenExecutor(resolver, listenAnnotation.priorityAsc(), method); } }