blob: 18aa49566b329d1fcee2bc12ecec04c86959598e [file] [log] [blame]
J. Dukef57b87e2007-12-01 00:00:00 +00001/*
Kelly O'Hairbd4f4be2010-05-25 15:54:51 -07002 * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved.
J. Dukef57b87e2007-12-01 00:00:00 +00003 * 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'Hairbd4f4be2010-05-25 15:54:51 -070019 * 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. Dukef57b87e2007-12-01 00:00:00 +000022 */
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
35import java.io.IOException;
36import java.net.URI;
37import java.util.Arrays;
38import java.util.Collections;
39import java.util.Set;
40import javax.annotation.processing.AbstractProcessor;
41import javax.annotation.processing.RoundEnvironment;
42import javax.annotation.processing.SupportedAnnotationTypes;
43import javax.annotation.processing.SupportedSourceVersion;
44import javax.annotation.processing.ProcessingEnvironment;
45import javax.lang.model.SourceVersion;
46import javax.lang.model.element.ExecutableElement;
47import javax.lang.model.element.TypeElement;
48import javax.lang.model.type.ExecutableType;
49import javax.lang.model.type.DeclaredType;
50import javax.lang.model.type.TypeMirror;
51import javax.lang.model.util.Elements;
52import javax.tools.JavaCompiler;
53import javax.tools.JavaFileObject;
54import javax.tools.SimpleJavaFileObject;
55import javax.tools.ToolProvider;
56
57public 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
96class 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. Dukef57b87e2007-12-01 00:00:00 +0000108class 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 Darcy779ba4b2010-02-15 20:06:11 -0800147
148 @Override
149 public SourceVersion getSupportedSourceVersion() {
150 return SourceVersion.latest();
151 }
J. Dukef57b87e2007-12-01 00:00:00 +0000152}