|
1 /* |
|
2 * Copyright (c) 2015, 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 * @bug 8049238 |
|
27 * @summary Checks Signature attribute for method parameters. |
|
28 * @library /tools/lib /tools/javac/lib ../lib |
|
29 * @build TestBase TestResult InMemoryFileManager ToolBox |
|
30 * @build MethodParameterTest Driver ExpectedSignature ExpectedSignatureContainer |
|
31 * @run main Driver MethodParameterTest |
|
32 */ |
|
33 |
|
34 import java.util.ArrayList; |
|
35 import java.util.List; |
|
36 import java.util.Map; |
|
37 import java.util.Set; |
|
38 |
|
39 @ExpectedSignature(descriptor = "MethodParameterTest", signature = "<T:Ljava/lang/Object;>Ljava/lang/Object;") |
|
40 public class MethodParameterTest<T> { |
|
41 |
|
42 @ExpectedSignature(descriptor = "<init>(java.lang.Object, java.util.Set, java.util.ArrayList)", |
|
43 signature = "<E:TT;U::Ljava/util/List<TE;>;:Ljava/lang/Runnable;>" + |
|
44 "(TT;Ljava/util/Set<-TE;>;Ljava/util/ArrayList<+Ljava/util/Set<TU;>;>;)V") |
|
45 <E extends T, U extends List<E> & Runnable> |
|
46 MethodParameterTest(T a, Set<? super E> b, ArrayList<? extends Set<U>> c) { |
|
47 } |
|
48 |
|
49 @ExpectedSignature(descriptor = "method(java.lang.Object, java.util.List, java.util.ArrayList)", |
|
50 signature = "<E:TT;U::Ljava/util/List<TE;>;:Ljava/lang/Runnable;>" + |
|
51 "(TT;TU;Ljava/util/ArrayList<+Ljava/util/Set<TU;>;>;)V") |
|
52 <E extends T, U extends List<E> & Runnable> |
|
53 void method(T a, U b, ArrayList<? extends Set<U>> c) { |
|
54 } |
|
55 |
|
56 @ExpectedSignature(descriptor = "staticMethod(java.util.Set, java.util.List[], java.util.Map)", |
|
57 signature = "<T::Ljava/util/List<*>;E::Ljava/util/Set<-TT;>;>(TE;[TT;Ljava/util/Map<*+TE;>;)TE;") |
|
58 static <T extends List<?>, E extends Set<? super T>> E staticMethod(E a, T[] b, Map<?, ? extends E> c) { |
|
59 return null; |
|
60 } |
|
61 |
|
62 @ExpectedSignature(descriptor = "<init>(java.lang.Object, boolean[])", signature = "(TT;[Z)V") |
|
63 MethodParameterTest(T a, boolean...b) { |
|
64 } |
|
65 |
|
66 @ExpectedSignature(descriptor = "<init>(java.lang.Object, char[])", signature = "(TT;[C)V") |
|
67 MethodParameterTest(T a, char...b) { |
|
68 } |
|
69 |
|
70 @ExpectedSignature(descriptor = "<init>(java.lang.Object, byte[])", signature = "(TT;[B)V") |
|
71 MethodParameterTest(T a, byte...b) { |
|
72 } |
|
73 |
|
74 @ExpectedSignature(descriptor = "<init>(java.lang.Object, short[])", signature = "(TT;[S)V") |
|
75 MethodParameterTest(T a, short...b) { |
|
76 } |
|
77 |
|
78 @ExpectedSignature(descriptor = "<init>(java.lang.Object, int[])", signature = "(TT;[I)V") |
|
79 MethodParameterTest(T a, int...b) { |
|
80 } |
|
81 |
|
82 @ExpectedSignature(descriptor = "<init>(java.lang.Object, long[])", signature = "(TT;[J)V") |
|
83 MethodParameterTest(T a, long...b) { |
|
84 } |
|
85 |
|
86 @ExpectedSignature(descriptor = "<init>(java.lang.Object, float[])", signature = "(TT;[F)V") |
|
87 MethodParameterTest(T a, float...b) { |
|
88 } |
|
89 |
|
90 @ExpectedSignature(descriptor = "<init>(java.lang.Object, double[])", signature = "(TT;[D)V") |
|
91 MethodParameterTest(T a, double...b) { |
|
92 } |
|
93 |
|
94 @ExpectedSignature(descriptor = "<init>(java.lang.Object, java.lang.Object[])", |
|
95 signature = "(TT;[Ljava/lang/Object;)V") |
|
96 MethodParameterTest(T a, Object...b) { |
|
97 } |
|
98 |
|
99 @ExpectedSignature(descriptor = "<init>(java.lang.Object[])", signature = "([TT;)V") |
|
100 MethodParameterTest(T...a) { |
|
101 } |
|
102 |
|
103 // no Signature attribute |
|
104 MethodParameterTest(int...a) { |
|
105 } |
|
106 |
|
107 @ExpectedSignature(descriptor = "genericBooleanMethod(java.lang.Object, boolean[])", signature = "(TT;[Z)V") |
|
108 void genericBooleanMethod(T a, boolean...b) { |
|
109 } |
|
110 |
|
111 @ExpectedSignature(descriptor = "genericCharMethod(java.lang.Object, char[])", signature = "(TT;[C)V") |
|
112 void genericCharMethod(T a, char...b) { |
|
113 } |
|
114 |
|
115 @ExpectedSignature(descriptor = "genericByteMethod(java.lang.Object, byte[])", signature = "(TT;[B)V") |
|
116 void genericByteMethod(T a, byte...b) { |
|
117 } |
|
118 |
|
119 @ExpectedSignature(descriptor = "genericShortMethod(java.lang.Object, short[])", signature = "(TT;[S)V") |
|
120 void genericShortMethod(T a, short...b) { |
|
121 } |
|
122 |
|
123 @ExpectedSignature(descriptor = "genericIntMethod(java.lang.Object, int[])", signature = "(TT;[I)V") |
|
124 void genericIntMethod(T a, int...b) { |
|
125 } |
|
126 |
|
127 @ExpectedSignature(descriptor = "genericLongMethod(java.lang.Object, long[])", signature = "(TT;[J)V") |
|
128 void genericLongMethod(T a, long...b) { |
|
129 } |
|
130 |
|
131 @ExpectedSignature(descriptor = "genericFloatMethod(java.lang.Object, float[])", signature = "(TT;[F)V") |
|
132 void genericFloatMethod(T a, float...b) { |
|
133 } |
|
134 |
|
135 @ExpectedSignature(descriptor = "genericDoubleMethod(java.lang.Object, double[])", signature = "(TT;[D)V") |
|
136 void genericDoubleMethod(T a, double...b) { |
|
137 } |
|
138 |
|
139 @ExpectedSignature(descriptor = "genericObjectMethod(java.lang.Object, java.lang.Object[])", |
|
140 signature = "(TT;[Ljava/lang/Object;)V") |
|
141 void genericObjectMethod(T a, Object...b) { |
|
142 } |
|
143 |
|
144 @ExpectedSignature(descriptor = "genericMethod(java.lang.Object[])", signature = "([TT;)V") |
|
145 void genericMethod(T...a) { |
|
146 } |
|
147 |
|
148 void noSignature(int...a) { |
|
149 } |
|
150 |
|
151 @ExpectedSignature(descriptor = "staticGenericBooleanMethod(java.lang.Object, boolean[])", |
|
152 signature = "<T:Ljava/lang/Object;>(TT;[Z)V") |
|
153 static <T> void staticGenericBooleanMethod(T a, boolean...b) { |
|
154 } |
|
155 |
|
156 @ExpectedSignature(descriptor = "staticGenericCharMethod(java.lang.Object, char[])", |
|
157 signature = "<T:Ljava/lang/Object;>(TT;[C)V") |
|
158 static <T> void staticGenericCharMethod(T a, char...b) { |
|
159 } |
|
160 |
|
161 @ExpectedSignature(descriptor = "staticGenericByteMethod(java.lang.Object, byte[])", |
|
162 signature = "<T:Ljava/lang/Object;>(TT;[B)V") |
|
163 static <T> void staticGenericByteMethod(T a, byte...b) { |
|
164 } |
|
165 |
|
166 @ExpectedSignature(descriptor = "staticGenericShortMethod(java.lang.Object, short[])", |
|
167 signature = "<T:Ljava/lang/Object;>(TT;[S)V") |
|
168 static <T> void staticGenericShortMethod(T a, short...b) { |
|
169 } |
|
170 |
|
171 @ExpectedSignature(descriptor = "staticGenericIntMethod(java.lang.Object, int[])", |
|
172 signature = "<T:Ljava/lang/Object;>(TT;[I)V") |
|
173 static <T> void staticGenericIntMethod(T a, int...b) { |
|
174 } |
|
175 |
|
176 @ExpectedSignature(descriptor = "staticGenericLongMethod(java.lang.Object, long[])", |
|
177 signature = "<T:Ljava/lang/Object;>(TT;[J)V") |
|
178 static <T> void staticGenericLongMethod(T a, long...b) { |
|
179 } |
|
180 |
|
181 @ExpectedSignature(descriptor = "staticGenericFloatMethod(java.lang.Object, float[])", |
|
182 signature = "<T:Ljava/lang/Object;>(TT;[F)V") |
|
183 static <T> void staticGenericFloatMethod(T a, float...b) { |
|
184 } |
|
185 |
|
186 @ExpectedSignature(descriptor = "staticGenericDoubleMethod(java.lang.Object, double[])", |
|
187 signature = "<T:Ljava/lang/Object;>(TT;[D)V") |
|
188 static <T> void staticGenericDoubleMethod(T a, double...b) { |
|
189 } |
|
190 |
|
191 @ExpectedSignature(descriptor = "staticGenericObjectMethod(java.lang.Object, java.lang.Object[])", |
|
192 signature = "<T:Ljava/lang/Object;>(TT;[Ljava/lang/Object;)V") |
|
193 static <T> void staticGenericObjectMethod(T a, Object...b) { |
|
194 } |
|
195 |
|
196 @ExpectedSignature(descriptor = "staticGenericMethod(java.lang.Object[])", |
|
197 signature = "<T:Ljava/lang/Object;>([TT;)V") |
|
198 static <T> void staticGenericMethod(T...a) { |
|
199 } |
|
200 |
|
201 static void staticNoSignatureAttribute(int...a) { |
|
202 } |
|
203 } |