1 /* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8177466 27 * @summary Add compiler support for local variable type-inference 28 * @modules jdk.compiler/com.sun.source.tree 29 * jdk.compiler/com.sun.source.util 30 * jdk.compiler/com.sun.tools.javac.api 31 * jdk.compiler/com.sun.tools.javac.code 32 * jdk.compiler/com.sun.tools.javac.util 33 * @build LocalVariableInferenceTester 34 * @run main LocalVariableInferenceTester PrimitiveTypeTest.java 35 */ 36 class PrimitiveTypeTest { 37 38 byte[] b_arr = { 0 }; 39 short[] s_arr = { 0 }; 40 int[] i_arr = { 0 }; 41 long[] l_arr = { 0 }; 42 float[] f_arr = { 0 }; 43 double[] d_arr = { 0 }; 44 char[] c_arr = { 0 }; 45 boolean[] z_arr = { false }; 46 testPrimitive()47 void testPrimitive() { 48 @InferredType("byte") 49 var b = (byte)0; 50 @InferredType("short") 51 var s = (short)0; 52 @InferredType("int") 53 var i = 0; 54 @InferredType("long") 55 var l = 0L; 56 @InferredType("float") 57 var f = 0f; 58 @InferredType("double") 59 var d = 0d; 60 @InferredType("char") 61 var c = 'c'; 62 @InferredType("boolean") 63 var z = false; 64 } 65 testPrimitiveArray()66 void testPrimitiveArray() { 67 @InferredType("byte[]") 68 var b = b_arr; 69 @InferredType("short[]") 70 var s = s_arr; 71 @InferredType("int[]") 72 var i = i_arr; 73 @InferredType("long[]") 74 var l = l_arr; 75 @InferredType("float[]") 76 var f = f_arr; 77 @InferredType("double[]") 78 var d = d_arr; 79 @InferredType("char[]") 80 var c = c_arr; 81 @InferredType("boolean[]") 82 var z = z_arr; 83 } 84 testForEachPrimitive()85 void testForEachPrimitive() { 86 for (@InferredType("byte") var b : b_arr) { break; } 87 for (@InferredType("short") var s : s_arr) { break; } 88 for (@InferredType("int") var i : i_arr) { break; } 89 for (@InferredType("long") var l : l_arr) { break; } 90 for (@InferredType("float") var f : f_arr) { break; } 91 for (@InferredType("double") var d : d_arr) { break; } 92 for (@InferredType("char") var c : c_arr) { break; } 93 for (@InferredType("boolean") var z : z_arr) { break; } 94 } 95 } 96