當前位置: 首頁>>代碼示例>>Java>>正文


Java MethodType.parameterArray方法代碼示例

本文整理匯總了Java中java.lang.invoke.MethodType.parameterArray方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodType.parameterArray方法的具體用法?Java MethodType.parameterArray怎麽用?Java MethodType.parameterArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.invoke.MethodType的用法示例。


在下文中一共展示了MethodType.parameterArray方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: getCallMethodType

import java.lang.invoke.MethodType; //導入方法依賴的package包/類
private static MethodType getCallMethodType(final boolean isVarArgCall, final MethodType type) {
    final Class<?>[] callParamTypes;
    if (isVarArgCall) {
        // Variable arity calls are always (Object callee, Object this, Object[] params)
        callParamTypes = new Class<?>[] { Object.class, Object.class, Object[].class };
    } else {
        // Adjust invocation type signature for conversions we instituted in
        // convertParam; also, byte and short get passed as ints.
        final Class<?>[] origParamTypes = type.parameterArray();
        callParamTypes = new Class<?>[origParamTypes.length + 2];
        callParamTypes[0] = Object.class; // callee; could be ScriptFunction.class ostensibly
        callParamTypes[1] = Object.class; // this
        for(int i = 0; i < origParamTypes.length; ++i) {
            callParamTypes[i + 2] = getNashornParamType(origParamTypes[i], false);
        }
    }
    return MethodType.methodType(getNashornReturnType(type.returnType()), callParamTypes);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:JavaAdapterBytecodeGenerator.java

示例3: TypeMap

import java.lang.invoke.MethodType; //導入方法依賴的package包/類
/**
 * Constructor
 * @param functionNodeId function node id
 * @param type           method type found at runtime corresponding to parameter guess
 * @param needsCallee    does the function using this type map need a callee
 */
public TypeMap(final int functionNodeId, final MethodType type, final boolean needsCallee) {
    final Type[] types = new Type[type.parameterCount()];
    int pos = 0;
    for (final Class<?> p : type.parameterArray()) {
        types[pos++] = Type.typeFor(p);
    }
    paramTypeMap.put(functionNodeId, types);
    returnTypeMap.put(functionNodeId, Type.typeFor(type.returnType()));

    this.needsCallee = needsCallee;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:18,代碼來源:TypeMap.java

示例4: testParameterArray

import java.lang.invoke.MethodType; //導入方法依賴的package包/類
/**
 * Test of parameterArray method, of class MethodType.
 */
@Test
public void testParameterArray() {
    System.out.println("parameterArray");
    MethodType instance = mt_viS;
    Class<?>[] expResult = ptypes;
    Class<?>[] result = instance.parameterArray();
    assertEquals(Arrays.asList(expResult), Arrays.asList(result));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:12,代碼來源:MethodTypeTest.java

示例5: getArrayCreatorMethodType

import java.lang.invoke.MethodType; //導入方法依賴的package包/類
private static MethodType getArrayCreatorMethodType(final MethodType type) {
    final Class<?>[] callParamTypes = type.parameterArray();
    for(int i = 0; i < callParamTypes.length; ++i) {
        callParamTypes[i] = getNashornParamType(callParamTypes[i], true);
    }
    return MethodType.methodType(Object[].class, callParamTypes);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:JavaAdapterBytecodeGenerator.java

示例6: TypeMap

import java.lang.invoke.MethodType; //導入方法依賴的package包/類
/**
 * Constructor
 * @param functionNodeId function node id
 * @param type           method type found at runtime corresponding to parameter guess
 * @param needsCallee    does the function using this type map need a callee
 */
public TypeMap(final int functionNodeId, final MethodType type, final boolean needsCallee) {
    final Type[] types = new Type[type.parameterCount()];
    int pos = 0;
    for (final Class<?> p : type.parameterArray()) {
        types[pos++] = Type.typeFor(p);
    }

    this.functionNodeId = functionNodeId;
    this.paramTypes = types;
    this.returnType = Type.typeFor(type.returnType());
    this.needsCallee = needsCallee;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:TypeMap.java

示例7: convertTypes

import java.lang.invoke.MethodType; //導入方法依賴的package包/類
private static void convertTypes(MethodType mt, Object[] args) {
  Class<?>[] params = mt.parameterArray();

  for (int i = 0; i < params.length; i++) {
    Class<?> param = params[i];

    if (param.isPrimitive() && args[i] instanceof Number) {
      if (param == byte.class) {
        args[i] = ((Number) args[i]).byteValue();
      } else if (param == double.class) {
        args[i] = ((Number) args[i]).doubleValue();
      } else if (param == float.class) {
        args[i] = ((Number) args[i]).floatValue();
      } else if (param == int.class) {
        args[i] = ((Number) args[i]).intValue();
      } else if (param == long.class) {
        args[i] = ((Number) args[i]).longValue();
      } else if (param == short.class) {
        args[i] = ((Number) args[i]).shortValue();
      }
    }

    if (args[i] instanceof String
        && (param == char.class || param == Character.class)) {
      args[i] = ((String) args[i]).charAt(0);
    }

    if (param == Class.class && args[i] instanceof JavaType) {
      args[i] = ((JavaType) args[i]).getJavaClass();
    }

    if (args[i] instanceof Null) {
      args[i] = null;
    }
  }
}
 
開發者ID:btk5h,項目名稱:skript-mirror,代碼行數:37,代碼來源:ExprJavaCall.java

示例8: ClassString

import java.lang.invoke.MethodType; //導入方法依賴的package包/類
ClassString(final MethodType type) {
    this(type.parameterArray());
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:4,代碼來源:ClassString.java

示例9: matchesArgs

import java.lang.invoke.MethodType; //導入方法依賴的package包/類
private static boolean matchesArgs(Object[] args, MethodHandle mh) {
  MethodType mt = mh.type();
  if (mt.parameterCount() != args.length && !mh.isVarargsCollector()) {
    return false;
  }

  Class<?>[] params = mt.parameterArray();

  for (int i = 0; i < params.length; i++) {
    if (i == params.length - 1 && mh.isVarargsCollector()) {
      break;
    }

    Class<?> param = params[i];
    Object arg = args[i];

    if (!param.isInstance(arg)) {
      if (arg instanceof Number && Util.NUMERIC_CLASSES.contains(param)) {
        continue;
      }

      if (param.isPrimitive() && Util.WRAPPER_CLASSES.get(param).isInstance(arg)) {
        continue;
      }

      if (arg instanceof String
          && (param == char.class || param == Character.class)
          && ((String) arg).length() == 1) {
        continue;
      }

      if (param == Class.class && arg instanceof JavaType) {
        continue;
      }

      if (!param.isPrimitive() && arg instanceof Null) {
        continue;
      }

      return false;
    }
  }

  return true;
}
 
開發者ID:btk5h,項目名稱:skript-mirror,代碼行數:46,代碼來源:ExprJavaCall.java


注:本文中的java.lang.invoke.MethodType.parameterArray方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。