Thu, 24 Feb 2011 08:40:49 -0800
7018753: tools/javac/varargs/warning/Warn5.java times out on slow machines
Summary: Use a single file manager for all JavacTasks
Reviewed-by: jjg, mcimadamore
mcimadamore@792 | 1 | /* |
mcimadamore@792 | 2 | * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
mcimadamore@792 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
mcimadamore@792 | 4 | * |
mcimadamore@792 | 5 | * This code is free software; you can redistribute it and/or modify it |
mcimadamore@792 | 6 | * under the terms of the GNU General Public License version 2 only, as |
mcimadamore@792 | 7 | * published by the Free Software Foundation. |
mcimadamore@792 | 8 | * |
mcimadamore@792 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
mcimadamore@792 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
mcimadamore@792 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
mcimadamore@792 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
mcimadamore@792 | 13 | * accompanied this code). |
mcimadamore@792 | 14 | * |
mcimadamore@792 | 15 | * You should have received a copy of the GNU General Public License version |
mcimadamore@792 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
mcimadamore@792 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
mcimadamore@792 | 18 | * |
mcimadamore@792 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
mcimadamore@792 | 20 | * or visit www.oracle.com if you need additional information or have any |
mcimadamore@792 | 21 | * questions. |
mcimadamore@792 | 22 | */ |
mcimadamore@792 | 23 | |
mcimadamore@792 | 24 | /* |
mcimadamore@792 | 25 | * @test |
mcimadamore@792 | 26 | * @bug 7006109 |
mcimadamore@792 | 27 | * @summary Add test library to simplify the task of writing automated type-system tests |
mcimadamore@792 | 28 | * @author mcimadamore |
mcimadamore@792 | 29 | * @library . |
mcimadamore@792 | 30 | * @run main CastTest |
mcimadamore@792 | 31 | */ |
mcimadamore@792 | 32 | |
mcimadamore@792 | 33 | import com.sun.tools.javac.code.Type; |
mcimadamore@792 | 34 | import com.sun.tools.javac.code.Type.*; |
mcimadamore@792 | 35 | import com.sun.tools.javac.code.Symbol.*; |
mcimadamore@792 | 36 | import java.lang.reflect.Array; |
mcimadamore@792 | 37 | |
mcimadamore@792 | 38 | import static com.sun.tools.javac.code.Flags.*; |
mcimadamore@792 | 39 | |
mcimadamore@792 | 40 | /** |
mcimadamore@792 | 41 | * Check invariants in cast conversion involving primitive types and arrays |
mcimadamore@792 | 42 | */ |
mcimadamore@792 | 43 | public class CastTest extends TypeHarness { |
mcimadamore@792 | 44 | |
mcimadamore@792 | 45 | Type[] allTypes; |
mcimadamore@792 | 46 | |
mcimadamore@792 | 47 | static final boolean T = true; |
mcimadamore@792 | 48 | static final boolean F = false; |
mcimadamore@792 | 49 | |
mcimadamore@792 | 50 | boolean[][] cast_result = { |
mcimadamore@792 | 51 | //byte, short, int, long, float, double, char, bool, C, +C, I, T, byte[], short[], int[], long[], float[], double[], char[], bool[], C[], +C[], I[], T[] |
mcimadamore@792 | 52 | /*byte*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F }, |
mcimadamore@792 | 53 | /*short*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F }, |
mcimadamore@792 | 54 | /*int*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F }, |
mcimadamore@792 | 55 | /*long*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F }, |
mcimadamore@792 | 56 | /*float*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F }, |
mcimadamore@792 | 57 | /*double*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F }, |
mcimadamore@792 | 58 | /*char*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F }, |
mcimadamore@792 | 59 | /*bool*/ { F , F , F , F , F , F , F , T , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F }, |
mcimadamore@792 | 60 | /*C*/ { F , F , F , F , F , F , F , F , T, F , T, T, F , F , F , F , F , F , F , F , F , F , F , F }, |
mcimadamore@792 | 61 | /*+C*/ { F , F , F , F , F , F , F , F , F, T , F, T, F , F , F , F , F , F , F , F , F , F , F , F }, |
mcimadamore@792 | 62 | /*I*/ { F , F , F , F , F , F , F , F , T, F , T, T, F , F , F , F , F , F , F , F , F , F , F , F }, |
mcimadamore@792 | 63 | /*T*/ { F , F , F , F , F , F , F , F , T, T , T, T, T , T , T , T , T , T , T , T , T , T , T , T }, |
mcimadamore@792 | 64 | /*byte[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, T , F , F , F , F , F , F , F , F , F , F , F }, |
mcimadamore@792 | 65 | /*short[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , T , F , F , F , F , F , F , F , F , F , F }, |
mcimadamore@792 | 66 | /*int[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , T , F , F , F , F , F , F , F , F , F }, |
mcimadamore@792 | 67 | /*long[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , T , F , F , F , F , F , F , F , F }, |
mcimadamore@792 | 68 | /*float[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , T , F , F , F , F , F , F , F }, |
mcimadamore@792 | 69 | /*double[]*/{ F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , T , F , F , F , F , F , F }, |
mcimadamore@792 | 70 | /*char[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , F , T , F , F , F , F , F }, |
mcimadamore@792 | 71 | /*bool[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , F , F , T , F , F , F , F }, |
mcimadamore@792 | 72 | /*C[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , F , F , F , T , F , T , T }, |
mcimadamore@792 | 73 | /*+C[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , F , F , F , F , T , F , T }, |
mcimadamore@792 | 74 | /*I[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , F , F , F , T , F , T , T }, |
mcimadamore@792 | 75 | /*T[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , F , F , F , T , T , T , T }}; |
mcimadamore@792 | 76 | |
mcimadamore@792 | 77 | CastTest() { |
mcimadamore@792 | 78 | Type[] primitiveTypes = { |
mcimadamore@792 | 79 | predef.byteType, |
mcimadamore@792 | 80 | predef.shortType, |
mcimadamore@792 | 81 | predef.intType, |
mcimadamore@792 | 82 | predef.longType, |
mcimadamore@792 | 83 | predef.floatType, |
mcimadamore@792 | 84 | predef.doubleType, |
mcimadamore@792 | 85 | predef.charType, |
mcimadamore@792 | 86 | predef.booleanType }; |
mcimadamore@792 | 87 | |
mcimadamore@792 | 88 | Type[] referenceTypes = { |
mcimadamore@792 | 89 | fac.Class(), |
mcimadamore@792 | 90 | fac.Class(FINAL), |
mcimadamore@792 | 91 | fac.Interface(), |
mcimadamore@792 | 92 | fac.TypeVariable() }; |
mcimadamore@792 | 93 | |
mcimadamore@792 | 94 | Type[] arrayTypes = new Type[primitiveTypes.length + referenceTypes.length]; |
mcimadamore@792 | 95 | int idx = 0; |
mcimadamore@792 | 96 | for (Type t : join(Type.class, primitiveTypes, referenceTypes)) { |
mcimadamore@792 | 97 | arrayTypes[idx++] = fac.Array(t); |
mcimadamore@792 | 98 | } |
mcimadamore@792 | 99 | |
mcimadamore@792 | 100 | allTypes = join(Type.class, primitiveTypes, referenceTypes, arrayTypes); |
mcimadamore@792 | 101 | } |
mcimadamore@792 | 102 | |
mcimadamore@792 | 103 | void test() { |
mcimadamore@792 | 104 | for (int i = 0; i < allTypes.length ; i++) { |
mcimadamore@792 | 105 | for (int j = 0; j < allTypes.length ; j++) { |
mcimadamore@792 | 106 | assertCastable(allTypes[i], allTypes[j], cast_result[i][j]); |
mcimadamore@792 | 107 | } |
mcimadamore@792 | 108 | } |
mcimadamore@792 | 109 | } |
mcimadamore@792 | 110 | |
mcimadamore@792 | 111 | @SuppressWarnings("unchecked") |
mcimadamore@792 | 112 | <T> T[] join(Class<T> type, T[]... args) { |
mcimadamore@792 | 113 | int totalLength = 0; |
mcimadamore@792 | 114 | for (T[] arr : args) { |
mcimadamore@792 | 115 | totalLength += arr.length; |
mcimadamore@792 | 116 | } |
mcimadamore@792 | 117 | T[] new_arr = (T[])Array.newInstance(type, totalLength); |
mcimadamore@792 | 118 | int idx = 0; |
mcimadamore@792 | 119 | for (T[] arr : args) { |
mcimadamore@792 | 120 | System.arraycopy(arr, 0, new_arr, idx, arr.length); |
mcimadamore@792 | 121 | idx += arr.length; |
mcimadamore@792 | 122 | } |
mcimadamore@792 | 123 | return new_arr; |
mcimadamore@792 | 124 | } |
mcimadamore@792 | 125 | |
mcimadamore@792 | 126 | public static void main(String[] args) { |
mcimadamore@792 | 127 | new CastTest().test(); |
mcimadamore@792 | 128 | } |
mcimadamore@792 | 129 | } |