本文整理了Java中java.lang.invoke.MethodHandle.isVarargsCollector()
方法的一些代码示例,展示了MethodHandle.isVarargsCollector()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MethodHandle.isVarargsCollector()
方法的具体详情如下:
包路径:java.lang.invoke.MethodHandle
类名称:MethodHandle
方法名:isVarargsCollector
[英]Determines if this method handle supports #asVarargsCollector calls. Such method handles arise from the following sources:
代码示例来源:origin: prestodb/presto
public Procedure(String schema, String name, List<Argument> arguments, MethodHandle methodHandle)
{
this.schema = checkNotNullOrEmpty(schema, "schema").toLowerCase(ENGLISH);
this.name = checkNotNullOrEmpty(name, "name").toLowerCase(ENGLISH);
this.arguments = unmodifiableList(new ArrayList<>(arguments));
this.methodHandle = requireNonNull(methodHandle, "methodHandle is null");
Set<String> names = new HashSet<>();
for (Argument argument : arguments) {
checkArgument(names.add(argument.getName()), "Duplicate argument name: " + argument.getName());
}
checkArgument(!methodHandle.isVarargsCollector(), "Method must have fixed arity");
checkArgument(methodHandle.type().returnType() == void.class, "Method must return void");
long parameterCount = methodHandle.type().parameterList().stream()
.filter(type -> !ConnectorSession.class.isAssignableFrom(type))
.count();
checkArgument(parameterCount == arguments.size(), "Method parameter count must match arguments");
}
代码示例来源:origin: prestodb/presto
public Procedure(String schema, String name, List<Argument> arguments, MethodHandle methodHandle)
{
this.schema = checkNotNullOrEmpty(schema, "schema").toLowerCase(ENGLISH);
this.name = checkNotNullOrEmpty(name, "name").toLowerCase(ENGLISH);
this.arguments = unmodifiableList(new ArrayList<>(arguments));
this.methodHandle = requireNonNull(methodHandle, "methodHandle is null");
Set<String> names = new HashSet<>();
for (Argument argument : arguments) {
checkArgument(names.add(argument.getName()), "Duplicate argument name: " + argument.getName());
}
checkArgument(!methodHandle.isVarargsCollector(), "Method must have fixed arity");
checkArgument(methodHandle.type().returnType() == void.class, "Method must return void");
long parameterCount = methodHandle.type().parameterList().stream()
.filter(type -> !ConnectorSession.class.isAssignableFrom(type))
.count();
checkArgument(parameterCount == arguments.size(), "Method parameter count must match arguments");
}
代码示例来源:origin: szegedi/dynalink
@Override
boolean isVarArgs() {
return target.isVarargsCollector();
}
代码示例来源:origin: org.dynalang/dynalink
@Override
boolean isVarArgs() {
return target.isVarargsCollector();
}
代码示例来源:origin: eclipse/golo-lang
public boolean isVarargsCollector() {
return handle.isVarargsCollector();
}
代码示例来源:origin: eclipse/golo-lang
@Override
public String toString() {
return String.format("FunctionReference{handle=%s%s, parameterNames=%s}",
handle.isVarargsCollector() ? "(varargs)" : "",
handle,
Arrays.toString(parameterNames));
}
代码示例来源:origin: org.dynalang/dynalink
private static void appendSig(StringBuilder b, MethodHandle m) {
b.append('(');
appendTypes(b, m.type().parameterArray(), m.isVarargsCollector());
b.append(')');
}
代码示例来源:origin: szegedi/dynalink
private static void appendSig(final StringBuilder b, final MethodHandle m) {
b.append('(');
appendTypes(b, m.type().parameterArray(), m.isVarargsCollector());
b.append(')');
}
代码示例来源:origin: szegedi/dynalink
@SuppressWarnings("unused")
private void throwAmbiguousMethod(final Class<?>[] argTypes, final List<MethodHandle> methods) throws NoSuchMethodException {
final String arity = methods.get(0).isVarargsCollector() ? "variable" : "fixed";
throw new NoSuchMethodException("Can't unambiguously select between " + arity + " arity signatures " +
getSignatureList(methods) + " of the method " + parent.getName() + " for argument types " +
argTypesString(argTypes));
}
代码示例来源:origin: org.dynalang/dynalink
@SuppressWarnings("unused")
private void throwAmbiguousMethod(Class<?>[] argTypes, List<MethodHandle> methods) throws NoSuchMethodException {
final String arity = methods.get(0).isVarargsCollector() ? "variable" : "fixed";
throw new NoSuchMethodException("Can't unambiguously select between " + arity + " arity signatures " +
getSignatureList(methods) + " of the method " + parent.getName() + " for argument types " +
argTypesString(argTypes));
}
代码示例来源:origin: org.dynalang/dynalink
private static MethodHandle dropReceiver(final MethodHandle mh, final Class<?> receiverClass) {
MethodHandle newHandle = MethodHandles.dropArguments(mh, 0, receiverClass);
// NOTE: this is a workaround for the fact that dropArguments doesn't preserve vararg collector state.
if(mh.isVarargsCollector() && !newHandle.isVarargsCollector()) {
final MethodType type = mh.type();
newHandle = newHandle.asVarargsCollector(type.parameterType(type.parameterCount() - 1));
}
return newHandle;
}
}
代码示例来源:origin: szegedi/dynalink
private static MethodHandle dropReceiver(final MethodHandle mh, final Class<?> receiverClass) {
MethodHandle newHandle = MethodHandles.dropArguments(mh, 0, receiverClass);
// NOTE: this is a workaround for the fact that dropArguments doesn't preserve vararg collector state.
if(mh.isVarargsCollector() && !newHandle.isVarargsCollector()) {
final MethodType type = mh.type();
newHandle = newHandle.asVarargsCollector(type.parameterType(type.parameterCount() - 1));
}
return newHandle;
}
}
代码示例来源:origin: com.facebook.presto/presto-spi
public Procedure(String schema, String name, List<Argument> arguments, MethodHandle methodHandle)
{
this.schema = checkNotNullOrEmpty(schema, "schema").toLowerCase(ENGLISH);
this.name = checkNotNullOrEmpty(name, "name").toLowerCase(ENGLISH);
this.arguments = unmodifiableList(new ArrayList<>(arguments));
this.methodHandle = requireNonNull(methodHandle, "methodHandle is null");
Set<String> names = new HashSet<>();
for (Argument argument : arguments) {
checkArgument(names.add(argument.getName()), "Duplicate argument name: " + argument.getName());
}
checkArgument(!methodHandle.isVarargsCollector(), "Method must have fixed arity");
checkArgument(methodHandle.type().returnType() == void.class, "Method must return void");
long parameterCount = methodHandle.type().parameterList().stream()
.filter(type -> !ConnectorSession.class.isAssignableFrom(type))
.count();
checkArgument(parameterCount == arguments.size(), "Method parameter count must match arguments");
}
代码示例来源:origin: com.facebook.presto/presto-jdbc
public Procedure(String schema, String name, List<Argument> arguments, MethodHandle methodHandle)
{
this.schema = checkNotNullOrEmpty(schema, "schema").toLowerCase(ENGLISH);
this.name = checkNotNullOrEmpty(name, "name").toLowerCase(ENGLISH);
this.arguments = unmodifiableList(new ArrayList<>(arguments));
this.methodHandle = requireNonNull(methodHandle, "methodHandle is null");
Set<String> names = new HashSet<>();
for (Argument argument : arguments) {
checkArgument(names.add(argument.getName()), "Duplicate argument name: " + argument.getName());
}
checkArgument(!methodHandle.isVarargsCollector(), "Method must have fixed arity");
checkArgument(methodHandle.type().returnType() == void.class, "Method must return void");
long parameterCount = methodHandle.type().parameterList().stream()
.filter(type -> !ConnectorSession.class.isAssignableFrom(type))
.count();
checkArgument(parameterCount == arguments.size(), "Method parameter count must match arguments");
}
代码示例来源:origin: prestosql/presto
public Procedure(String schema, String name, List<Argument> arguments, MethodHandle methodHandle)
{
this.schema = checkNotNullOrEmpty(schema, "schema").toLowerCase(ENGLISH);
this.name = checkNotNullOrEmpty(name, "name").toLowerCase(ENGLISH);
this.arguments = unmodifiableList(new ArrayList<>(arguments));
this.methodHandle = requireNonNull(methodHandle, "methodHandle is null");
Set<String> names = new HashSet<>();
for (Argument argument : arguments) {
checkArgument(names.add(argument.getName()), "Duplicate argument name: " + argument.getName());
}
checkArgument(!methodHandle.isVarargsCollector(), "Method must have fixed arity");
checkArgument(methodHandle.type().returnType() == void.class, "Method must return void");
long parameterCount = methodHandle.type().parameterList().stream()
.filter(type -> !ConnectorSession.class.isAssignableFrom(type))
.count();
checkArgument(parameterCount == arguments.size(), "Method parameter count must match arguments");
}
代码示例来源:origin: io.prestosql/presto-jdbc
public Procedure(String schema, String name, List<Argument> arguments, MethodHandle methodHandle)
{
this.schema = checkNotNullOrEmpty(schema, "schema").toLowerCase(ENGLISH);
this.name = checkNotNullOrEmpty(name, "name").toLowerCase(ENGLISH);
this.arguments = unmodifiableList(new ArrayList<>(arguments));
this.methodHandle = requireNonNull(methodHandle, "methodHandle is null");
Set<String> names = new HashSet<>();
for (Argument argument : arguments) {
checkArgument(names.add(argument.getName()), "Duplicate argument name: " + argument.getName());
}
checkArgument(!methodHandle.isVarargsCollector(), "Method must have fixed arity");
checkArgument(methodHandle.type().returnType() == void.class, "Method must return void");
long parameterCount = methodHandle.type().parameterList().stream()
.filter(type -> !ConnectorSession.class.isAssignableFrom(type))
.count();
checkArgument(parameterCount == arguments.size(), "Method parameter count must match arguments");
}
代码示例来源:origin: prestosql/presto
public Procedure(String schema, String name, List<Argument> arguments, MethodHandle methodHandle)
{
this.schema = checkNotNullOrEmpty(schema, "schema").toLowerCase(ENGLISH);
this.name = checkNotNullOrEmpty(name, "name").toLowerCase(ENGLISH);
this.arguments = unmodifiableList(new ArrayList<>(arguments));
this.methodHandle = requireNonNull(methodHandle, "methodHandle is null");
Set<String> names = new HashSet<>();
for (Argument argument : arguments) {
checkArgument(names.add(argument.getName()), "Duplicate argument name: " + argument.getName());
}
checkArgument(!methodHandle.isVarargsCollector(), "Method must have fixed arity");
checkArgument(methodHandle.type().returnType() == void.class, "Method must return void");
long parameterCount = methodHandle.type().parameterList().stream()
.filter(type -> !ConnectorSession.class.isAssignableFrom(type))
.count();
checkArgument(parameterCount == arguments.size(), "Method parameter count must match arguments");
}
代码示例来源:origin: eclipse/golo-lang
public MethodHandle coerce(MethodHandle target) {
if (target.isVarargsCollector() && isLastArgumentAnArray()) {
return target.asFixedArity().asType(type);
}
return target.asType(type);
}
代码示例来源:origin: anba/es6draft
private static MethodHandle toCanonical(MethodHandle handle, int fixedArguments, boolean varargs, Method method) {
assert !handle.isVarargsCollector();
MethodType type = handle.type();
int actual = type.parameterCount() - fixedArguments - (varargs ? 1 : 0);
Object[] defaults = method != null ? methodDefaults(method, fixedArguments, actual) : null;
MethodHandle filter = Parameters.filter(actual, varargs, defaults);
MethodHandle spreader = MethodHandles.spreadInvoker(type, fixedArguments);
spreader = MethodHandles.insertArguments(spreader, 0, handle);
spreader = MethodHandles.filterArguments(spreader, fixedArguments, filter);
return spreader;
}
代码示例来源:origin: eclipse/golo-lang
/**
* Spread arguments over this function parameters.
*
* @param arguments arguments as an array.
* @return a return value.
* @throws Throwable ...because an exception can be thrown.
*/
public Object spread(Object... arguments) throws Throwable {
int arity = arity();
if (this.handle.isVarargsCollector() && (arity > 0) && (arguments[arity - 1] instanceof Object[])) {
return this.handle
.asFixedArity()
.asSpreader(Object[].class, arguments.length)
.invoke(arguments);
}
return this.handle
.asSpreader(Object[].class, arguments.length)
.invoke(arguments);
}
内容来源于网络,如有侵权,请联系作者删除!