author | lana |
Thu, 21 Jan 2016 09:46:01 -0800 | |
changeset 35340 | 38f7386ed942 |
parent 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
4696
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
2 |
* Copyright (c) 2010, 2015, 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 |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
28 |
* @modules jdk.compiler |
4696
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 |
|
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
31 |
import java.io.File; |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
32 |
import java.io.IOException; |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
33 |
import java.io.StringWriter; |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
34 |
import javax.tools.JavaCompiler; |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
35 |
import javax.tools.JavaFileObject; |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
36 |
import javax.tools.StandardJavaFileManager; |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
37 |
import javax.tools.ToolProvider; |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
38 |
import com.sun.source.tree.ClassTree; |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
39 |
import com.sun.source.util.JavacTask; |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
40 |
import com.sun.source.util.TreeScanner; |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
41 |
import java.io.FileWriter; |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
42 |
|
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
43 |
public class T6665791 { |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
44 |
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
|
45 |
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
|
46 |
|
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
47 |
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
|
48 |
write(test_java, test); |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
49 |
|
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
50 |
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
51 |
try (StandardJavaFileManager manager = |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
52 |
compiler.getStandardFileManager(null, null, null)) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
53 |
Iterable<? extends JavaFileObject> units = manager.getJavaFileObjects(test_java); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
54 |
final StringWriter sw = new StringWriter(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
55 |
JavacTask task = (JavacTask) compiler.getTask(sw, manager, null, null, |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
56 |
null, units); |
4696
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
57 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
58 |
new TreeScanner<Boolean, Void>() { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
59 |
@Override |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
60 |
public Boolean visitClass(ClassTree arg0, Void arg1) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
61 |
sw.write(arg0.toString()); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
62 |
return super.visitClass(arg0, arg1); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
63 |
} |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
64 |
}.scan(task.parse(), null); |
4696
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
65 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
66 |
System.out.println("output:"); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
67 |
System.out.println(sw.toString()); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
68 |
String found = sw.toString().replaceAll("\\s+", " ").trim(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
69 |
String expect = test.replaceAll("\\s+", " ").trim(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
70 |
if (!expect.equals(found)) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
71 |
System.out.println("expect: " + expect); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
72 |
System.out.println("found: " + found); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
73 |
throw new Exception("unexpected output"); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
74 |
} |
4696
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 |
} |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
77 |
|
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
78 |
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
|
79 |
FileWriter out = new FileWriter(file); |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
80 |
out.write(body); |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
81 |
out.close(); |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
82 |
} |
45b45d9c96dd
6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents:
diff
changeset
|
83 |
} |