J. Duke | f57b87e | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 1 | /* |
Kelly O'Hair | bd4f4be | 2010-05-25 15:54:51 -0700 | [diff] [blame^] | 2 | * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved. |
J. Duke | f57b87e | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
Kelly O'Hair | bd4f4be | 2010-05-25 15:54:51 -0700 | [diff] [blame^] | 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. |
J. Duke | f57b87e | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * @test |
| 26 | * @bug 6468404 |
| 27 | * @summary ExecutableElement.getParameters() uses raw type for class loaded from -g bytecode |
| 28 | * @author jesse.glick@... |
| 29 | * @author Peter von der Ah\u00e9 |
| 30 | * @library ../lib |
| 31 | * @compile T6468404.java |
| 32 | * @run main T6468404 |
| 33 | */ |
| 34 | |
| 35 | import java.io.IOException; |
| 36 | import java.net.URI; |
| 37 | import java.util.Arrays; |
| 38 | import java.util.Collections; |
| 39 | import java.util.Set; |
| 40 | import javax.annotation.processing.AbstractProcessor; |
| 41 | import javax.annotation.processing.RoundEnvironment; |
| 42 | import javax.annotation.processing.SupportedAnnotationTypes; |
| 43 | import javax.annotation.processing.SupportedSourceVersion; |
| 44 | import javax.annotation.processing.ProcessingEnvironment; |
| 45 | import javax.lang.model.SourceVersion; |
| 46 | import javax.lang.model.element.ExecutableElement; |
| 47 | import javax.lang.model.element.TypeElement; |
| 48 | import javax.lang.model.type.ExecutableType; |
| 49 | import javax.lang.model.type.DeclaredType; |
| 50 | import javax.lang.model.type.TypeMirror; |
| 51 | import javax.lang.model.util.Elements; |
| 52 | import javax.tools.JavaCompiler; |
| 53 | import javax.tools.JavaFileObject; |
| 54 | import javax.tools.SimpleJavaFileObject; |
| 55 | import javax.tools.ToolProvider; |
| 56 | |
| 57 | public class T6468404 extends ToolTester { |
| 58 | void test(String... args) { |
| 59 | System.err.println("Compiling with sources:"); |
| 60 | task = tool.getTask( |
| 61 | null, fm, null, null, |
| 62 | null, Collections.singleton(new DummyFO("C"))); |
| 63 | task.setProcessors(Collections.singleton(new P())); |
| 64 | if (!task.call()) |
| 65 | throw new AssertionError(); |
| 66 | |
| 67 | System.err.println("Compiling with binaries w/o -g:"); |
| 68 | task = tool.getTask( |
| 69 | null, fm, null, null, |
| 70 | null, Collections.singleton(new DummyFO("Dummy"))); |
| 71 | task.setProcessors(Collections.singleton(new P())); |
| 72 | if (!task.call()) |
| 73 | throw new AssertionError(); |
| 74 | |
| 75 | task = tool.getTask( |
| 76 | null, fm, null, |
| 77 | Arrays.asList("-g"), |
| 78 | null, Collections.singleton(new DummyFO("C"))); |
| 79 | if (!task.call()) |
| 80 | throw new AssertionError(); |
| 81 | |
| 82 | System.err.println("Compiling with binaries w/ -g:"); |
| 83 | task = tool.getTask( |
| 84 | null, fm, null, null, |
| 85 | null, Collections.singleton(new DummyFO("Dummy"))); |
| 86 | task.setProcessors(Collections.singleton(new P())); |
| 87 | if (!task.call()) |
| 88 | throw new AssertionError(); |
| 89 | } |
| 90 | public static void main(String... args) { |
| 91 | new T6468404().test(args); |
| 92 | } |
| 93 | |
| 94 | } |
| 95 | |
| 96 | class DummyFO extends SimpleJavaFileObject { |
| 97 | String n; |
| 98 | public DummyFO(String n) { |
| 99 | super(URI.create("nowhere:/" + n + ".java"), JavaFileObject.Kind.SOURCE); |
| 100 | this.n = n; |
| 101 | } |
| 102 | public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { |
| 103 | return "public class " + n + " {" + n + "(java.util.List<String> l) {}}"; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | @SupportedAnnotationTypes("*") |
J. Duke | f57b87e | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 108 | class P extends AbstractProcessor { |
| 109 | boolean ran = false; |
| 110 | |
| 111 | Elements elements; |
| 112 | |
| 113 | @Override |
| 114 | public synchronized void init(ProcessingEnvironment processingEnv) { |
| 115 | super.init(processingEnv); |
| 116 | elements = processingEnv.getElementUtils(); |
| 117 | } |
| 118 | |
| 119 | ExecutableElement getFirstMethodIn(String name) { |
| 120 | return (ExecutableElement)elements.getTypeElement(name).getEnclosedElements().get(0); |
| 121 | } |
| 122 | |
| 123 | boolean isParameterized(TypeMirror type) { |
| 124 | return !((DeclaredType)type).getTypeArguments().isEmpty(); |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
| 129 | if (!ran) { |
| 130 | ran = true; |
| 131 | ExecutableElement m = getFirstMethodIn("C"); |
| 132 | System.err.println("method: " + m); |
| 133 | |
| 134 | TypeMirror type = (DeclaredType)m.getParameters().get(0).asType(); |
| 135 | System.err.println("parameters[0]: " + type); |
| 136 | if (!isParameterized(type)) |
| 137 | throw new AssertionError(type); |
| 138 | |
| 139 | type = ((ExecutableType)m.asType()).getParameterTypes().get(0); |
| 140 | System.err.println("parameterTypes[0]: " + type); |
| 141 | if (!isParameterized(type)) |
| 142 | throw new AssertionError(type); |
| 143 | System.err.println(); |
| 144 | } |
| 145 | return true; |
| 146 | } |
Joe Darcy | 779ba4b | 2010-02-15 20:06:11 -0800 | [diff] [blame] | 147 | |
| 148 | @Override |
| 149 | public SourceVersion getSupportedSourceVersion() { |
| 150 | return SourceVersion.latest(); |
| 151 | } |
J. Duke | f57b87e | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 152 | } |