author | vasya |
Mon, 14 Dec 2015 20:18:19 +0100 | |
changeset 34752 | 9c262a013456 |
parent 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
6580
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
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. |
6580
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
4 |
* |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
8 |
* |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
14 |
* |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
18 |
* |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
21 |
* questions. |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
22 |
*/ |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
23 |
|
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
24 |
/* |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
25 |
* @test |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
26 |
* @bug 6570730 |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
27 |
* @summary com.sun.source.tree.ModifiersTree.getFlags() should return class type |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
28 |
* @modules jdk.compiler/com.sun.tools.javac.api |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
29 |
* jdk.compiler/com.sun.tools.javac.file |
6580
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
30 |
*/ |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
31 |
|
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
32 |
import java.io.*; |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
33 |
import java.util.*; |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
34 |
import javax.tools.*; |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
35 |
import com.sun.source.tree.*; |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
36 |
import com.sun.source.util.*; |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
37 |
import com.sun.tools.javac.api.*; |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
38 |
|
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
39 |
public class ClassTreeTest { |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
40 |
public static void main(String... args) throws Exception { |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
41 |
new ClassTreeTest().run(); |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
42 |
} |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
43 |
|
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
44 |
void run() throws Exception { |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
45 |
JavacTool tool = JavacTool.create(); |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6580
diff
changeset
|
46 |
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6580
diff
changeset
|
47 |
List<String> opts = Collections.<String>emptyList(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6580
diff
changeset
|
48 |
File testSrc = new File(System.getProperty("test.src")); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6580
diff
changeset
|
49 |
File thisFile = new File(testSrc, ClassTreeTest.class.getSimpleName() + ".java"); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6580
diff
changeset
|
50 |
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(thisFile); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6580
diff
changeset
|
51 |
JavacTask task = tool.getTask(null, fm, null, opts, null, fos); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6580
diff
changeset
|
52 |
for (CompilationUnitTree cu: task.parse()) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6580
diff
changeset
|
53 |
check(cu, "CLASS", Tree.Kind.CLASS); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6580
diff
changeset
|
54 |
check(cu, "INTERFACE", Tree.Kind.INTERFACE); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6580
diff
changeset
|
55 |
check(cu, "ENUM", Tree.Kind.ENUM); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6580
diff
changeset
|
56 |
check(cu, "ANNOTATION_TYPE", Tree.Kind.ANNOTATION_TYPE); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6580
diff
changeset
|
57 |
} |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6580
diff
changeset
|
58 |
|
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6580
diff
changeset
|
59 |
int expected = 4; |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6580
diff
changeset
|
60 |
if (checks != expected) |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6580
diff
changeset
|
61 |
error("Unexpected number of checks performed; expected: " + expected + ", found: " + checks); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6580
diff
changeset
|
62 |
|
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6580
diff
changeset
|
63 |
if (errors > 0) |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6580
diff
changeset
|
64 |
throw new Exception(errors + " errors found"); |
6580
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
65 |
} |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
66 |
} |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
67 |
|
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
68 |
void check(CompilationUnitTree cu, String name, Tree.Kind k) { |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
69 |
checks++; |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
70 |
|
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
71 |
TreeScanner<ClassTree,String> s = new TreeScanner<ClassTree,String>() { |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
72 |
@Override |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
73 |
public ClassTree visitClass(ClassTree c, String name) { |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
74 |
if (c.getSimpleName().toString().equals(name)) |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
75 |
return c; |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
76 |
else |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
77 |
return super.visitClass(c, name); |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
78 |
} |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
79 |
|
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
80 |
@Override |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
81 |
public ClassTree reduce(ClassTree t1, ClassTree t2) { |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
82 |
return (t1 != null ? t1 : t2); |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
83 |
} |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
84 |
}; |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
85 |
|
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
86 |
ClassTree c = s.scan(cu, name); |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
87 |
if (c == null) |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
88 |
error("Can't find node named " + name); |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
89 |
else if (c.getKind() != k) |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
90 |
error("Unexpected kind for node named " + name + ": expected: " + k + ", found: " + c.getKind()); |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
91 |
} |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
92 |
|
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
93 |
void error(String msg) { |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
94 |
System.err.println("Error: " + msg); |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
95 |
errors++; |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
96 |
} |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
97 |
|
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
98 |
int checks; |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
99 |
int errors; |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
100 |
|
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
101 |
class CLASS { } |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
102 |
interface INTERFACE { } |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
103 |
enum ENUM { } |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
104 |
@interface ANNOTATION_TYPE { } |
d3d578d22cc7
6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents:
diff
changeset
|
105 |
} |