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; }
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; }
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); } } }
try { AsmCachedMethod asmCachedMethod = new AsmCachedMethod(); asmCachedMethod.methodAccessIndex = ((MethodAccess)methodAccess).getIndex(method.getName(), parameterTypes); asmCachedMethod.methodAccess = (MethodAccess)methodAccess; cachedMethod = asmCachedMethod;
/** Invokes the method with the specified name and the specified param types. */ public Object invoke (Object object, String methodName, Class[] paramTypes, Object... args) { return invoke(object, getIndex(methodName, paramTypes), args); }
/** Invokes the first method with the specified name and the specified number of arguments. */ public Object invoke (Object object, String methodName, Object... args) { return invoke(object, getIndex(methodName, args == null ? 0 : args.length), args); }
/** * Invokes the first method with the specified name. */ public Object invoke (Object object, String methodName, Object... args) { return invoke(object, getIndex(methodName), args); }
/** Invokes the first method with the specified name and the specified number of arguments. */ public Object invoke (Object object, String methodName, Object... args) { return invoke(object, getIndex(methodName, args == null ? 0 : args.length), args); }
/** Invokes the method with the specified name and the specified param types. */ public Object invoke (Object object, String methodName, Class[] paramTypes, Object... args) { return invoke(object, getIndex(methodName, paramTypes), args); }
/** Invokes the first method with the specified name and the specified number of arguments. */ public Object invoke (Object object, String methodName, Object... args) { return invoke(object, getIndex(methodName, args == null ? 0 : args.length), args); }
/** Invokes the method with the specified name and the specified param types. */ public Object invoke (Object object, String methodName, Class[] paramTypes, Object... args) { return invoke(object, getIndex(methodName, paramTypes), args); }
/** Invokes the first method with the specified name and the specified number of arguments. */ public Object invoke (Object object, String methodName, Object... args) { return invoke(object, getIndex(methodName, args == null ? 0 : args.length), args); }
/** Invokes the method with the specified name and the specified param types. */ public Object invoke (Object object, String methodName, Class[] paramTypes, Object... args) { return invoke(object, getIndex(methodName, paramTypes), args); }
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); }
/** * Builds the method sorted cache. Sorts the methods alphabetically by name. */ private static void buildMethodCache(Class<?> clazz, MethodAccess methodAccess) { if(!_methodSortCache.containsKey(clazz)) { LogCache[] sortedLogCache = new LogCache[methodAccess.getMethodNames().length]; String[] sortedMethodNames = Arrays.copyOf(methodAccess.getMethodNames(), sortedLogCache.length); Arrays.sort(sortedMethodNames); for(int i = 0; i < sortedLogCache.length; i++) { sortedLogCache[i] = new LogCache(methodAccess.getIndex(sortedMethodNames[i]), getMethodLogScope(clazz, sortedMethodNames[i])); } _methodSortCache.put(clazz, sortedLogCache); } }
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); }
methodIndex = methodAccess.getIndex(methodInfo.name(), paramTypes); } else { method.setAccessible(true);
int methodIndex = ma.getIndex(methodName, paramTypes); Object returnObject = ma.invoke(rpcObject, methodIndex, params); return RpcMessages.newRsponseRpcMessage(req.getId(), returnObject);