T6665791.java revision 553
0N/A/*
3845N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A */
0N/A
0N/A/*
1879N/A * @test
1879N/A * @bug 6665791
1879N/A * @summary com.sun.source.tree.MethodTree.toString() does not output default values
1879N/A */
0N/A
3845N/Aimport java.io.File;
3845N/Aimport java.io.IOException;
3845N/Aimport java.io.StringWriter;
3845N/Aimport javax.tools.JavaCompiler;
3845N/Aimport javax.tools.JavaFileObject;
3845N/Aimport javax.tools.StandardJavaFileManager;
3845N/Aimport javax.tools.ToolProvider;
3845N/Aimport com.sun.source.tree.ClassTree;
3845N/Aimport com.sun.source.util.JavacTask;
0N/Aimport com.sun.source.util.TreeScanner;
0N/Aimport java.io.FileWriter;
400N/A
0N/Apublic class T6665791 {
0N/A static String test = "public @interface Annotation { boolean booleanProperty() default false; }";
0N/A static File test_java = new File("Test.java");
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A write(test_java, test);
0N/A
0N/A JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
0N/A StandardJavaFileManager manager =
0N/A compiler.getStandardFileManager(null, null, null);
0N/A Iterable<? extends JavaFileObject> units = manager.getJavaFileObjects(test_java);
605N/A final StringWriter sw = new StringWriter();
0N/A JavacTask task = (JavacTask) compiler.getTask(sw, manager, null, null,
0N/A null, units);
0N/A
0N/A new TreeScanner<Boolean, Void>() {
0N/A @Override
0N/A public Boolean visitClass(ClassTree arg0, Void arg1) {
0N/A sw.write(arg0.toString());
0N/A return super.visitClass(arg0, arg1);
0N/A }
0N/A }.scan(task.parse(), null);
0N/A
0N/A System.out.println("output:");
0N/A System.out.println(sw.toString());
0N/A String found = sw.toString().replaceAll("\\s+", " ").trim();
0N/A String expect = test.replaceAll("\\s+", " ").trim();
0N/A if (!expect.equals(found)) {
0N/A System.out.println("expect: " + expect);
0N/A System.out.println("found: " + found);
0N/A throw new Exception("unexpected output");
0N/A }
0N/A }
0N/A
0N/A static void write(File file, String body) throws IOException {
2767N/A FileWriter out = new FileWriter(file);
2767N/A out.write(body);
2767N/A out.close();
2767N/A }
2767N/A}
2767N/A