java.lang.invoke.MethodType#toString ( )源码实例Demo

下面列出了java.lang.invoke.MethodType#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: MethodTypeTest.java
/**
 * Test of toString method, of class MethodType.
 */
@Test
public void testToString() {
    System.out.println("toString");
    MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
    //String expResult = "void[int, class java.lang.String]";
    String[] expResults = {
        "(int,String)void",
        "(Object,Object)Object",
        "()void",
        "()Object",
        "(String,Integer)int",
        "(String,int)Integer",
        "(String,Integer)Integer",
        "(String,int)int"
    };
    for (int i = 0; i < instances.length; i++) {
        MethodType instance = instances[i];
        String result = instance.toString();
        System.out.println("#"+i+":"+result);
        assertEquals("#"+i, expResults[i], result);
    }
}
 
源代码2 项目: jdk8u60   文件: MethodTypeTest.java
/**
 * Test of toString method, of class MethodType.
 */
@Test
public void testToString() {
    System.out.println("toString");
    MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
    //String expResult = "void[int, class java.lang.String]";
    String[] expResults = {
        "(int,String)void",
        "(Object,Object)Object",
        "()void",
        "()Object",
        "(String,Integer)int",
        "(String,int)Integer",
        "(String,Integer)Integer",
        "(String,int)int"
    };
    for (int i = 0; i < instances.length; i++) {
        MethodType instance = instances[i];
        String result = instance.toString();
        System.out.println("#"+i+":"+result);
        assertEquals("#"+i, expResults[i], result);
    }
}
 
源代码3 项目: openjdk-jdk8u-backup   文件: MethodTypeTest.java
/**
 * Test of toString method, of class MethodType.
 */
@Test
public void testToString() {
    System.out.println("toString");
    MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
    //String expResult = "void[int, class java.lang.String]";
    String[] expResults = {
        "(int,String)void",
        "(Object,Object)Object",
        "()void",
        "()Object",
        "(String,Integer)int",
        "(String,int)Integer",
        "(String,Integer)Integer",
        "(String,int)int"
    };
    for (int i = 0; i < instances.length; i++) {
        MethodType instance = instances[i];
        String result = instance.toString();
        System.out.println("#"+i+":"+result);
        assertEquals("#"+i, expResults[i], result);
    }
}
 
源代码4 项目: openjdk-jdk9   文件: MethodTypeTest.java
/**
 * Test of toString method, of class MethodType.
 */
@Test
public void testToString() {
    System.out.println("toString");
    MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
    //String expResult = "void[int, class java.lang.String]";
    String[] expResults = {
        "(int,String)void",
        "(Object,Object)Object",
        "()void",
        "()Object",
        "(String,Integer)int",
        "(String,int)Integer",
        "(String,Integer)Integer",
        "(String,int)int"
    };
    for (int i = 0; i < instances.length; i++) {
        MethodType instance = instances[i];
        String result = instance.toString();
        System.out.println("#"+i+":"+result);
        assertEquals("#"+i, expResults[i], result);
    }
}
 
源代码5 项目: jdk8u-jdk   文件: MethodTypeTest.java
/**
 * Test of toString method, of class MethodType.
 */
@Test
public void testToString() {
    System.out.println("toString");
    MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
    //String expResult = "void[int, class java.lang.String]";
    String[] expResults = {
        "(int,String)void",
        "(Object,Object)Object",
        "()void",
        "()Object",
        "(String,Integer)int",
        "(String,int)Integer",
        "(String,Integer)Integer",
        "(String,int)int"
    };
    for (int i = 0; i < instances.length; i++) {
        MethodType instance = instances[i];
        String result = instance.toString();
        System.out.println("#"+i+":"+result);
        assertEquals("#"+i, expResults[i], result);
    }
}
 
源代码6 项目: hottub   文件: MethodTypeTest.java
/**
 * Test of toString method, of class MethodType.
 */
