当前位置: 首页>>代码示例>>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;未经允许,请勿转载。