List of usage examples for java.lang.invoke MethodHandle invokeWithArguments
public Object invokeWithArguments(java.util.List<?> arguments) throws Throwable
From source file:org.diorite.config.impl.proxy.ConfigInvocationHandler.java
@Nullable private Object invoke(Config proxy, Method method, Object[] args) throws Throwable { Function<Object[], Object> function = this.basicMethods.get(method); if (function != null) { return function.apply(args); }//from www. j av a 2s .c o m // check for dispatcher: ConfigPropertyActionInstance actionFor = this.template.getActionFor(new MethodSignature(method)); if (actionFor != null) { MethodInvoker methodInvoker = new MethodInvoker(method); ConfigPropertyTemplate<?> templateFor = this.template.getTemplateFor(actionFor); if (templateFor != null) { ConfigPropertyValueImpl<Object> propertyValue = this.getOrCreatePredefinedValue(templateFor); if (methodInvoker.getReturnType() == void.class) { this.registerVoidMethod(method, arg -> actionFor.perform(methodInvoker, propertyValue, arg)); actionFor.perform(methodInvoker, propertyValue, args); return null; } else { this.registerMethod(method, arg -> actionFor.perform(methodInvoker, propertyValue, arg)); return actionFor.perform(methodInvoker, propertyValue, args); } } } // check for default implementation try { MethodHandle methodHandle = DioriteReflectionUtils.createLookup(method.getDeclaringClass(), -1) .unreflectSpecial(method, method.getDeclaringClass()).bindTo(proxy); Object r = methodHandle.invokeWithArguments(args); this.registerMethod(method, (arg) -> { try { return methodHandle.invokeWithArguments(arg); } catch (Throwable throwable) { throw new RuntimeException(throwable); } }); return r; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException( "Config class " + this.template.getConfigType() + " executed unknown method: " + method, e); } }
From source file:org.granitemc.granite.utils.Mappings.java
public static Object invoke(Object object, MethodHandle handle, Object... args) { try {//from w w w. j a v a2 s .c o m return handle.invokeWithArguments(ArrayUtils.add(args, 0, object)); } catch (Throwable throwable) { throwable.printStackTrace(); } return null; }