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