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