author | akulyakh |
Thu, 21 May 2015 11:41:04 -0700 | |
changeset 30730 | d3ce7619db2c |
parent 20244 | d627dd086b41 |
permissions | -rw-r--r-- |
20244 | 1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
20244
diff
changeset
|
2 |
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
20244 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
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. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 8023835 |
|
27 |
* @summary Verify that TreeMaker.QualIdent(Symbol) field access cascade ends with |
|
28 |
* the top-level package (when no toplevel is set in TreeMaker) |
|
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
20244
diff
changeset
|
29 |
* @modules jdk.compiler/com.sun.tools.javac.api |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
20244
diff
changeset
|
30 |
* jdk.compiler/com.sun.tools.javac.code |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
20244
diff
changeset
|
31 |
* jdk.compiler/com.sun.tools.javac.tree |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
20244
diff
changeset
|
32 |
* jdk.compiler/com.sun.tools.javac.util |
20244 | 33 |
* @run main MakeQualIdent |
34 |
*/ |
|
35 |
||
36 |
import com.sun.source.tree.IdentifierTree; |
|
37 |
import com.sun.source.tree.MemberSelectTree; |
|
38 |
import com.sun.source.tree.Tree; |
|
39 |
import com.sun.source.util.JavacTask; |
|
40 |
import com.sun.source.util.TreeScanner; |
|
41 |
import com.sun.tools.javac.api.JavacTaskImpl; |
|
42 |
import com.sun.tools.javac.api.JavacTool; |
|
43 |
import com.sun.tools.javac.code.Symtab; |
|
44 |
import com.sun.tools.javac.tree.TreeMaker; |
|
45 |
import com.sun.tools.javac.util.Context; |
|
46 |
import java.util.ArrayList; |
|
47 |
||
48 |
public class MakeQualIdent { |
|
49 |
public static void main(String... args) throws Exception { |
|
50 |
JavacTool tool = JavacTool.create(); |
|
51 |
JavacTask task = tool.getTask(null, null, null, new ArrayList<String>(), null, null); |
|
52 |
Context ctx = ((JavacTaskImpl)task).getContext(); |
|
53 |
TreeMaker treeMaker = TreeMaker.instance(ctx); |
|
54 |
Symtab syms = Symtab.instance(ctx); |
|
55 |
||
56 |
String stringTree = printTree(treeMaker.QualIdent(syms.stringType.tsym)); |
|
57 |
||
58 |
if (!"java.lang.String".equals(stringTree)) { |
|
59 |
throw new IllegalStateException(stringTree); |
|
60 |
} |
|
61 |
} |
|
62 |
||
63 |
private static String printTree(Tree tree) { |
|
64 |
final StringBuilder result = new StringBuilder(); |
|
65 |
||
66 |
new TreeScanner<Void, Void>() { |
|
67 |
@Override public Void visitIdentifier(IdentifierTree node, Void p) { |
|
68 |
result.append(node.getName()); |
|
69 |
return super.visitIdentifier(node, p); |
|
70 |
} |
|
71 |
@Override public Void visitMemberSelect(MemberSelectTree node, Void p) { |
|
72 |
scan(node.getExpression(), null); |
|
73 |
result.append("."); |
|
74 |
result.append(node.getIdentifier()); |
|
75 |
return null; |
|
76 |
} |
|
77 |
}.scan(tree, null); |
|
78 |
||
79 |
return result.toString(); |
|
80 |
} |
|
81 |
} |