author | akulyakh |
Thu, 21 May 2015 11:41:04 -0700 | |
changeset 30730 | d3ce7619db2c |
parent 27319 | 030080f03e4f |
permissions | -rw-r--r-- |
6587
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
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. |
6587
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
4 |
* |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
8 |
* |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
13 |
* accompanied this code). |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
14 |
* |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
18 |
* |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
21 |
* questions. |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
22 |
*/ |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
23 |
|
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
24 |
/* |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
25 |
* @test |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
26 |
* @bug 6956462 |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
27 |
* @summary AssertionError exception throws in the Compiler Tree API in JDK 7. |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
28 |
* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
29 |
* @modules jdk.compiler |
6587
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
30 |
* @build TestClass T6956462 |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
31 |
* @run main T6956462 |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
32 |
*/ |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
33 |
|
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
34 |
import java.io.*; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
35 |
import java.net.URISyntaxException; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
36 |
import java.util.*; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
37 |
import javax.tools.*; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
38 |
import javax.tools.JavaCompiler.CompilationTask; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
39 |
import com.sun.source.tree.*; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
40 |
import com.sun.source.util.*; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
41 |
|
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
42 |
public class T6956462 { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
43 |
public static void main(String[] args) throws Exception { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
44 |
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
45 |
if (compiler == null) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
46 |
throw new RuntimeException("can't get javax.tools.JavaCompiler!"); |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
47 |
} |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6587
diff
changeset
|
48 |
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6587
diff
changeset
|
49 |
List<File> files = new ArrayList<File>(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6587
diff
changeset
|
50 |
files.add(new File(T6956462.class.getResource("TestClass.java").toURI())); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6587
diff
changeset
|
51 |
final CompilationTask task = compiler.getTask(null, fm, null, |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6587
diff
changeset
|
52 |
null, null, fm.getJavaFileObjectsFromFiles(files)); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6587
diff
changeset
|
53 |
JavacTask javacTask = (JavacTask) task; |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6587
diff
changeset
|
54 |
for (CompilationUnitTree cu : javacTask.parse()) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6587
diff
changeset
|
55 |
cu.accept(new MyVisitor(javacTask), null); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6587
diff
changeset
|
56 |
} |
6587
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
57 |
} |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
58 |
} |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
59 |
|
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
60 |
private static class MyVisitor extends SimpleTreeVisitor<Tree, Void> { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
61 |
private final Trees trees; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
62 |
private CompilationUnitTree file; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
63 |
|
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
64 |
private MyVisitor(JavacTask javac) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
65 |
this.trees = Trees.instance(javac); |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
66 |
} |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
67 |
|
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
68 |
@Override |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
69 |
public Tree visitCompilationUnit(CompilationUnitTree file, Void v) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
70 |
this.file = file; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
71 |
for (Tree typeDecl : file.getTypeDecls()) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
72 |
typeDecl.accept(this, v); |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
73 |
} |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
74 |
return null; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
75 |
} |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
76 |
|
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
77 |
@Override |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
78 |
public Tree visitImport(ImportTree imp, Void v) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
79 |
return null; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
80 |
} |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
81 |
|
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
82 |
@Override |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
83 |
public Tree visitMethodInvocation(MethodInvocationTree invoke, Void v) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
84 |
invoke.getMethodSelect().accept(this, v); |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
85 |
return null; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
86 |
} |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
87 |
|
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
88 |
@Override |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
89 |
public Tree visitBlock(BlockTree block, Void v) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
90 |
for (StatementTree stat : block.getStatements()) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
91 |
stat.accept(this, v); |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
92 |
} |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
93 |
return null; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
94 |
} |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
95 |
|
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
96 |
@Override |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
97 |
public Tree visitClass(ClassTree clazz, Void v) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
98 |
for (Tree member : clazz.getMembers()) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
99 |
member.accept(this, v); |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
100 |
} |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
101 |
return null; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
102 |
} |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
103 |
|
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
104 |
@Override |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
105 |
public Tree visitIdentifier(IdentifierTree ident, Void v) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
106 |
trees.getScope(trees.getPath(file, ident)); |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
107 |
return null; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
108 |
} |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
109 |
|
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
110 |
@Override |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
111 |
public Tree visitMethod(MethodTree method, Void v) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
112 |
method.getBody().accept(this, v); |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
113 |
return null; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
114 |
} |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
115 |
|
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
116 |
@Override |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
117 |
public Tree visitMemberSelect(MemberSelectTree select, Void v) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
118 |
select.getExpression().accept(this, v); |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
119 |
return null; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
120 |
} |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
121 |
|
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
122 |
@Override |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
123 |
public Tree visitVariable(VariableTree var, Void v) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
124 |
var.getInitializer().accept(this, v); |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
125 |
return null; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
126 |
} |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
127 |
} |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
diff
changeset
|
128 |
} |