1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/meth/InvokeMHTrans.java Tue Sep 07 17:32:27 2010 +0100 1.3 @@ -0,0 +1,102 @@ 1.4 +/* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. 1.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.6 + * 1.7 + * This code is free software; you can redistribute it and/or modify it 1.8 + * under the terms of the GNU General Public License version 2 only, as 1.9 + * published by the Free Software Foundation. 1.10 + * 1.11 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.12 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.13 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.14 + * version 2 for more details (a copy is included in the LICENSE file that 1.15 + * accompanied this code). 1.16 + * 1.17 + * You should have received a copy of the GNU General Public License version 1.18 + * 2 along with this work; if not, write to the Free Software Foundation, 1.19 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.20 + * 1.21 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.22 + * or visit www.oracle.com if you need additional information or have any 1.23 + * questions. 1.24 + */ 1.25 + 1.26 +/* 1.27 + * @test 1.28 + * @bug 6754038 6979327 1.29 + * @summary Generate call sites for method handle 1.30 + * @author jrose 1.31 + * 1.32 + * @compile/fail/ref=InvokeMHTrans.out -Werror -XDrawDiagnostics -source 7 -target 7 InvokeMHTrans.java 1.33 + */ 1.34 + 1.35 +/* 1.36 + * Standalone testing: 1.37 + * <code> 1.38 + * $ cd $MY_REPO_DIR/langtools 1.39 + * $ (cd make; make) 1.40 + * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/meth/InvokeMH.java 1.41 + * $ javap -c -classpath dist meth.InvokeMH 1.42 + * </code> 1.43 + */ 1.44 + 1.45 +package meth; 1.46 + 1.47 +import java.dyn.MethodHandle; 1.48 + 1.49 +public class InvokeMHTrans { 1.50 + void test(MethodHandle mh_SiO, 1.51 + MethodHandle mh_vS, 1.52 + MethodHandle mh_vi, 1.53 + MethodHandle mh_vv) throws Throwable { 1.54 + Object o; String s; int i; // for return type testing 1.55 + 1.56 + // next five must have sig = (String,int)Object 1.57 + mh_SiO.invokeExact("world", 123); 1.58 + mh_SiO.invokeExact("mundus", 456); 1.59 + Object k = "kosmos"; 1.60 + mh_SiO.invokeExact((String)k, 789); 1.61 + o = mh_SiO.invokeExact((String)null, 000); 1.62 + o = mh_SiO.<Object>invokeExact("arda", -123); 1.63 + 1.64 + // sig = ()String 1.65 + s = mh_vS.<String>invokeExact(); 1.66 + 1.67 + // sig = ()int 1.68 + i = mh_vi.<int>invokeExact(); 1.69 + o = mh_vi.<int>invokeExact(); 1.70 + //s = mh_vi.<int>invokeExact(); //BAD 1.71 + mh_vi.<int>invokeExact(); 1.72 + 1.73 + // sig = ()void 1.74 + //o = mh_vv.<void>invokeExact(); //BAD 1.75 + mh_vv.<void>invokeExact(); 1.76 + } 1.77 + 1.78 + void testGen(MethodHandle mh_SiO, 1.79 + MethodHandle mh_vS, 1.80 + MethodHandle mh_vi, 1.81 + MethodHandle mh_vv) throws Throwable { 1.82 + Object o; String s; int i; // for return type testing 1.83 + 1.84 + // next five must have sig = (*,*)* 1.85 + mh_SiO.invokeGeneric((Object)"world", (Object)123); 1.86 + mh_SiO.<void>invokeGeneric((Object)"mundus", (Object)456); 1.87 + Object k = "kosmos"; 1.88 + mh_SiO.invokeGeneric(k, 789); 1.89 + o = mh_SiO.invokeGeneric(null, 000); 1.90 + o = mh_SiO.<Object>invokeGeneric("arda", -123); 1.91 + 1.92 + // sig = ()String 1.93 + o = mh_vS.invokeGeneric(); 1.94 + 1.95 + // sig = ()int 1.96 + i = mh_vi.<int>invokeGeneric(); 1.97 + o = mh_vi.invokeGeneric(); 1.98 + //s = mh_vi.<int>invokeGeneric(); //BAD 1.99 + mh_vi.<void>invokeGeneric(); 1.100 + 1.101 + // sig = ()void 1.102 + //o = mh_vv.<void>invokeGeneric(); //BAD 1.103 + o = mh_vv.invokeGeneric(); 1.104 + } 1.105 +}