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