author | akulyakh |
Thu, 21 May 2015 11:41:04 -0700 | |
changeset 30730 | d3ce7619db2c |
parent 19246 | 4c6990756cd3 |
permissions | -rw-r--r-- |
19246
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
19246
diff
changeset
|
2 |
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
19246
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
4 |
* |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
8 |
* |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
13 |
* accompanied this code). |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
14 |
* |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
18 |
* |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
21 |
* questions. |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
22 |
*/ |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
23 |
|
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
24 |
/* |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
25 |
* @test |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
26 |
* @bug 8014826 |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
27 |
* @summary test Pretty print of NewArray |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
28 |
* @author ksrini |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
19246
diff
changeset
|
29 |
* @modules jdk.compiler/com.sun.tools.javac.api |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
19246
diff
changeset
|
30 |
* jdk.compiler/com.sun.tools.javac.tree |
19246
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
31 |
*/ |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
32 |
import com.sun.source.tree.ClassTree; |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
33 |
import com.sun.source.tree.CompilationUnitTree; |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
34 |
import com.sun.tools.javac.api.JavacTaskImpl; |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
35 |
import com.sun.tools.javac.tree.JCTree; |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
36 |
import java.io.IOException; |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
37 |
import java.net.URI; |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
38 |
import java.util.Arrays; |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
39 |
import javax.tools.JavaCompiler; |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
40 |
import javax.tools.JavaFileObject; |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
41 |
import javax.tools.SimpleJavaFileObject; |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
42 |
import javax.tools.ToolProvider; |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
43 |
|
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
44 |
public class NewArrayPretty { |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
45 |
private final JavaCompiler tool; |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
46 |
NewArrayPretty() { |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
47 |
tool = ToolProvider.getSystemJavaCompiler(); |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
48 |
} |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
49 |
public static void main(String... args) throws Exception { |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
50 |
NewArrayPretty nap = new NewArrayPretty(); |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
51 |
nap.run("Class[] cls = null"); |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
52 |
nap.run("Class[] cls = new Class[]{Object.class}"); |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
53 |
} |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
54 |
void run(String code) throws IOException { |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
55 |
String src = "public class Test {" + code + ";}"; |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
56 |
|
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
57 |
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
58 |
null, Arrays.asList(new MyFileObject(src))); |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
59 |
|
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
60 |
for (CompilationUnitTree cut : ct.parse()) { |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
61 |
JCTree.JCVariableDecl var = |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
62 |
(JCTree.JCVariableDecl) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0); |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
63 |
|
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
64 |
if (!code.equals(var.toString())) { |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
65 |
System.err.println("Expected: " + code); |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
66 |
System.err.println("Obtained: " + var.toString()); |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
67 |
throw new RuntimeException("strings do not match!"); |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
68 |
} |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
69 |
} |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
70 |
} |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
71 |
} |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
72 |
class MyFileObject extends SimpleJavaFileObject { |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
73 |
|
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
74 |
private String text; |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
75 |
|
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
76 |
public MyFileObject(String text) { |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
77 |
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
78 |
this.text = text; |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
79 |
} |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
80 |
|
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
81 |
@Override |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
82 |
public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
83 |
return text; |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
84 |
} |
4c6990756cd3
8014826: c.s.t.javac.tree.Pretty.visitNewArray() prints duplicate dimension markers
ksrini
parents:
diff
changeset
|
85 |
} |