Mon, 13 Dec 2010 15:11:00 -0800
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
Reviewed-by: jjg, darcy
jjg@10 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. |
jjg@10 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@10 | 4 | * |
jjg@10 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@10 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
jjg@10 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
jjg@10 | 10 | * |
jjg@10 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@10 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@10 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@10 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@10 | 15 | * accompanied this code). |
jjg@10 | 16 | * |
jjg@10 | 17 | * You should have received a copy of the GNU General Public License version |
jjg@10 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@10 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@10 | 20 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
jjg@10 | 24 | */ |
jjg@10 | 25 | |
jjg@10 | 26 | /* |
jjg@10 | 27 | * @test |
jjg@10 | 28 | * @bug 6668802 |
jjg@10 | 29 | * @summary javac handles diagnostics for last line badly, if line not terminated by newline |
jjg@10 | 30 | */ |
jjg@10 | 31 | |
jjg@10 | 32 | import java.io.*; |
jjg@10 | 33 | import java.util.*; |
jjg@10 | 34 | |
jjg@10 | 35 | public class T6668802 |
jjg@10 | 36 | { |
jjg@10 | 37 | public static void main(String[] args) throws Exception { |
jjg@10 | 38 | new T6668802().run(); |
jjg@10 | 39 | } |
jjg@10 | 40 | |
jjg@10 | 41 | void run() throws Exception { |
jjg@10 | 42 | String test = "public class Test {"; |
jjg@10 | 43 | File f = writeTestFile("Test.java", test); |
jjg@10 | 44 | String[] out = compileBadFile(f); |
jjg@10 | 45 | for (String line: out) |
jjg@10 | 46 | System.err.println(">>>" + line + "<<<"); |
jjg@10 | 47 | if (!out[1].equals(test)) { |
jjg@10 | 48 | show("expected", test); |
jjg@10 | 49 | show(" actual", out[1]); |
jjg@10 | 50 | throw new Error("test failed"); |
jjg@10 | 51 | } |
jjg@10 | 52 | } |
jjg@10 | 53 | |
jjg@10 | 54 | File writeTestFile(String path, String contents) throws IOException { |
jjg@10 | 55 | File f = new File(path); |
jjg@10 | 56 | FileWriter out = new FileWriter(f); |
jjg@10 | 57 | out.write(contents); |
jjg@10 | 58 | out.close(); |
jjg@10 | 59 | return f; |
jjg@10 | 60 | } |
jjg@10 | 61 | |
jjg@10 | 62 | String[] compileBadFile(File file) throws IOException { |
jjg@10 | 63 | List<String> options = new ArrayList<String>(); |
jjg@10 | 64 | options.add(file.getPath()); |
jjg@10 | 65 | System.err.println("compile: " + options); |
jjg@10 | 66 | String[] opts = options.toArray(new String[options.size()]); |
jjg@10 | 67 | StringWriter sw = new StringWriter(); |
jjg@10 | 68 | PrintWriter out = new PrintWriter(sw); |
jjg@10 | 69 | int rc = com.sun.tools.javac.Main.compile(opts, out); |
jjg@10 | 70 | if (rc == 0) |
jjg@10 | 71 | throw new Error("compilation succeeded unexpectedly"); |
jjg@10 | 72 | out.close(); |
jjg@10 | 73 | return sw.toString().split("[\n\r]+"); |
jjg@10 | 74 | } |
jjg@10 | 75 | |
jjg@10 | 76 | void show(String prefix, String text) { |
jjg@10 | 77 | System.err.println(prefix + ": (" + text.length() + ") " + text); |
jjg@10 | 78 | } |
jjg@10 | 79 | } |