当前位置: 首页>>代码示例>>Java>>正文


Java MethodType.appendParameterTypes方法代码示例

本文整理汇总了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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:RecompilableScriptFunctionData.java

示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:TypeMap.java

示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:PermuteArgsTest.java

示例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);
}
 
开发者ID:forax,项目名称:mjolnir,代码行数:49,代码来源:TupleHandle.java


注:本文中的java.lang.invoke.MethodType.appendParameterTypes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。