Mon, 13 Dec 2010 15:11:00 -0800
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
Reviewed-by: jjg, darcy
jjg@461 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
jjg@461 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@461 | 4 | * |
jjg@461 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@461 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@461 | 7 | * published by the Free Software Foundation. |
jjg@461 | 8 | * |
jjg@461 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@461 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@461 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@461 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@461 | 13 | * accompanied this code). |
jjg@461 | 14 | * |
jjg@461 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@461 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@461 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@461 | 18 | * |
ohair@554 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 20 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 21 | * questions. |
jjg@461 | 22 | */ |
jjg@461 | 23 | |
jjg@461 | 24 | /* |
jjg@461 | 25 | * @test |
jjg@461 | 26 | * @bug 6665791 |
jjg@461 | 27 | * @summary com.sun.source.tree.MethodTree.toString() does not output default values |
jjg@461 | 28 | */ |
jjg@461 | 29 | |
jjg@461 | 30 | import java.io.File; |
jjg@461 | 31 | import java.io.IOException; |
jjg@461 | 32 | import java.io.StringWriter; |
jjg@461 | 33 | import javax.tools.JavaCompiler; |
jjg@461 | 34 | import javax.tools.JavaFileObject; |
jjg@461 | 35 | import javax.tools.StandardJavaFileManager; |
jjg@461 | 36 | import javax.tools.ToolProvider; |
jjg@461 | 37 | import com.sun.source.tree.ClassTree; |
jjg@461 | 38 | import com.sun.source.util.JavacTask; |
jjg@461 | 39 | import com.sun.source.util.TreeScanner; |
jjg@461 | 40 | import java.io.FileWriter; |
jjg@461 | 41 | |
jjg@461 | 42 | public class T6665791 { |
jjg@461 | 43 | static String test = "public @interface Annotation { boolean booleanProperty() default false; }"; |
jjg@461 | 44 | static File test_java = new File("Test.java"); |
jjg@461 | 45 | |
jjg@461 | 46 | public static void main(String[] args) throws Exception { |
jjg@461 | 47 | write(test_java, test); |
jjg@461 | 48 | |
jjg@461 | 49 | JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
jjg@461 | 50 | StandardJavaFileManager manager = |
jjg@461 | 51 | compiler.getStandardFileManager(null, null, null); |
jjg@461 | 52 | Iterable<? extends JavaFileObject> units = manager.getJavaFileObjects(test_java); |
jjg@461 | 53 | final StringWriter sw = new StringWriter(); |
jjg@461 | 54 | JavacTask task = (JavacTask) compiler.getTask(sw, manager, null, null, |
jjg@461 | 55 | null, units); |
jjg@461 | 56 | |
jjg@461 | 57 | new TreeScanner<Boolean, Void>() { |
jjg@461 | 58 | @Override |
jjg@461 | 59 | public Boolean visitClass(ClassTree arg0, Void arg1) { |
jjg@461 | 60 | sw.write(arg0.toString()); |
jjg@461 | 61 | return super.visitClass(arg0, arg1); |
jjg@461 | 62 | } |
jjg@461 | 63 | }.scan(task.parse(), null); |
jjg@461 | 64 | |
jjg@461 | 65 | System.out.println("output:"); |
jjg@461 | 66 | System.out.println(sw.toString()); |
jjg@461 | 67 | String found = sw.toString().replaceAll("\\s+", " ").trim(); |
jjg@461 | 68 | String expect = test.replaceAll("\\s+", " ").trim(); |
jjg@461 | 69 | if (!expect.equals(found)) { |
jjg@461 | 70 | System.out.println("expect: " + expect); |
jjg@461 | 71 | System.out.println("found: " + found); |
jjg@461 | 72 | throw new Exception("unexpected output"); |
jjg@461 | 73 | } |
jjg@461 | 74 | } |
jjg@461 | 75 | |
jjg@461 | 76 | static void write(File file, String body) throws IOException { |
jjg@461 | 77 | FileWriter out = new FileWriter(file); |
jjg@461 | 78 | out.write(body); |
jjg@461 | 79 | out.close(); |
jjg@461 | 80 | } |
jjg@461 | 81 | } |