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