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