當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。