@Test
public void testToString() {
    System.out.println("toString");
    MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
    //String expResult = "void[int, class java.lang.String]";
    String[] expResults = {
        "(int,String)void",
        "(Object,Object)Object",
        "()void",
        "()Object",
        "(String,Integer)int",
        "(String,int)Integer",
        "(String,Integer)Integer",
        "(String,int)int"
    };
    for (int i = 0; i < instances.length; i++) {
        MethodType instance = instances[i];
        String result = instance.toString();
        System.out.println("#"+i+":"+result);
        assertEquals("#"+i, expResults[i], result);
    }
}
 
源代码7 项目: jdk8u-dev-jdk   文件: MethodTypeTest.java
/**
 * Test of toString method, of class MethodType.
 */
@Test
public void testToString() {
    System.out.println("toString");
    MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
    //String expResult = "void[int, class java.lang.String]";
    String[] expResults = {
        "(int,String)void",
        "(Object,Object)Object",
        "()void",
        "()Object",
        "(String,Integer)int",
        "(String,int)Integer",
        "(String,Integer)Integer",
        "(String,int)int"
    };
    for (int i = 0; i < instances.length; i++) {
        MethodType instance = instances[i];
        String result = instance.toString();
        System.out.println("#"+i+":"+result);
        assertEquals("#"+i, expResults[i], result);
    }
}
 
源代码8 项目: openjdk-8-source   文件: MethodTypeTest.java
/**
 * Test of toString method, of class MethodType.
 */
@Test
public void testToString() {
    System.out.println("toString");
    MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
    //String expResult = "void[int, class java.lang.String]";
    String[] expResults = {
        "(int,String)void",
        "(Object,Object)Object",
        "()void",
        "()Object",
        "(String,Integer)int",
        "(String,int)Integer",
        "(String,Integer)Integer",
        "(String,int)int"
    };
    for (int i = 0; i < instances.length; i++) {
        MethodType instance = instances[i];
        String result = instance.toString();
        System.out.println("#"+i+":"+result);
        assertEquals("#"+i, expResults[i], result);
    }
}
 
源代码9 项目: jdk8u-jdk   文件: MethodTypeTest.java
/**
 * Test of toString method, of class MethodType.
 */
@Test
public void testToString() {
    System.out.println("toString");
    MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
    //String expResult = "void[int, class java.lang.String]";
    String[] expResults = {
        "(int,String)void",
        "(Object,Object)Object",
        "()void",
        "()Object",
        "(String,Integer)int",
        "(String,int)Integer",
        "(String,Integer)Integer",
        "(String,int)int"
    };
    for (int i = 0; i < instances.length; i++) {
        MethodType instance = instances[i];
        String result = instance.toString();
        System.out.println("#"+i+":"+result);
        assertEquals("#"+i, expResults[i], result);
    }
}
 
源代码10 项目: openjdk-8   文件: MethodTypeTest.java
/**
 * Test of toString method, of class MethodType.
 */
@Test
public void testToString() {
    System.out.println("toString");
    MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
    //String expResult = "void[int, class java.lang.String]";
    String[] expResults = {
        "(int,String)void",
        "(Object,Object)Object",
        "()void",
        "()Object",
        "(String,Integer)int",
        "(String,int)Integer",
        "(String,Integer)Integer",
        "(String,int)int"
    };
    for (int i = 0; i < instances.length; i++) {
        MethodType instance = instances[i];
        String result = instance.toString();
        System.out.println("#"+i+":"+result);
        assertEquals("#"+i, expResults[i], result);
    }
}
 
源代码11 项目: jdk8u_jdk   文件: MethodTypeTest.java
/**
 * Test of toString method, of class MethodType.
 */
@Test
public void testToString() {
    System.out.println("toString");
    MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
    //String expResult = "void[int, class java.lang.String]";
    String[] expResults = {
        "(int,String)void",
        "(Object,Object)Object",
        "()void",
        "()Object",
        "(String,Integer)int",
        "(String,int)Integer",
        "(String,Integer)Integer",
        "(String,int)int"
    };
    for (int i = 0; i < instances.length; i++) {
        MethodType instance = instances[i];
        String result = instance.toString();
        System.out.println("#"+i+":"+result);
        assertEquals("#"+i, expResults[i], result);
    }
}
 
