Java Code Examples for java.lang.invoke.MethodType#toString()

The following examples show how to use java.lang.invoke.MethodType#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MethodTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 2
Source File: MethodTypeTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 3
Source File: MethodTypeTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 4
Source File: MethodTypeTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 5
Source File: MethodTypeTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 6
Source File: MethodTypeTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 7
Source File: MethodTypeTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 8
Source File: MethodTypeTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 9
Source File: MethodTypeTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 10
Source File: MethodTypeTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 11
Source File: MethodTypeTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 12
Source File: SingleDynamicMethod.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 13
Source File: SingleDynamicMethod.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 14
Source File: BasicStaticTest.java    From openjdk-systemtest with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 15
Source File: SingleDynamicMethod.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 16
Source File: SingleDynamicMethod.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 17
Source File: SingleDynamicMethod.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 18
Source File: SingleDynamicMethod.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 19
Source File: SingleDynamicMethod.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 20
Source File: Properties.java    From es6draft with MIT License 4 votes vote down vote up
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;
}