duke@1: /* ohair@554: * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as duke@1: * published by the Free Software Foundation. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: /* duke@1: * @test duke@1: * @bug 6468404 duke@1: * @summary ExecutableElement.getParameters() uses raw type for class loaded from -g bytecode duke@1: * @author jesse.glick@... duke@1: * @author Peter von der Ah\u00e9 duke@1: * @library ../lib duke@1: * @compile T6468404.java duke@1: * @run main T6468404 duke@1: */ duke@1: duke@1: import java.io.IOException; duke@1: import java.net.URI; duke@1: import java.util.Arrays; duke@1: import java.util.Collections; duke@1: import java.util.Set; duke@1: import javax.annotation.processing.AbstractProcessor; duke@1: import javax.annotation.processing.RoundEnvironment; duke@1: import javax.annotation.processing.SupportedAnnotationTypes; duke@1: import javax.annotation.processing.SupportedSourceVersion; duke@1: import javax.annotation.processing.ProcessingEnvironment; duke@1: import javax.lang.model.SourceVersion; duke@1: import javax.lang.model.element.ExecutableElement; duke@1: import javax.lang.model.element.TypeElement; duke@1: import javax.lang.model.type.ExecutableType; duke@1: import javax.lang.model.type.DeclaredType; duke@1: import javax.lang.model.type.TypeMirror; duke@1: import javax.lang.model.util.Elements; duke@1: import javax.tools.JavaCompiler; duke@1: import javax.tools.JavaFileObject; duke@1: import javax.tools.SimpleJavaFileObject; duke@1: import javax.tools.ToolProvider; duke@1: duke@1: public class T6468404 extends ToolTester { duke@1: void test(String... args) { duke@1: System.err.println("Compiling with sources:"); duke@1: task = tool.getTask( duke@1: null, fm, null, null, duke@1: null, Collections.singleton(new DummyFO("C"))); duke@1: task.setProcessors(Collections.singleton(new P())); duke@1: if (!task.call()) duke@1: throw new AssertionError(); duke@1: duke@1: System.err.println("Compiling with binaries w/o -g:"); duke@1: task = tool.getTask( duke@1: null, fm, null, null, duke@1: null, Collections.singleton(new DummyFO("Dummy"))); duke@1: task.setProcessors(Collections.singleton(new P())); duke@1: if (!task.call()) duke@1: throw new AssertionError(); duke@1: duke@1: task = tool.getTask( duke@1: null, fm, null, duke@1: Arrays.asList("-g"), duke@1: null, Collections.singleton(new DummyFO("C"))); duke@1: if (!task.call()) duke@1: throw new AssertionError(); duke@1: duke@1: System.err.println("Compiling with binaries w/ -g:"); duke@1: task = tool.getTask( duke@1: null, fm, null, null, duke@1: null, Collections.singleton(new DummyFO("Dummy"))); duke@1: task.setProcessors(Collections.singleton(new P())); duke@1: if (!task.call()) duke@1: throw new AssertionError(); duke@1: } duke@1: public static void main(String... args) { duke@1: new T6468404().test(args); duke@1: } duke@1: duke@1: } duke@1: duke@1: class DummyFO extends SimpleJavaFileObject { duke@1: String n; duke@1: public DummyFO(String n) { duke@1: super(URI.create("nowhere:/" + n + ".java"), JavaFileObject.Kind.SOURCE); duke@1: this.n = n; duke@1: } duke@1: public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { duke@1: return "public class " + n + " {" + n + "(java.util.List l) {}}"; duke@1: } duke@1: } duke@1: duke@1: @SupportedAnnotationTypes("*") duke@1: class P extends AbstractProcessor { duke@1: boolean ran = false; duke@1: duke@1: Elements elements; duke@1: duke@1: @Override duke@1: public synchronized void init(ProcessingEnvironment processingEnv) { duke@1: super.init(processingEnv); duke@1: elements = processingEnv.getElementUtils(); duke@1: } duke@1: duke@1: ExecutableElement getFirstMethodIn(String name) { duke@1: return (ExecutableElement)elements.getTypeElement(name).getEnclosedElements().get(0); duke@1: } duke@1: duke@1: boolean isParameterized(TypeMirror type) { duke@1: return !((DeclaredType)type).getTypeArguments().isEmpty(); duke@1: } duke@1: duke@1: @Override duke@1: public boolean process(Set annotations, RoundEnvironment roundEnv) { duke@1: if (!ran) { duke@1: ran = true; duke@1: ExecutableElement m = getFirstMethodIn("C"); duke@1: System.err.println("method: " + m); duke@1: duke@1: TypeMirror type = (DeclaredType)m.getParameters().get(0).asType(); duke@1: System.err.println("parameters[0]: " + type); duke@1: if (!isParameterized(type)) duke@1: throw new AssertionError(type); duke@1: duke@1: type = ((ExecutableType)m.asType()).getParameterTypes().get(0); duke@1: System.err.println("parameterTypes[0]: " + type); duke@1: if (!isParameterized(type)) duke@1: throw new AssertionError(type); duke@1: System.err.println(); duke@1: } duke@1: return true; duke@1: } darcy@495: darcy@495: @Override darcy@495: public SourceVersion getSupportedSourceVersion() { darcy@495: return SourceVersion.latest(); darcy@495: } duke@1: }