源代码12 项目: nashorn   文件: SingleDynamicMethod.java
static String getMethodNameWithSignature(MethodType type, String methodName) {
    final String typeStr = type.toString();
    final int retTypeIndex = typeStr.lastIndexOf(')') + 1;
    int secondParamIndex = typeStr.indexOf(',') + 1;
    if(secondParamIndex == 0) {
        secondParamIndex = retTypeIndex - 1;
    }
    return typeStr.substring(retTypeIndex) + " " + methodName + "(" + typeStr.substring(secondParamIndex, retTypeIndex);
}
 
源代码13 项目: TencentKona-8   文件: SingleDynamicMethod.java
static String getMethodNameWithSignature(final MethodType type, final String methodName, final boolean withReturnType) {
    final String typeStr = type.toString();
    final int retTypeIndex = typeStr.lastIndexOf(')') + 1;
    int secondParamIndex = typeStr.indexOf(',') + 1;
    if(secondParamIndex == 0) {
        secondParamIndex = retTypeIndex - 1;
    }
    final StringBuilder b = new StringBuilder();
    if (withReturnType) {
        b.append(typeStr, retTypeIndex, typeStr.length()).append(' ');
    }
    return b.append(methodName).append('(').append(typeStr, secondParamIndex, retTypeIndex).toString();
}
 
源代码14 项目: jdk8u60   文件: SingleDynamicMethod.java
static String getMethodNameWithSignature(final MethodType type, final String methodName) {
    final String typeStr = type.toString();
    final int retTypeIndex = typeStr.lastIndexOf(')') + 1;
    int secondParamIndex = typeStr.indexOf(',') + 1;
    if(secondParamIndex == 0) {
        secondParamIndex = retTypeIndex - 1;
    }
    return typeStr.substring(retTypeIndex) + " " + methodName + "(" + typeStr.substring(secondParamIndex, retTypeIndex);
}
 
源代码15 项目: openjdk-jdk8u   文件: SingleDynamicMethod.java
static String getMethodNameWithSignature(final MethodType type, final String methodName, final boolean withReturnType) {
    final String typeStr = type.toString();
    final int retTypeIndex = typeStr.lastIndexOf(')') + 1;
    int secondParamIndex = typeStr.indexOf(',') + 1;
    if(secondParamIndex == 0) {
        secondParamIndex = retTypeIndex - 1;
    }
    final StringBuilder b = new StringBuilder();
    if (withReturnType) {
        b.append(typeStr, retTypeIndex, typeStr.length()).append(' ');
    }
    return b.append(methodName).append('(').append(typeStr, secondParamIndex, retTypeIndex).toString();
}
 
源代码16 项目: openjdk-systemtest   文件: BasicStaticTest.java
public static void check(MethodType ideal, MethodType actual) {
    if (!ideal.equals(actual)) {
        String idealString = (ideal==null)? "null" : ideal.toString();
        String actualString = (actual==null)? "null" : actual.toString();
        throw new Error("ERROR: Expected " + idealString + "; found " + actualString);
    }
}
 
源代码17 项目: openjdk-jdk8u-backup   文件: SingleDynamicMethod.java
static String getMethodNameWithSignature(final MethodType type, final String methodName, final boolean withReturnType) {
    final String typeStr = type.toString();
    final int retTypeIndex = typeStr.lastIndexOf(')') + 1;
    int secondParamIndex = typeStr.indexOf(',') + 1;
    if(secondParamIndex == 0) {
        secondParamIndex = retTypeIndex - 1;
    }
    final StringBuilder b = new StringBuilder();
    if (withReturnType) {
        b.append(typeStr, retTypeIndex, typeStr.length()).append(' ');
    }
    return b.append(methodName).append('(').append(typeStr, secondParamIndex, retTypeIndex).toString();
}
 
