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
1 /*
2 * Copyright 2006-2007 Sun Microsystems, Inc. All Rights Reserved.
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 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
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 */
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;
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();
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();
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();
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 }
94 }
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 }
107 @SupportedAnnotationTypes("*")
108 @SupportedSourceVersion(SourceVersion.RELEASE_6)
109 class P extends AbstractProcessor {
110 boolean ran = false;
112 Elements elements;
114 @Override
115 public synchronized void init(ProcessingEnvironment processingEnv) {
116 super.init(processingEnv);
117 elements = processingEnv.getElementUtils();
118 }
120 ExecutableElement getFirstMethodIn(String name) {
121 return (ExecutableElement)elements.getTypeElement(name).getEnclosedElements().get(0);
122 }
124 boolean isParameterized(TypeMirror type) {
125 return !((DeclaredType)type).getTypeArguments().isEmpty();
126 }
128 @Override
129 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
130 if (!ran) {
131 ran = true;
132 ExecutableElement m = getFirstMethodIn("C");
133 System.err.println("method: " + m);
135 TypeMirror type = (DeclaredType)m.getParameters().get(0).asType();
136 System.err.println("parameters[0]: " + type);
137 if (!isParameterized(type))
138 throw new AssertionError(type);
140 type = ((ExecutableType)m.asType()).getParameterTypes().get(0);
141 System.err.println("parameterTypes[0]: " + type);
142 if (!isParameterized(type))
143 throw new AssertionError(type);
144 System.err.println();
145 }
146 return true;
147 }
148 }