T8142931.java revision 3573:c4a18ee691c4
134355Sjb/* 234355Sjb * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. 389985Sbde * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4112902Sjeff * 534355Sjb * This code is free software; you can redistribute it and/or modify it 634355Sjb * under the terms of the GNU General Public License version 2 only, as 764002Speter * published by the Free Software Foundation. 834355Sjb * 934355Sjb * This code is distributed in the hope that it will be useful, but WITHOUT 1034355Sjb * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1134355Sjb * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1234355Sjb * version 2 for more details (a copy is included in the LICENSE file that 1334355Sjb * accompanied this code). 1434355Sjb * 1534355Sjb * You should have received a copy of the GNU General Public License version 1634355Sjb * 2 along with this work; if not, write to the Free Software Foundation, 1734355Sjb * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1834355Sjb * 1934355Sjb * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2034355Sjb * or visit www.oracle.com if you need additional information or have any 2134355Sjb * questions. 2234355Sjb */ 2334355Sjb 2434355Sjb/* 2534355Sjb * @test 2634355Sjb * @bug 8142931 2734355Sjb * @summary java compiler: type erasure doesn't work since 9-b28 2834355Sjb * @modules jdk.compiler/com.sun.tools.javac.api 2934355Sjb * jdk.compiler/com.sun.tools.javac.file 3034355Sjb */ 3134355Sjb 3234355Sjbimport java.io.*; 3334355Sjbimport java.util.*; 3434355Sjbimport javax.annotation.processing.*; 3534355Sjbimport javax.lang.model.*; 3634355Sjbimport javax.lang.model.element.*; 3734355Sjbimport javax.lang.model.util.ElementFilter; 3834355Sjbimport javax.lang.model.type.TypeMirror; 3934355Sjbimport javax.lang.model.type.DeclaredType; 4034355Sjbimport javax.tools.*; 4134355Sjbimport com.sun.source.util.*; 4234355Sjbimport com.sun.tools.javac.api.*; 4334355Sjb 4434355Sjb@SupportedAnnotationTypes("*") 4534355Sjbpublic class T8142931 extends AbstractProcessor { 4634355Sjb 4734355Sjb public java.util.List<? extends javax.xml.namespace.QName> f0; 4834355Sjb 4934355Sjb public static void main(String... args) throws IOException { 5034355Sjb String testSrc = System.getProperty("test.src", "."); 5134355Sjb String testClasses = System.getProperty("test.classes"); 5234355Sjb JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); 5334355Sjb MyDiagListener dl = new MyDiagListener(); 5434355Sjb try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) { 5534355Sjb Iterable<? extends JavaFileObject> files = 5634355Sjb fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T8142931.class.getName()+".java"))); 5734355Sjb Iterable<String> opts = Arrays.asList( 5834355Sjb "--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", 5934355Sjb "-XDaccessInternalAPI", 6034355Sjb "-proc:only", 6134355Sjb "-processor", "T8142931", 6234355Sjb "-processorpath", testClasses); 6334355Sjb StringWriter out = new StringWriter(); 6434355Sjb JavacTask task = (JavacTask)tool.getTask(out, fm, dl, opts, null, files); 6534355Sjb task.call(); 6634355Sjb String s = out.toString(); 6734355Sjb System.err.print(s); 6834355Sjb System.err.println(dl.count + " diagnostics; " + s.length() + " characters"); 6934355Sjb if (dl.count != 0 || s.length() != 0) 7034355Sjb throw new AssertionError("unexpected output from compiler"); 7134355Sjb } 7234355Sjb } 7334355Sjb 7434355Sjb @Override 7534355Sjb public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 7634355Sjb Set<? extends Element> set = roundEnv.getRootElements(); 7734355Sjb for (Element element : set) { 7834355Sjb Collection<VariableElement> fields = ElementFilter.fieldsIn(((TypeElement) element).getEnclosedElements()); 7934355Sjb for (VariableElement field : fields) { 8034355Sjb TypeMirror listType = field.asType(); 8134355Sjb List<? extends TypeMirror> typeArgs = ((DeclaredType) listType).getTypeArguments(); 8234355Sjb TypeMirror arg = typeArgs.get(0); 8334355Sjb String erasure = processingEnv.getTypeUtils().erasure(arg).toString(); 8434355Sjb if (!erasure.equals("javax.xml.namespace.QName")) 8534355Sjb throw new AssertionError("Wrong Erasure: " + erasure); 8634355Sjb } 8734355Sjb } 8834355Sjb return false; 8934355Sjb } 9034355Sjb 9134355Sjb @Override 9234355Sjb public SourceVersion getSupportedSourceVersion() { 9334355Sjb return SourceVersion.latest(); 9434355Sjb } 9534355Sjb 9634355Sjb static class MyDiagListener implements DiagnosticListener { 9734355Sjb public void report(Diagnostic d) { 9834355Sjb System.err.println(d); 9934355Sjb count++; 10034355Sjb } 10134355Sjb 10234355Sjb public int count; 10334355Sjb } 10434355Sjb} 10534355Sjb 10634355Sjb