源代码18 项目: openjdk-jdk9   文件: SingleDynamicMethod.java
static String getMethodNameWithSignature(final MethodType type, final String methodName, final boolean withReturnType) {
    final String typeStr = type.toString();
    final int retTypeIndex = typeStr.lastIndexOf(')') + 1;
    int secondParamIndex = typeStr.indexOf(',') + 1;
    if(secondParamIndex == 0) {
        secondParamIndex = retTypeIndex - 1;
    }
    final StringBuilder b = new StringBuilder();
    if (withReturnType) {
        b.append(typeStr, retTypeIndex, typeStr.length()).append(' ');
    }
    return b.append(methodName).append('(').append(typeStr, secondParamIndex, retTypeIndex).toString();
}
 
源代码19 项目: jdk8u_nashorn   文件: SingleDynamicMethod.java
static String getMethodNameWithSignature(final MethodType type, final String methodName, final boolean withReturnType) {
    final String typeStr = type.toString();
    final int retTypeIndex = typeStr.lastIndexOf(')') + 1;
    int secondParamIndex = typeStr.indexOf(',') + 1;
    if(secondParamIndex == 0) {
        secondParamIndex = retTypeIndex - 1;
    }
    final StringBuilder b = new StringBuilder();
    if (withReturnType) {
        b.append(typeStr, retTypeIndex, typeStr.length()).append(' ');
    }
    return b.append(methodName).append('(').append(typeStr, secondParamIndex, retTypeIndex).toString();
}
 
源代码20 项目: es6draft   文件: Properties.java
private static MethodHandle getStaticMethodHandle(Lookup lookup, Method method) throws IllegalAccessException {
    MethodHandle handle = lookup.unreflect(method);
    MethodType type = handle.type();
    Class<?>[] params = type.parameterArray();
    int p = 0, pcount = type.parameterCount();
    boolean callerContext = false;

    // First three parameters are (ExecutionContext, ExecutionContext?, Object=ThisValue)
    if (!(p < pcount && ExecutionContext.class.equals(params[p++]))) {
        throw new IllegalArgumentException(type.toString());
    }
    if (p < pcount && ExecutionContext.class.equals(params[p])) {
        callerContext = true;
        p++;
    }
    if (!(p < pcount && Object.class.equals(params[p++]))) {
        throw new IllegalArgumentException(type.toString());
    }
    // Always required to return Object (for now at least)
    if (!Object.class.equals(type.returnType())) {
        throw new IllegalArgumentException(type.toString());
    }
    // Collect remaining arguments into Object[]
    if (!(p + 1 == pcount && Object[].class.equals(params[p]))) {
        final int fixedArguments = callerContext ? 3 : 2;
        final boolean varargs = handle.isVarargsCollector();
        // Otherwise all trailing arguments need to be of type Object or Object[]
        for (; p < pcount; ++p) {
            if (Object.class.equals(params[p])) {
                continue;
            }
            if (p + 1 == pcount && Object[].class.equals(params[p]) && varargs) {
                continue;
            }
            throw new IllegalArgumentException(type.toString());
        }
        // Trailing Object[] arguments are no longer spread in var-args methods (jdk8u40, jdk9).
        if (varargs) {
            handle = handle.asFixedArity();
        }
        // Convert to (ExecutionContext, Object, ...) -> Object handle
        handle = toCanonical(handle, fixedArguments, varargs, method);
    }
    if (!callerContext) {
        handle = MethodHandles.dropArguments(handle, 1, ExecutionContext.class);
    }

    // assert handle.type().parameterCount() == 4;
    // assert handle.type().parameterType(0) == ExecutionContext.class;
    // assert handle.type().parameterType(1) == ExecutionContext.class;
    // assert handle.type().parameterType(2) == Object.class;
    // assert handle.type().parameterType(3) == Object[].class;
    // assert handle.type().returnType() == Object.class;

    return handle;
}