author | akulyakh |
Thu, 21 May 2015 11:41:04 -0700 | |
changeset 30730 | d3ce7619db2c |
parent 8842 | d532916921b7 |
child 34752 | 9c262a013456 |
permissions | -rw-r--r-- |
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
8842
diff
changeset
|
2 |
* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. |
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
4 |
* |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
8 |
* |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
14 |
* |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
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. |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
22 |
*/ |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
23 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
24 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
25 |
/* |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
26 |
* @test |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
27 |
* @bug 6557752 |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
28 |
* @summary Test for wrapping the original type in ErrorType. |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
29 |
* @library ../lib |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
8842
diff
changeset
|
30 |
* @modules jdk.compiler/com.sun.tools.javac.util |
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
31 |
* @compile T6557752.java |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
32 |
* @run main T6557752 |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
33 |
*/ |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
34 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
35 |
import com.sun.source.tree.AssignmentTree; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
36 |
import com.sun.source.tree.CompilationUnitTree; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
37 |
import com.sun.source.tree.MethodInvocationTree; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
38 |
import com.sun.source.util.JavacTask; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
39 |
import com.sun.source.util.TreePath; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
40 |
import com.sun.source.util.TreePathScanner; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
41 |
import com.sun.source.util.Trees; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
42 |
import com.sun.tools.javac.api.JavacTaskImpl; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
43 |
import com.sun.tools.javac.util.List; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
44 |
import java.io.IOException; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
45 |
import java.net.URI; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
46 |
import javax.lang.model.type.ErrorType; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
47 |
import javax.lang.model.type.TypeKind; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
48 |
import javax.lang.model.type.TypeMirror; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
49 |
import javax.tools.JavaCompiler; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
50 |
import javax.tools.JavaFileObject; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
51 |
import javax.tools.SimpleJavaFileObject; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
52 |
import javax.tools.ToolProvider; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
53 |
import javax.lang.model.util.Types; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
54 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
55 |
public class T6557752 { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
56 |
static class MyFileObject extends SimpleJavaFileObject { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
57 |
public MyFileObject() { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
58 |
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
59 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
60 |
public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
61 |
return "import java.util.*;\n" |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
62 |
+ "public class Test {\n" |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
63 |
+ " void foobar() {\n" |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
64 |
+ " Iterator<Number> itr = null;\n" |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
65 |
+ " String str = itr.next();\n" |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
66 |
+ " FooBar fooBar = FooBar.foobar();\n" |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
67 |
+ " }\n" |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
68 |
+ "}"; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
69 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
70 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
71 |
static Trees trees; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
72 |
static JavacTask task = null; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
73 |
public static void main(String[] args) throws IOException { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
74 |
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
75 |
task = (JavacTask) compiler.getTask(null, null, null, null, null, List.of(new MyFileObject())); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
76 |
Iterable<? extends CompilationUnitTree> asts = task.parse(); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
77 |
task.analyze(); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
78 |
trees = Trees.instance(task); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
79 |
MyVisitor myVisitor = new MyVisitor(); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
80 |
for (CompilationUnitTree ast : asts) { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
81 |
myVisitor.compilationUnit = ast; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
82 |
myVisitor.scan(ast, null); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
83 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
84 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
85 |
if (!myVisitor.foundError) { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
86 |
throw new AssertionError("Expected error not found!"); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
87 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
88 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
89 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
90 |
static class MyVisitor extends TreePathScanner<Void,Void> { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
91 |
public boolean foundError = false; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
92 |
CompilationUnitTree compilationUnit = null; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
93 |
int i = 0; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
94 |
@Override |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
95 |
public Void visitMethodInvocation(MethodInvocationTree node, Void ignored) { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
96 |
TreePath path = TreePath.getPath(compilationUnit, node); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
97 |
TypeMirror typeMirror = trees.getTypeMirror(path); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
98 |
if (typeMirror.getKind() == TypeKind.ERROR) { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
99 |
if (i == 0) { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
100 |
String str1 = trees.getOriginalType((ErrorType)typeMirror).toString(); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
101 |
if (!str1.equals("java.lang.Number")) { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
102 |
throw new AssertionError("Trees.getOriginalType() error!"); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
103 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
104 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
105 |
Types types = task.getTypes(); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
106 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
107 |
str1 = types.asElement(trees.getOriginalType((ErrorType)typeMirror)).toString(); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
108 |
if (!str1.equals("java.lang.Number")) { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
109 |
throw new AssertionError("Types.asElement() error!"); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
110 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
111 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
112 |
i++; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
113 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
114 |
else if (i == 1) { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
115 |
String str1 = trees.getOriginalType((ErrorType)typeMirror).toString(); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
116 |
if (!str1.equals("FooBar")) { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
117 |
throw new AssertionError("Trees.getOriginalType() error!"); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
118 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
119 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
120 |
Types types = task.getTypes(); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
121 |
|
8842 | 122 |
str1 = types.asElement(trees.getOriginalType((ErrorType)typeMirror)).toString(); |
123 |
if (!str1.equals("FooBar")) { |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
5520
diff
changeset
|
124 |
throw new AssertionError("Types.asElement() error!"); |
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
125 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
126 |
foundError = true; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
127 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
128 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
129 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
130 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
131 |
return null; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
132 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
133 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
134 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
diff
changeset
|
135 |
} |