1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/api/6468404/T6468404.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,153 @@ 1.4 +/* 1.5 + * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test 1.29 + * @bug 6468404 1.30 + * @summary ExecutableElement.getParameters() uses raw type for class loaded from -g bytecode 1.31 + * @author jesse.glick@... 1.32 + * @author Peter von der Ah\u00e9 1.33 + * @library ../lib 1.34 + * @build ToolTester 1.35 + * @compile T6468404.java 1.36 + * @run main T6468404 1.37 + */ 1.38 + 1.39 +import java.io.IOException; 1.40 +import java.net.URI; 1.41 +import java.util.Arrays; 1.42 +import java.util.Collections; 1.43 +import java.util.Set; 1.44 +import javax.annotation.processing.AbstractProcessor; 1.45 +import javax.annotation.processing.RoundEnvironment; 1.46 +import javax.annotation.processing.SupportedAnnotationTypes; 1.47 +import javax.annotation.processing.SupportedSourceVersion; 1.48 +import javax.annotation.processing.ProcessingEnvironment; 1.49 +import javax.lang.model.SourceVersion; 1.50 +import javax.lang.model.element.ExecutableElement; 1.51 +import javax.lang.model.element.TypeElement; 1.52 +import javax.lang.model.type.ExecutableType; 1.53 +import javax.lang.model.type.DeclaredType; 1.54 +import javax.lang.model.type.TypeMirror; 1.55 +import javax.lang.model.util.Elements; 1.56 +import javax.tools.JavaCompiler; 1.57 +import javax.tools.JavaFileObject; 1.58 +import javax.tools.SimpleJavaFileObject; 1.59 +import javax.tools.ToolProvider; 1.60 + 1.61 +public class T6468404 extends ToolTester { 1.62 + void test(String... args) { 1.63 + System.err.println("Compiling with sources:"); 1.64 + task = tool.getTask( 1.65 + null, fm, null, null, 1.66 + null, Collections.singleton(new DummyFO("C"))); 1.67 + task.setProcessors(Collections.singleton(new P())); 1.68 + if (!task.call()) 1.69 + throw new AssertionError(); 1.70 + 1.71 + System.err.println("Compiling with binaries w/o -g:"); 1.72 + task = tool.getTask( 1.73 + null, fm, null, null, 1.74 + null, Collections.singleton(new DummyFO("Dummy"))); 1.75 + task.setProcessors(Collections.singleton(new P())); 1.76 + if (!task.call()) 1.77 + throw new AssertionError(); 1.78 + 1.79 + task = tool.getTask( 1.80 + null, fm, null, 1.81 + Arrays.asList("-g"), 1.82 + null, Collections.singleton(new DummyFO("C"))); 1.83 + if (!task.call()) 1.84 + throw new AssertionError(); 1.85 + 1.86 + System.err.println("Compiling with binaries w/ -g:"); 1.87 + task = tool.getTask( 1.88 + null, fm, null, null, 1.89 + null, Collections.singleton(new DummyFO("Dummy"))); 1.90 + task.setProcessors(Collections.singleton(new P())); 1.91 + if (!task.call()) 1.92 + throw new AssertionError(); 1.93 + } 1.94 + public static void main(String... args) { 1.95 + new T6468404().test(args); 1.96 + } 1.97 + 1.98 +} 1.99 + 1.100 +class DummyFO extends SimpleJavaFileObject { 1.101 + String n; 1.102 + public DummyFO(String n) { 1.103 + super(URI.create("nowhere:/" + n + ".java"), JavaFileObject.Kind.SOURCE); 1.104 + this.n = n; 1.105 + } 1.106 + public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { 1.107 + return "public class " + n + " {" + n + "(java.util.List<String> l) {}}"; 1.108 + } 1.109 +} 1.110 + 1.111 +@SupportedAnnotationTypes("*") 1.112 +class P extends AbstractProcessor { 1.113 + boolean ran = false; 1.114 + 1.115 + Elements elements; 1.116 + 1.117 + @Override 1.118 + public synchronized void init(ProcessingEnvironment processingEnv) { 1.119 + super.init(processingEnv); 1.120 + elements = processingEnv.getElementUtils(); 1.121 + } 1.122 + 1.123 + ExecutableElement getFirstMethodIn(String name) { 1.124 + return (ExecutableElement)elements.getTypeElement(name).getEnclosedElements().get(0); 1.125 + } 1.126 + 1.127 + boolean isParameterized(TypeMirror type) { 1.128 + return !((DeclaredType)type).getTypeArguments().isEmpty(); 1.129 + } 1.130 + 1.131 + @Override 1.132 + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 1.133 + if (!ran) { 1.134 + ran = true; 1.135 + ExecutableElement m = getFirstMethodIn("C"); 1.136 + System.err.println("method: " + m); 1.137 + 1.138 + TypeMirror type = (DeclaredType)m.getParameters().get(0).asType(); 1.139 + System.err.println("parameters[0]: " + type); 1.140 + if (!isParameterized(type)) 1.141 + throw new AssertionError(type); 1.142 + 1.143 + type = ((ExecutableType)m.asType()).getParameterTypes().get(0); 1.144 + System.err.println("parameterTypes[0]: " + type); 1.145 + if (!isParameterized(type)) 1.146 + throw new AssertionError(type); 1.147 + System.err.println(); 1.148 + } 1.149 + return true; 1.150 + } 1.151 + 1.152 + @Override 1.153 + public SourceVersion getSupportedSourceVersion() { 1.154 + return SourceVersion.latest(); 1.155 + } 1.156 +}