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


Java MethodHandles.permuteArguments方法代碼示例

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


在下文中一共展示了MethodHandles.permuteArguments方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testReturnOnStack

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
@Test
public void testReturnOnStack() throws Throwable {
    MethodHandles.Lookup l = MethodHandles.lookup();

    MethodHandle consumeIdentity = l.findStatic(
            PermuteArgsReturnVoidTest.class, "consumeIdentity",
            MethodType.methodType(String.class, String.class, int.class, int.class));
    MethodHandle consumeVoid = l.findStatic(
            PermuteArgsReturnVoidTest.class, "consumeVoid",
            MethodType.methodType(void.class, String.class, int.class, int.class));

    MethodHandle f = MethodHandles.foldArguments(consumeIdentity, consumeVoid);

    MethodHandle p = MethodHandles.permuteArguments(f, MethodType.methodType(String.class, String.class, int.class, int.class), 0, 2, 1);

    String s = (String) p.invoke("IN", 0, 0);
    Assert.assertEquals(s.getClass(), String.class);
    Assert.assertEquals(s, "IN");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:PermuteArgsReturnVoidTest.java

示例2: testReturnFromArg

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
@Test
public void testReturnFromArg() throws Throwable {
    MethodHandles.Lookup l = MethodHandles.lookup();

    MethodHandle consumeIdentity = dropArguments(
            identity(String.class), 1, int.class, int.class);
    MethodHandle consumeVoid = l.findStatic(
            PermuteArgsReturnVoidTest.class, "consumeVoid",
            MethodType.methodType(void.class, String.class, int.class, int.class));

    MethodHandle f = MethodHandles.foldArguments(consumeIdentity, consumeVoid);

    MethodHandle p = MethodHandles.permuteArguments(f, MethodType.methodType(String.class, String.class, int.class, int.class), 0, 2, 1);

    String s = (String) p.invoke("IN", 0, 0);
    Assert.assertEquals(s.getClass(), String.class);
    Assert.assertEquals(s, "IN");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:PermuteArgsReturnVoidTest.java

示例3: or

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
public Pattern or(Pattern match) {
  return new Pattern(form.or(match.form),
      uberForm -> MethodHandles.permuteArguments(
                    MethodHandles.filterArguments(
                        guardWithTest(
                          dropArguments(
                            uberForm.createAs(methodType(void.class, int.class, boolean.class)).component(1),
                            0, Object.class),
                          dropArguments(identity(Object.class), 0, Object.class),
                          dropArguments(match.mh.apply(uberForm), 1, Object.class)),
                      1, mh.apply(uberForm)),
                    methodType(Object.class, Object.class), new int[] { 0, 0}));
}
 
開發者ID:forax,項目名稱:mjolnir,代碼行數:14,代碼來源:Pattern.java

示例4: permute

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
static MethodHandle permute(MethodHandle h) {
    // The handles representing virtual methods need to be rearranged to match the required order of arguments
    // (loop-local state comes first, then loop arguments). As the receiver comes first in the signature but is
    // a loop argument, it must be moved to the appropriate position in the signature.
    return MethodHandles.permuteArguments(h,
            methodType(h.type().returnType(), int.class, int.class, LOOP_WITH_VIRTUALS, int.class), 2, 0, 1, 3);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:LoopCombinatorTest.java

示例5: constantBoolean

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
private static MethodHandle constantBoolean(final Boolean value, final MethodType type) {
    return MethodHandles.permuteArguments(MethodHandles.constant(Boolean.TYPE, value),
            type.changeReturnType(Boolean.TYPE));
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:5,代碼來源:Guards.java

示例6: testPermuteArguments

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
void testPermuteArguments(Object[] args, Class<?>[] types, int[] reorder) throws Throwable {
    countTest();
    if (args == null && types == null) {
        int max = 0;
        for (int j : reorder) {
            if (max < j)  max = j;
        }
        args = randomArgs(max+1, Integer.class);
    }
    if (args == null) {
        args = randomArgs(types);
    }
    if (types == null) {
        types = new Class<?>[args.length];
        for (int i = 0; i < args.length; i++)
            types[i] = args[i].getClass();
    }
    int inargs = args.length, outargs = reorder.length;
    assertTrue(inargs == types.length);
    if (verbosity >= 3)
        System.out.println("permuteArguments "+Arrays.toString(reorder));
    Object[] permArgs = new Object[outargs];
    Class<?>[] permTypes = new Class<?>[outargs];
    for (int i = 0; i < outargs; i++) {
        permArgs[i] = args[reorder[i]];
        permTypes[i] = types[reorder[i]];
    }
    if (verbosity >= 4) {
        System.out.println("in args:   "+Arrays.asList(args));
        System.out.println("out args:  "+Arrays.asList(permArgs));
        System.out.println("in types:  "+Arrays.asList(types));
        System.out.println("out types: "+Arrays.asList(permTypes));
    }
    MethodType inType  = MethodType.methodType(Object.class, types);
    MethodType outType = MethodType.methodType(Object.class, permTypes);
    MethodHandle target = varargsList(outargs).asType(outType);
    MethodHandle newTarget = MethodHandles.permuteArguments(target, inType, reorder);
    if (verbosity >= 5)  System.out.println("newTarget = "+newTarget);
    Object result = newTarget.invokeWithArguments(args);
    Object expected = Arrays.asList(permArgs);
    if (!expected.equals(result)) {
        System.out.println("*** failed permuteArguments "+Arrays.toString(reorder)+" types="+Arrays.asList(types));
        System.out.println("in args:   "+Arrays.asList(args));
        System.out.println("out args:  "+expected);
        System.out.println("bad args:  "+result);
    }
    assertEquals(expected, result);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:49,代碼來源:MethodHandlesTest.java


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