ByteCodeEventHandlerInfo(ComponentSystem handler, Method method, int priority, String activity, Collection<Class<? extends Component>> filterComponents, Collection<Class<? extends Component>> componentParams) { this.handler = handler; this.activity = activity; this.methodAccess = MethodAccess.get(handler.getClass()); methodIndex = methodAccess.getIndex(method.getName(), method.getParameterTypes()); this.filterComponents = ImmutableList.copyOf(filterComponents); this.componentParams = ImmutableList.copyOf(componentParams); this.priority = priority; }
/** * 构造器 * @param target */ protected ClassBeanWrapper(T target) { this.target = target; this._fields = new HashMap<String, Field>(); for (Field _field : getFields(target.getClass(), true)/*target.getClass().getDeclaredFields()*/) { if (Modifier.isStatic(_field.getModifiers())) { continue; } this._fields.put(_field.getName(), _field); } // this.methodAccess = __methodCache.get(target.getClass()); if (this.methodAccess == null) { this.methodAccess = MethodAccess.get(target.getClass()); __methodCache.put(target.getClass(), this.methodAccess); } }
ByteCodeEventHandlerInfo(ComponentSystem handler, Method method, int priority, String activity, Collection<Class<? extends Component>> filterComponents, Collection<Class<? extends Component>> componentParams) { this.handler = handler; this.activity = activity; this.methodAccess = MethodAccess.get(handler.getClass()); methodIndex = methodAccess.getIndex(method.getName(), method.getParameterTypes()); this.filterComponents = ImmutableList.copyOf(filterComponents); this.componentParams = ImmutableList.copyOf(componentParams); this.priority = priority; }
methodAccess = MethodAccess.get(ownerClass);
ReflectASMFieldAccessor(Class<T> ownerType, Field field, Class<U> fieldType) throws InaccessibleFieldException { methodAccess = MethodAccess.get(ownerType); Method getter = ReflectionUtil.findGetter(field); if (getter != null) { getterIndex = methodAccess.getIndex(getter.getName()); } Method setter = ReflectionUtil.findSetter(field); if (setter != null) { setterIndex = methodAccess.getIndex(setter.getName()); } if (getterIndex == NO_METHOD || setterIndex == NO_METHOD) { fieldAccess = FieldAccess.get(ownerType); try { fieldIndex = fieldAccess.getIndex(field.getName()); } catch (IllegalArgumentException e) { throw new InaccessibleFieldException("Failed to create accessor for field '" + field.getName() + "' of type '" + ownerType.getName() + "'", e); } } }
/** * 初始化providerInvoker */ private Invoker<Object> initProviderInvoker(String key, String className, String methodName, String[] parameterTypeNames, URL url) { Invoker<Object> wrapperInvoker; Invoker<Object> invoker = new RpcProviderInvoker<>(getBeanFunc); Class clazz = ClassUtils.getClassByName(className); invoker.setInterface(clazz); invoker.setUrl(url); //类级别的注解 Provider typeProvider = invoker.getInterface().getAnnotation(Provider.class); setTypeParameters(typeProvider, url.getParameters()); Set<String> excludeFilters = Arrays.stream(typeProvider.excludeFilters()).collect(Collectors.toSet()); //兼容性更好些 Method method = ClassUtils.getMethod(className, methodName, parameterTypeNames); invoker.setMethod(method); //reflectasm更快些(实际上是把反射生成了直接调用的代码) MethodAccess methodAccess = MethodAccess.get(ClassUtils.getClassByName(className)); invoker.setMethodAccess(methodAccess); //方法级别的注解 Provider methodProvider = method.getAnnotation(Provider.class); //方法级别的会覆盖type级别的 if (null != methodProvider) { setMethodParameters(methodProvider, url.getParameters()); } wrapperInvoker = FilterWrapper.ins().buildInvokerChain(invoker, "", Constants.PROVIDER, excludeFilters); invokerMap.putIfAbsent(key, wrapperInvoker); return wrapperInvoker; }
if (asm && !Util.isAndroid && Modifier.isPublic(type.getModifiers())) methodAccess = MethodAccess.get(type);
protected ReflectedActionViewVarDef(Meta meta, Class<?> cls, Method method, App app) { this.cls = cls; this.method = method; if (!meta.isStatic) { methodAccess = MethodAccess.get(cls); methodIndex = methodAccess.getIndex(method.getName(), method.getParameterTypes()); } initLoaders(app); }
protected ReflectedActionViewVarDef(Meta meta, Class<?> cls, Method method, App app) { this.cls = cls; this.method = method; if (!meta.isStatic) { methodAccess = MethodAccess.get(cls); methodIndex = methodAccess.getIndex(method.getName(), method.getParameterTypes()); } initLoaders(app); }
access = MethodAccess.get(type); for (int i = 0, n = properties.length; i < n; i++) { CachedProperty property = properties[i];
access = MethodAccess.get(type); for (int i = 0, n = properties.length; i < n; i++) { CachedProperty property = properties[i];
access = MethodAccess.get(type); for (int i = 0, n = properties.length; i < n; i++) { CachedProperty property = properties[i];
static <T> T invokeObject( final Object instance, final String name, final Object... args) { return Fn.getNull(() -> { final MethodAccess access = MethodAccess.get(instance.getClass()); // Direct invoke, multi overwrite for unbox/box issue still existing. // TODO: Unbox/Box type issue Object result; try { result = access.invoke(instance, name, args); } catch (final Throwable ex) { ex.printStackTrace(); // Could not call, re-find the method by index // Search method by argument index because could not call directly final int index; final List<Class<?>> types = new ArrayList<>(); for (final Object arg : args) { types.add(Ut.toPrimary(arg.getClass())); } index = access.getIndex(name, types.toArray(new Class<?>[]{})); result = access.invoke(instance, index, args); } final Object ret = result; return Fn.getNull(() -> (T) ret, ret); }, instance, name); }
static <T> T invokeObject( final Object instance, final String name, final Object... args) { return Fn.getNull(() -> { final MethodAccess access = MethodAccess.get(instance.getClass()); // Direct invoke, multi overwrite for unbox/box issue still existing. // TODO: Unbox/Box type issue Object result; try { result = access.invoke(instance, name, args); } catch (final Throwable ex) { ex.printStackTrace(); // Could not call, re-find the method by index // Search method by argument index because could not call directly final int index; final List<Class<?>> types = new ArrayList<>(); for (final Object arg : args) { types.add(Ut.toPrimary(arg.getClass())); } index = access.getIndex(name, types.toArray(new Class<?>[]{})); result = access.invoke(instance, index, args); } final Object ret = result; return Fn.getNull(() -> (T) ret, ret); }, instance, name); }
Class[] paramTypes = paramTypes(); methodAccess = MethodAccess.get(jobClass); methodIndex = methodAccess.getIndex(methodInfo.name(), paramTypes); } else {
Class[] paramTypes = paramTypes(); methodAccess = MethodAccess.get(jobClass); methodIndex = methodAccess.getIndex(methodInfo.name(), paramTypes); } else {
if (!this.isStatic) { methodAccess = MethodAccess.get(handlerClass); methodIndex = methodAccess.getIndex(methodInfo.name(), paramTypes); host = Act.getInstance(handlerClass);
methodAccess = MethodAccess.get(commanderClass); commandIndex = methodAccess.getIndex(methodMetaInfo.methodName(), paramTypes); } else {
MethodAccess ma = MethodAccess.get(rpcInterface); int methodIndex = ma.getIndex(methodName, paramTypes); Object returnObject = ma.invoke(rpcObject, methodIndex, params);
methodAccess = MethodAccess.get(commanderClass); commandIndex = methodAccess.getIndex(methodMetaInfo.methodName(), paramTypes); } else {