本文整理汇总了Java中java.lang.invoke.MethodType.appendParameterTypes方法的典型用法代码示例。如果您正苦于以下问题:Java MethodType.appendParameterTypes方法的具体用法?Java MethodType.appendParameterTypes怎么用?Java MethodType.appendParameterTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.invoke.MethodType
的用法示例。
在下文中一共展示了MethodType.appendParameterTypes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: explicitParams
import java.lang.invoke.MethodType; //导入方法依赖的package包/类
private MethodType explicitParams(final MethodType callSiteType) {
if (CompiledFunction.isVarArgsType(callSiteType)) {
return null;
}
final MethodType noCalleeThisType = callSiteType.dropParameterTypes(0, 2); // (callee, this) is always in call site type
final int callSiteParamCount = noCalleeThisType.parameterCount();
// Widen parameters of reference types to Object as we currently don't care for specialization among reference
// types. E.g. call site saying (ScriptFunction, Object, String) should still link to (ScriptFunction, Object, Object)
final Class<?>[] paramTypes = noCalleeThisType.parameterArray();
boolean changed = false;
for (int i = 0; i < paramTypes.length; ++i) {
final Class<?> paramType = paramTypes[i];
if (!(paramType.isPrimitive() || paramType == Object.class)) {
paramTypes[i] = Object.class;
changed = true;
}
}
final MethodType generalized = changed ? MethodType.methodType(noCalleeThisType.returnType(), paramTypes) : noCalleeThisType;
if (callSiteParamCount < getArity()) {
return generalized.appendParameterTypes(Collections.<Class<?>>nCopies(getArity() - callSiteParamCount, Object.class));
}
return generalized;
}
示例2: getCallSiteType
import java.lang.invoke.MethodType; //导入方法依赖的package包/类
MethodType getCallSiteType(final FunctionNode functionNode) {
final Type[] types = paramTypeMap.get(functionNode.getId());
if (types == null) {
return null;
}
MethodType mt = MethodType.methodType(returnTypeMap.get(functionNode.getId()).getTypeClass());
if (needsCallee) {
mt = mt.appendParameterTypes(ScriptFunction.class);
}
mt = mt.appendParameterTypes(Object.class); //this
for (final Type type : types) {
if (type == null) {
return null; // not all parameter information is supplied
}
mt = mt.appendParameterTypes(type.getTypeClass());
}
return mt;
}
示例3: adjustArity
import java.lang.invoke.MethodType; //导入方法依赖的package包/类
static MethodHandle adjustArity(MethodHandle mh, int arity) {
MethodType mt = mh.type();
int posArgs = mt.parameterCount() - 1;
Class<?> reptype = mt.parameterType(posArgs).getComponentType();
MethodType mt1 = mt.dropParameterTypes(posArgs, posArgs+1);
while (mt1.parameterCount() < arity) {
Class<?> pt = reptype;
if (pt == Object.class && posArgs > 0)
// repeat types cyclically if possible:
pt = mt1.parameterType(mt1.parameterCount() - posArgs);
mt1 = mt1.appendParameterTypes(pt);
}
try {
return mh.asType(mt1);
} catch (WrongMethodTypeException | IllegalArgumentException ex) {
throw new IllegalArgumentException("cannot convert to type "+mt1+" from "+mh, ex);
}
}
示例4: adapt
import java.lang.invoke.MethodType; //导入方法依赖的package包/类
private TupleHandle adapt(MethodType type, Form form) {
if (this.type.equals(type)) {
return this;
}
int objects = 0;
int prims = 0;
List<Class<?>> parameters = type.parameterList();
int length = parameters.size();
int[] reorder = new int[form.objects + form.prims];
MethodHandle[] cs = new MethodHandle[length];
for(int i = 0; i < length; i++) {
Class<?> parameter = parameters.get(i);
int index = parameter.isPrimitive()? form.objects + prims++: objects++;
MethodHandle c = components[index];
cs[i] = narrow(c, parameter);
reorder[index] = i;
}
// need to fill the holes (objects & prims) for the constructor
int hole = length;
for(int i = objects; i < form.objects; i++) {
reorder[i] = hole++;
}
for(int i = form.objects + prims; i < form.objects + form.prims; i++) {
reorder[i] = hole++;
}
MethodType consType = type.changeReturnType(Object.class);
MethodHandle cons = constructor;
MethodType permutedType = erase(consType);
if (objects < form.objects) {
permutedType = permutedType.appendParameterTypes(classes(Object.class, form.objects - objects));
}
if (prims < form.prims) {
permutedType = permutedType.appendParameterTypes(classes(long.class, form.prims - prims));
}
cons = permuteArguments(cons, permutedType, reorder);
if (objects < form.objects) {
cons = MethodHandles.insertArguments(cons, length, values(null, form.objects - objects));
}
if (prims < form.prims) {
cons = MethodHandles.insertArguments(cons, length, values(0L, form.prims - prims));
}
cons = widen(cons, consType);
return new TupleHandle(type, cons, cs);
}