author | darcy |
Fri, 02 Feb 2018 10:29:25 -0800 | |
changeset 48723 | 6cb86bf0b51e |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
33915
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
1 |
/* |
36526 | 2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
33915
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
4 |
* |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
8 |
* |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
13 |
* accompanied this code). |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
14 |
* |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
18 |
* |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
21 |
* questions. |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
22 |
*/ |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
23 |
|
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
24 |
/* |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
25 |
* @test |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
26 |
* @bug 8142931 |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
27 |
* @summary java compiler: type erasure doesn't work since 9-b28 |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
28 |
* @modules jdk.compiler/com.sun.tools.javac.api |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
29 |
* jdk.compiler/com.sun.tools.javac.file |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
30 |
*/ |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
31 |
|
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
32 |
import java.io.*; |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
33 |
import java.util.*; |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
34 |
import javax.annotation.processing.*; |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
35 |
import javax.lang.model.*; |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
36 |
import javax.lang.model.element.*; |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
37 |
import javax.lang.model.util.ElementFilter; |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
38 |
import javax.lang.model.type.TypeMirror; |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
39 |
import javax.lang.model.type.DeclaredType; |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
40 |
import javax.tools.*; |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
41 |
import com.sun.source.util.*; |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
42 |
import com.sun.tools.javac.api.*; |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
43 |
|
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
44 |
@SupportedAnnotationTypes("*") |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
45 |
public class T8142931 extends AbstractProcessor { |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
46 |
|
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
47 |
public java.util.List<? extends javax.xml.namespace.QName> f0; |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
48 |
|
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
49 |
public static void main(String... args) throws IOException { |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
50 |
String testSrc = System.getProperty("test.src", "."); |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
51 |
String testClasses = System.getProperty("test.classes"); |
36526 | 52 |
JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); |
33915
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
53 |
MyDiagListener dl = new MyDiagListener(); |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
54 |
try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) { |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
55 |
Iterable<? extends JavaFileObject> files = |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
56 |
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T8142931.class.getName()+".java"))); |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
57 |
Iterable<String> opts = Arrays.asList( |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
58 |
"--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
59 |
"-XDaccessInternalAPI", |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
60 |
"-proc:only", |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
61 |
"-processor", "T8142931", |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36526
diff
changeset
|
62 |
"-processorpath", testClasses); |
33915
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
63 |
StringWriter out = new StringWriter(); |
36526 | 64 |
JavacTask task = (JavacTask)tool.getTask(out, fm, dl, opts, null, files); |
33915
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
65 |
task.call(); |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
66 |
String s = out.toString(); |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
67 |
System.err.print(s); |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
68 |
System.err.println(dl.count + " diagnostics; " + s.length() + " characters"); |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
69 |
if (dl.count != 0 || s.length() != 0) |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
70 |
throw new AssertionError("unexpected output from compiler"); |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
71 |
} |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
72 |
} |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
73 |
|
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
74 |
@Override |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
75 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
76 |
Set<? extends Element> set = roundEnv.getRootElements(); |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
77 |
for (Element element : set) { |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
78 |
Collection<VariableElement> fields = ElementFilter.fieldsIn(((TypeElement) element).getEnclosedElements()); |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
79 |
for (VariableElement field : fields) { |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
80 |
TypeMirror listType = field.asType(); |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
81 |
List<? extends TypeMirror> typeArgs = ((DeclaredType) listType).getTypeArguments(); |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
82 |
TypeMirror arg = typeArgs.get(0); |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
83 |
String erasure = processingEnv.getTypeUtils().erasure(arg).toString(); |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
84 |
if (!erasure.equals("javax.xml.namespace.QName")) |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
85 |
throw new AssertionError("Wrong Erasure: " + erasure); |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
86 |
} |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
87 |
} |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
88 |
return false; |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
89 |
} |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
90 |
|
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
91 |
@Override |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
92 |
public SourceVersion getSupportedSourceVersion() { |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
93 |
return SourceVersion.latest(); |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
94 |
} |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
95 |
|
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
96 |
static class MyDiagListener implements DiagnosticListener { |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
97 |
public void report(Diagnostic d) { |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
98 |
System.err.println(d); |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
99 |
count++; |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
100 |
} |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
101 |
|
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
102 |
public int count; |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
diff
changeset
|
103 |
} |
36526 | 104 |
} |
105 |