Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/reflect/Parameter/WithParameters.java
38828 views
1
/*
2
* Copyright (c) 2013, Oracle and/or its affiliates. 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 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.
22
*/
23
24
/*
25
* @test
26
* @compile -parameters WithParameters.java
27
* @run main WithParameters
28
* @summary javac should generate method parameters correctly.
29
*/
30
31
import java.lang.*;
32
import java.lang.annotation.*;
33
import java.lang.reflect.*;
34
import java.util.List;
35
36
public class WithParameters {
37
38
private static final Class<?>[] qux_types = {
39
int.class, Foo.class, List.class, List.class, List.class, String[].class
40
};
41
42
private static final String[] qux_names = {
43
"quux", "quuux", "l", "l2", "l3", "rest"
44
};
45
46
public static void main(String argv[]) throws Exception {
47
int error = 0;
48
Method[] methods = Foo.class.getMethods();
49
for(Method m : methods) {
50
System.err.println("Inspecting method " + m.getName());
51
Parameter[] parameters = m.getParameters();
52
if(parameters == null)
53
throw new Exception("getParameters should never be null");
54
for(int i = 0; i < parameters.length; i++) {
55
Parameter p = parameters[i];
56
if(!p.getDeclaringExecutable().equals(m)) {
57
System.err.println(p + ".getDeclaringExecutable != " + m);
58
error++;
59
}
60
if(null == p.getType()) {
61
System.err.println(p + ".getType() == null");
62
error++;
63
}
64
if(null == p.getParameterizedType()) {
65
System.err.println(p + ".getParameterizedType == null");
66
error++;
67
}
68
}
69
if(m.getName().equals("qux")) {
70
if(6 != parameters.length) {
71
System.err.println("Wrong number of parameters for qux");
72
error++;
73
}
74
for(int i = 0; i < parameters.length; i++) {
75
Parameter p = parameters[i];
76
if(!p.isNamePresent()) {
77
System.err.println(p + ".isNamePresent == false");
78
error++;
79
}
80
if(!parameters[i].getName().equals(qux_names[i])) {
81
System.err.println("Wrong parameter name for " + parameters[i]);
82
error++;
83
}
84
// The getType family work with or without
85
// parameter attributes compiled in.
86
if(!parameters[i].getType().equals(qux_types[i])) {
87
System.err.println("Wrong parameter type for " + parameters[0] + ": expected " + qux_types[i] + ", but got " + parameters[i].getType());
88
error++;
89
}
90
}
91
if(!parameters[0].toString().equals("final int quux")) {
92
System.err.println("toString for quux is wrong, expected \"final int quux\", got \"" + parameters[0] + "\"");
93
error++;
94
}
95
if(parameters[0].getModifiers() != Modifier.FINAL) {
96
System.err.println("quux is not final");
97
error++;
98
}
99
if(parameters[0].isVarArgs()) {
100
System.err.println("isVarArg for quux is wrong");
101
error++;
102
}
103
if(!parameters[0].getParameterizedType().equals(int.class)) {
104
System.err.println("getParameterizedType for quux is wrong");
105
error++;
106
}
107
if(!parameters[1].toString().equals("WithParameters$Foo quuux")) {
108
System.err.println("toString for quuux is wrong, expected \"WithParameters$Foo quuux\", got \"" + parameters[1] + "\"");
109
error++;
110
}
111
if(parameters[1].isVarArgs()) {
112
System.err.println("isVarArg for quuux is wrong");
113
error++;
114
}
115
if(!parameters[1].getParameterizedType().equals(Foo.class)) {
116
System.err.println("getParameterizedType for quuux is wrong");
117
error++;
118
}
119
Annotation[] anns = parameters[1].getAnnotations();
120
if(1 != anns.length) {
121
System.err.println("getAnnotations missed an annotation");
122
error++;
123
} else if(!anns[0].annotationType().equals(Thing.class)) {
124
System.err.println("getAnnotations has the wrong annotation");
125
error++;
126
}
127
if(!parameters[2].toString().equals("java.util.List<?> l")) {
128
System.err.println("toString for l is wrong, expected \"java.util.List<?> l\", got \"" + parameters[2] + "\"");
129
error++;
130
}
131
if(parameters[2].isVarArgs()) {
132
System.err.println("isVarArg for l is wrong");
133
error++;
134
}
135
if(!(parameters[2].getParameterizedType() instanceof
136
ParameterizedType)) {
137
System.err.println("getParameterizedType for l is wrong");
138
error++;
139
} else {
140
ParameterizedType pt =
141
(ParameterizedType) parameters[2].getParameterizedType();
142
if(!pt.getRawType().equals(List.class)) {
143
System.err.println("Raw type for l is wrong");
144
error++;
145
}
146
if(1 != pt.getActualTypeArguments().length) {
147
System.err.println("Number of type parameters for l is wrong");
148
error++;
149
}
150
if(!(pt.getActualTypeArguments()[0] instanceof WildcardType)) {
151
System.err.println("Type parameter for l is wrong");
152
error++;
153
}
154
}
155
if(!parameters[3].toString().equals("java.util.List<WithParameters$Foo> l2")) {
156
System.err.println("toString for l2 is wrong, expected \"java.util.List<WithParameters$Foo> l2\", got \"" + parameters[3] + "\"");
157
error++;
158
}
159
if(parameters[3].isVarArgs()) {
160
System.err.println("isVarArg for l2 is wrong");
161
error++;
162
}
163
if(!(parameters[3].getParameterizedType() instanceof
164
ParameterizedType)) {
165
System.err.println("getParameterizedType for l2 is wrong");
166
error++;
167
} else {
168
ParameterizedType pt =
169
(ParameterizedType) parameters[3].getParameterizedType();
170
if(!pt.getRawType().equals(List.class)) {
171
System.err.println("Raw type for l2 is wrong");
172
error++;
173
}
174
if(1 != pt.getActualTypeArguments().length) {
175
System.err.println("Number of type parameters for l2 is wrong");
176
error++;
177
}
178
if(!(pt.getActualTypeArguments()[0].equals(Foo.class))) {
179
System.err.println("Type parameter for l2 is wrong");
180
error++;
181
}
182
}
183
if(!parameters[4].toString().equals("java.util.List<? extends WithParameters$Foo> l3")) {
184
System.err.println("toString for l3 is wrong, expected \"java.util.List<? extends WithParameters$Foo> l3\", got \"" + parameters[3] + "\"");
185
error++;
186
}
187
if(parameters[4].isVarArgs()) {
188
System.err.println("isVarArg for l3 is wrong");
189
error++;
190
}
191
if(!(parameters[4].getParameterizedType() instanceof
192
ParameterizedType)) {
193
System.err.println("getParameterizedType for l3 is wrong");
194
error++;
195
} else {
196
ParameterizedType pt =
197
(ParameterizedType) parameters[4].getParameterizedType();
198
if(!pt.getRawType().equals(List.class)) {
199
System.err.println("Raw type for l3 is wrong");
200
error++;
201
}
202
if(1 != pt.getActualTypeArguments().length) {
203
System.err.println("Number of type parameters for l3 is wrong");
204
error++;
205
}
206
if(!(pt.getActualTypeArguments()[0] instanceof WildcardType)) {
207
System.err.println("Type parameter for l3 is wrong");
208
error++;
209
} else {
210
WildcardType wt = (WildcardType)
211
pt.getActualTypeArguments()[0];
212
if(!wt.getUpperBounds()[0].equals(Foo.class)) {
213
System.err.println("Upper bounds on type parameter fol l3 is wrong");
214
error++;
215
}
216
}
217
}
218
if(!parameters[5].toString().equals("java.lang.String... rest")) {
219
System.err.println("toString for rest is wrong, expected \"java.lang.String... rest\", got \"" + parameters[5] + "\"");
220
error++;
221
}
222
if(!parameters[5].isVarArgs()) {
223
System.err.println("isVarArg for rest is wrong");
224
error++;
225
}
226
if(!(parameters[5].getParameterizedType().equals(String[].class))) {
227
System.err.println("getParameterizedType for rest is wrong");
228
error++;
229
}
230
}
231
}
232
if(0 != error)
233
throw new Exception("Failed " + error + " tests");
234
}
235
236
void test(int test) {}
237
238
public class Foo {
239
int thing;
240
public void qux(final int quux, @Thing Foo quuux,
241
List<?> l, List<Foo> l2,
242
List<? extends Foo> l3,
243
String... rest) {}
244
}
245
246
@Retention(RetentionPolicy.RUNTIME)
247
public @interface Thing {}
248
249
}
250
251