author | darcy |
Tue, 11 Jun 2019 17:20:51 -0700 | |
changeset 55337 | ae3dbc712839 |
parent 54952 | a978d86ac389 |
child 57503 | 042dfb697624 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
54952
a978d86ac389
8224175: Fix inconsistencies in @jls and @jvms tags
darcy
parents:
52427
diff
changeset
|
2 |
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.lang.reflect; |
|
27 |
||
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
29125
diff
changeset
|
28 |
import jdk.internal.HotSpotIntrinsicCandidate; |
52427
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
52380
diff
changeset
|
29 |
import jdk.internal.access.SharedSecrets; |
37363
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
36511
diff
changeset
|
30 |
import jdk.internal.reflect.CallerSensitive; |
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
36511
diff
changeset
|
31 |
import jdk.internal.reflect.MethodAccessor; |
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
36511
diff
changeset
|
32 |
import jdk.internal.reflect.Reflection; |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
38882
diff
changeset
|
33 |
import jdk.internal.vm.annotation.ForceInline; |
38882
efb06b82374b
5041778: (ann) AnnotationFormatError if "default" Class type not found
darcy
parents:
37363
diff
changeset
|
34 |
import sun.reflect.annotation.ExceptionProxy; |
efb06b82374b
5041778: (ann) AnnotationFormatError if "default" Class type not found
darcy
parents:
37363
diff
changeset
|
35 |
import sun.reflect.annotation.TypeNotPresentExceptionProxy; |
2 | 36 |
import sun.reflect.generics.repository.MethodRepository; |
37 |
import sun.reflect.generics.factory.CoreReflectionFactory; |
|
38 |
import sun.reflect.generics.factory.GenericsFactory; |
|
39 |
import sun.reflect.generics.scope.MethodScope; |
|
40 |
import sun.reflect.annotation.AnnotationType; |
|
41 |
import sun.reflect.annotation.AnnotationParser; |
|
42 |
import java.lang.annotation.Annotation; |
|
43 |
import java.lang.annotation.AnnotationFormatError; |
|
44 |
import java.nio.ByteBuffer; |
|
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
45 |
import java.util.StringJoiner; |
2 | 46 |
|
47 |
/** |
|
48 |
* A {@code Method} provides information about, and access to, a single method |
|
49 |
* on a class or interface. The reflected method may be a class method |
|
50 |
* or an instance method (including an abstract method). |
|
51 |
* |
|
52 |
* <p>A {@code Method} permits widening conversions to occur when matching the |
|
53 |
* actual parameters to invoke with the underlying method's formal |
|
54 |
* parameters, but it throws an {@code IllegalArgumentException} if a |
|
55 |
* narrowing conversion would occur. |
|
56 |
* |
|
57 |
* @see Member |
|
58 |
* @see java.lang.Class |
|
59 |
* @see java.lang.Class#getMethods() |
|
60 |
* @see java.lang.Class#getMethod(String, Class[]) |
|
61 |
* @see java.lang.Class#getDeclaredMethods() |
|
62 |
* @see java.lang.Class#getDeclaredMethod(String, Class[]) |
|
63 |
* |
|
64 |
* @author Kenneth Russell |
|
65 |
* @author Nakul Saraiya |
|
45434
4582657c7260
8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents:
45332
diff
changeset
|
66 |
* @since 1.1 |
2 | 67 |
*/ |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
68 |
public final class Method extends Executable { |
3959
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
3941
diff
changeset
|
69 |
private Class<?> clazz; |
2 | 70 |
private int slot; |
71 |
// This is guaranteed to be interned by the VM in the 1.4 |
|
72 |
// reflection implementation |
|
73 |
private String name; |
|
3959
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
3941
diff
changeset
|
74 |
private Class<?> returnType; |
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
3941
diff
changeset
|
75 |
private Class<?>[] parameterTypes; |
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
3941
diff
changeset
|
76 |
private Class<?>[] exceptionTypes; |
2 | 77 |
private int modifiers; |
78 |
// Generics and annotations support |
|
79 |
private transient String signature; |
|
80 |
// generic info repository; lazily initialized |
|
81 |
private transient MethodRepository genericInfo; |
|
82 |
private byte[] annotations; |
|
83 |
private byte[] parameterAnnotations; |
|
84 |
private byte[] annotationDefault; |
|
85 |
private volatile MethodAccessor methodAccessor; |
|
86 |
// For sharing of MethodAccessors. This branching structure is |
|
87 |
// currently only two levels deep (i.e., one root Method and |
|
88 |
// potentially many Method objects pointing to it.) |
|
26455
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
89 |
// |
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
90 |
// If this branching structure would ever contain cycles, deadlocks can |
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
91 |
// occur in annotation code. |
2 | 92 |
private Method root; |
93 |
||
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
94 |
// Generics infrastructure |
2 | 95 |
private String getGenericSignature() {return signature;} |
96 |
||
97 |
// Accessor for factory |
|
98 |
private GenericsFactory getFactory() { |
|
99 |
// create scope and factory |
|
100 |
return CoreReflectionFactory.make(this, MethodScope.make(this)); |
|
101 |
} |
|
102 |
||
103 |
// Accessor for generic info repository |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
104 |
@Override |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
105 |
MethodRepository getGenericInfo() { |
2 | 106 |
// lazily initialize repository if necessary |
107 |
if (genericInfo == null) { |
|
108 |
// create and cache generic info repository |
|
109 |
genericInfo = MethodRepository.make(getGenericSignature(), |
|
110 |
getFactory()); |
|
111 |
} |
|
112 |
return genericInfo; //return cached repository |
|
113 |
} |
|
114 |
||
115 |
/** |
|
116 |
* Package-private constructor used by ReflectAccess to enable |
|
117 |
* instantiation of these objects in Java code from the java.lang |
|
118 |
* package via sun.reflect.LangReflectAccess. |
|
119 |
*/ |
|
3959
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
3941
diff
changeset
|
120 |
Method(Class<?> declaringClass, |
2 | 121 |
String name, |
3959
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
3941
diff
changeset
|
122 |
Class<?>[] parameterTypes, |
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
3941
diff
changeset
|
123 |
Class<?> returnType, |
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
3941
diff
changeset
|
124 |
Class<?>[] checkedExceptions, |
2 | 125 |
int modifiers, |
126 |
int slot, |
|
127 |
String signature, |
|
128 |
byte[] annotations, |
|
129 |
byte[] parameterAnnotations, |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
130 |
byte[] annotationDefault) { |
2 | 131 |
this.clazz = declaringClass; |
132 |
this.name = name; |
|
133 |
this.parameterTypes = parameterTypes; |
|
134 |
this.returnType = returnType; |
|
135 |
this.exceptionTypes = checkedExceptions; |
|
136 |
this.modifiers = modifiers; |
|
137 |
this.slot = slot; |
|
138 |
this.signature = signature; |
|
139 |
this.annotations = annotations; |
|
140 |
this.parameterAnnotations = parameterAnnotations; |
|
141 |
this.annotationDefault = annotationDefault; |
|
142 |
} |
|
143 |
||
144 |
/** |
|
145 |
* Package-private routine (exposed to java.lang.Class via |
|
146 |
* ReflectAccess) which returns a copy of this Method. The copy's |
|
147 |
* "root" field points to this Method. |
|
148 |
*/ |
|
149 |
Method copy() { |
|
150 |
// This routine enables sharing of MethodAccessor objects |
|
151 |
// among Method objects which refer to the same underlying |
|
152 |
// method in the VM. (All of this contortion is only necessary |
|
153 |
// because of the "accessibility" bit in AccessibleObject, |
|
154 |
// which implicitly requires that new java.lang.reflect |
|
155 |
// objects be fabricated for each reflective call on Class |
|
156 |
// objects.) |
|
26455
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
157 |
if (this.root != null) |
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
158 |
throw new IllegalArgumentException("Can not copy a non-root Method"); |
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
159 |
|
2 | 160 |
Method res = new Method(clazz, name, parameterTypes, returnType, |
161 |
exceptionTypes, modifiers, slot, signature, |
|
162 |
annotations, parameterAnnotations, annotationDefault); |
|
163 |
res.root = this; |
|
164 |
// Might as well eagerly propagate this if already present |
|
165 |
res.methodAccessor = methodAccessor; |
|
166 |
return res; |
|
167 |
} |
|
168 |
||
26455
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
169 |
/** |
32268
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
170 |
* Make a copy of a leaf method. |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
171 |
*/ |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
172 |
Method leafCopy() { |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
173 |
if (this.root == null) |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
174 |
throw new IllegalArgumentException("Can only leafCopy a non-root Method"); |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
175 |
|
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
176 |
Method res = new Method(clazz, name, parameterTypes, returnType, |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
177 |
exceptionTypes, modifiers, slot, signature, |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
178 |
annotations, parameterAnnotations, annotationDefault); |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
179 |
res.root = root; |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
180 |
res.methodAccessor = methodAccessor; |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
181 |
return res; |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
182 |
} |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
32033
diff
changeset
|
183 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42997
diff
changeset
|
184 |
/** |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42997
diff
changeset
|
185 |
* @throws InaccessibleObjectException {@inheritDoc} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42997
diff
changeset
|
186 |
* @throws SecurityException {@inheritDoc} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42997
diff
changeset
|
187 |
*/ |
36511 | 188 |
@Override |
189 |
@CallerSensitive |
|
190 |
public void setAccessible(boolean flag) { |
|
191 |
AccessibleObject.checkPermission(); |
|
192 |
if (flag) checkCanSetAccessible(Reflection.getCallerClass()); |
|
193 |
setAccessible0(flag); |
|
194 |
} |
|
195 |
||
196 |
@Override |
|
197 |
void checkCanSetAccessible(Class<?> caller) { |
|
198 |
checkCanSetAccessible(caller, clazz); |
|
199 |
} |
|
200 |
||
26455
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
201 |
@Override |
50091
05979f6ba560
8202113: Reflection API is causing caller classes to leak
mchung
parents:
49273
diff
changeset
|
202 |
Method getRoot() { |
26455
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
203 |
return root; |
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
204 |
} |
195a6f3e0cd0
8054987: (reflect) Add sharing of annotations between instances of Executable
jfranck
parents:
25859
diff
changeset
|
205 |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
206 |
@Override |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
207 |
boolean hasGenericInformation() { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
208 |
return (getGenericSignature() != null); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
209 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
210 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
211 |
@Override |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
212 |
byte[] getAnnotationBytes() { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
213 |
return annotations; |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
214 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
215 |
|
2 | 216 |
/** |
42228
dd6cc832ffd4
8169479: java.lang.reflect.Constructor class has wrong api documentation
darcy
parents:
41560
diff
changeset
|
217 |
* Returns the {@code Class} object representing the class or interface |
dd6cc832ffd4
8169479: java.lang.reflect.Constructor class has wrong api documentation
darcy
parents:
41560
diff
changeset
|
218 |
* that declares the method represented by this object. |
2 | 219 |
*/ |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
220 |
@Override |
2 | 221 |
public Class<?> getDeclaringClass() { |
222 |
return clazz; |
|
223 |
} |
|
224 |
||
225 |
/** |
|
226 |
* Returns the name of the method represented by this {@code Method} |
|
227 |
* object, as a {@code String}. |
|
228 |
*/ |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
229 |
@Override |
2 | 230 |
public String getName() { |
231 |
return name; |
|
232 |
} |
|
233 |
||
234 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
235 |
* {@inheritDoc} |
2 | 236 |
*/ |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
237 |
@Override |
2 | 238 |
public int getModifiers() { |
239 |
return modifiers; |
|
240 |
} |
|
241 |
||
242 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
243 |
* {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
244 |
* @throws GenericSignatureFormatError {@inheritDoc} |
2 | 245 |
* @since 1.5 |
246 |
*/ |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
247 |
@Override |
13795
73850c397272
7193406: Clean-up JDK Build Warnings in java.util, java.io
dxu
parents:
10342
diff
changeset
|
248 |
@SuppressWarnings({"rawtypes", "unchecked"}) |
2 | 249 |
public TypeVariable<Method>[] getTypeParameters() { |
250 |
if (getGenericSignature() != null) |
|
251 |
return (TypeVariable<Method>[])getGenericInfo().getTypeParameters(); |
|
252 |
else |
|
253 |
return (TypeVariable<Method>[])new TypeVariable[0]; |
|
254 |
} |
|
255 |
||
256 |
/** |
|
257 |
* Returns a {@code Class} object that represents the formal return type |
|
258 |
* of the method represented by this {@code Method} object. |
|
259 |
* |
|
260 |
* @return the return type for the method this object represents |
|
261 |
*/ |
|
262 |
public Class<?> getReturnType() { |
|
263 |
return returnType; |
|
264 |
} |
|
265 |
||
266 |
/** |
|
267 |
* Returns a {@code Type} object that represents the formal return |
|
268 |
* type of the method represented by this {@code Method} object. |
|
269 |
* |
|
270 |
* <p>If the return type is a parameterized type, |
|
271 |
* the {@code Type} object returned must accurately reflect |
|
55337
ae3dbc712839
7086604: (reflect) Clarifications to javadoc for getGeneric*Type methods in j.l.r
darcy
parents:
54952
diff
changeset
|
272 |
* the actual type arguments used in the source code. |
2 | 273 |
* |
274 |
* <p>If the return type is a type variable or a parameterized type, it |
|
275 |
* is created. Otherwise, it is resolved. |
|
276 |
* |
|
277 |
* @return a {@code Type} object that represents the formal return |
|
278 |
* type of the underlying method |
|
279 |
* @throws GenericSignatureFormatError |
|
280 |
* if the generic method signature does not conform to the format |
|
9266
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
9029
diff
changeset
|
281 |
* specified in |
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
9029
diff
changeset
|
282 |
* <cite>The Java™ Virtual Machine Specification</cite> |
2 | 283 |
* @throws TypeNotPresentException if the underlying method's |
284 |
* return type refers to a non-existent type declaration |
|
285 |
* @throws MalformedParameterizedTypeException if the |
|
286 |
* underlying method's return typed refers to a parameterized |
|
287 |
* type that cannot be instantiated for any reason |
|
288 |
* @since 1.5 |
|
289 |
*/ |
|
290 |
public Type getGenericReturnType() { |
|
291 |
if (getGenericSignature() != null) { |
|
292 |
return getGenericInfo().getReturnType(); |
|
293 |
} else { return getReturnType();} |
|
294 |
} |
|
295 |
||
42997
5f83f2054eca
8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents:
42948
diff
changeset
|
296 |
@Override |
5f83f2054eca
8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents:
42948
diff
changeset
|
297 |
Class<?>[] getSharedParameterTypes() { |
5f83f2054eca
8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents:
42948
diff
changeset
|
298 |
return parameterTypes; |
5f83f2054eca
8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents:
42948
diff
changeset
|
299 |
} |
5f83f2054eca
8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents:
42948
diff
changeset
|
300 |
|
49273
af8ab4f90a32
8199862: Examine ProxyBuilder::referencedTypes startup cost
redestad
parents:
47216
diff
changeset
|
301 |
@Override |
af8ab4f90a32
8199862: Examine ProxyBuilder::referencedTypes startup cost
redestad
parents:
47216
diff
changeset
|
302 |
Class<?>[] getSharedExceptionTypes() { |
af8ab4f90a32
8199862: Examine ProxyBuilder::referencedTypes startup cost
redestad
parents:
47216
diff
changeset
|
303 |
return exceptionTypes; |
af8ab4f90a32
8199862: Examine ProxyBuilder::referencedTypes startup cost
redestad
parents:
47216
diff
changeset
|
304 |
} |
af8ab4f90a32
8199862: Examine ProxyBuilder::referencedTypes startup cost
redestad
parents:
47216
diff
changeset
|
305 |
|
2 | 306 |
/** |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
307 |
* {@inheritDoc} |
2 | 308 |
*/ |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
309 |
@Override |
2 | 310 |
public Class<?>[] getParameterTypes() { |
10342
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
10127
diff
changeset
|
311 |
return parameterTypes.clone(); |
2 | 312 |
} |
313 |
||
314 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
315 |
* {@inheritDoc} |
22083
1ac4a52255f4
8030785: Missing "since 1.8" javadoc for java.lang.reflect.Method:getParameterCount
darcy
parents:
20482
diff
changeset
|
316 |
* @since 1.8 |
15294
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
317 |
*/ |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
318 |
public int getParameterCount() { return parameterTypes.length; } |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
319 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
320 |
|
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
321 |
/** |
df55735ea03c
8004729: Add java.lang.reflect.Parameter and related changes for parameter reflection
robm
parents:
14910
diff
changeset
|
322 |
* {@inheritDoc} |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
323 |
* @throws GenericSignatureFormatError {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
324 |
* @throws TypeNotPresentException {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
325 |
* @throws MalformedParameterizedTypeException {@inheritDoc} |
2 | 326 |
* @since 1.5 |
327 |
*/ |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
328 |
@Override |
2 | 329 |
public Type[] getGenericParameterTypes() { |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
330 |
return super.getGenericParameterTypes(); |
2 | 331 |
} |
332 |
||
333 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
334 |
* {@inheritDoc} |
2 | 335 |
*/ |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
336 |
@Override |
2 | 337 |
public Class<?>[] getExceptionTypes() { |
10342
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
10127
diff
changeset
|
338 |
return exceptionTypes.clone(); |
2 | 339 |
} |
340 |
||
341 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
342 |
* {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
343 |
* @throws GenericSignatureFormatError {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
344 |
* @throws TypeNotPresentException {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
345 |
* @throws MalformedParameterizedTypeException {@inheritDoc} |
2 | 346 |
* @since 1.5 |
347 |
*/ |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
348 |
@Override |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
349 |
public Type[] getGenericExceptionTypes() { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
350 |
return super.getGenericExceptionTypes(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
351 |
} |
2 | 352 |
|
353 |
/** |
|
354 |
* Compares this {@code Method} against the specified object. Returns |
|
355 |
* true if the objects are the same. Two {@code Methods} are the same if |
|
356 |
* they were declared by the same class and have the same name |
|
357 |
* and formal parameter types and return type. |
|
358 |
*/ |
|
359 |
public boolean equals(Object obj) { |
|
360 |
if (obj != null && obj instanceof Method) { |
|
361 |
Method other = (Method)obj; |
|
362 |
if ((getDeclaringClass() == other.getDeclaringClass()) |
|
363 |
&& (getName() == other.getName())) { |
|
364 |
if (!returnType.equals(other.getReturnType())) |
|
365 |
return false; |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
366 |
return equalParamTypes(parameterTypes, other.parameterTypes); |
2 | 367 |
} |
368 |
} |
|
369 |
return false; |
|
370 |
} |
|
371 |
||
372 |
/** |
|
373 |
* Returns a hashcode for this {@code Method}. The hashcode is computed |
|
374 |
* as the exclusive-or of the hashcodes for the underlying |
|
375 |
* method's declaring class name and the method's name. |
|
376 |
*/ |
|
377 |
public int hashCode() { |
|
378 |
return getDeclaringClass().getName().hashCode() ^ getName().hashCode(); |
|
379 |
} |
|
380 |
||
381 |
/** |
|
382 |
* Returns a string describing this {@code Method}. The string is |
|
383 |
* formatted as the method access modifiers, if any, followed by |
|
384 |
* the method return type, followed by a space, followed by the |
|
385 |
* class declaring the method, followed by a period, followed by |
|
386 |
* the method name, followed by a parenthesized, comma-separated |
|
387 |
* list of the method's formal parameter types. If the method |
|
388 |
* throws checked exceptions, the parameter list is followed by a |
|
42228
dd6cc832ffd4
8169479: java.lang.reflect.Constructor class has wrong api documentation
darcy
parents:
41560
diff
changeset
|
389 |
* space, followed by the word "{@code throws}" followed by a |
2 | 390 |
* comma-separated list of the thrown exception types. |
391 |
* For example: |
|
392 |
* <pre> |
|
393 |
* public boolean java.lang.Object.equals(java.lang.Object) |
|
394 |
* </pre> |
|
395 |
* |
|
396 |
* <p>The access modifiers are placed in canonical order as |
|
397 |
* specified by "The Java Language Specification". This is |
|
398 |
* {@code public}, {@code protected} or {@code private} first, |
|
399 |
* and then other modifiers in the following order: |
|
16743
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
400 |
* {@code abstract}, {@code default}, {@code static}, {@code final}, |
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
401 |
* {@code synchronized}, {@code native}, {@code strictfp}. |
16729
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16496
diff
changeset
|
402 |
* |
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16496
diff
changeset
|
403 |
* @return a string describing this {@code Method} |
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16496
diff
changeset
|
404 |
* |
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16496
diff
changeset
|
405 |
* @jls 8.4.3 Method Modifiers |
54952
a978d86ac389
8224175: Fix inconsistencies in @jls and @jvms tags
darcy
parents:
52427
diff
changeset
|
406 |
* @jls 9.4 Method Declarations |
29125
83b9bf8a6c2a
8073952: Spec of j.l.r.Method.toString/toGenericString need to be clarified
darcy
parents:
26455
diff
changeset
|
407 |
* @jls 9.6.1 Annotation Type Elements |
2 | 408 |
*/ |
409 |
public String toString() { |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
410 |
return sharedToString(Modifier.methodModifiers(), |
16729
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16496
diff
changeset
|
411 |
isDefault(), |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
412 |
parameterTypes, |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
413 |
exceptionTypes); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
414 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
415 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
416 |
@Override |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
417 |
void specificToStringHeader(StringBuilder sb) { |
16743
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
418 |
sb.append(getReturnType().getTypeName()).append(' '); |
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
419 |
sb.append(getDeclaringClass().getTypeName()).append('.'); |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
420 |
sb.append(getName()); |
2 | 421 |
} |
422 |
||
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
423 |
@Override |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
424 |
String toShortString() { |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
425 |
StringBuilder sb = new StringBuilder("method "); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
426 |
sb.append(getDeclaringClass().getTypeName()).append('.'); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
427 |
sb.append(getName()); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
428 |
sb.append('('); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
429 |
StringJoiner sj = new StringJoiner(","); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
430 |
for (Class<?> parameterType : getParameterTypes()) { |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
431 |
sj.add(parameterType.getTypeName()); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
432 |
} |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
433 |
sb.append(sj); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
434 |
sb.append(')'); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
435 |
return sb.toString(); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
436 |
} |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
437 |
|
2 | 438 |
/** |
52380
6b31efbf833e
6304578: (reflect) toGenericString fails to print bounds of type variables on generic methods
darcy
parents:
50735
diff
changeset
|
439 |
* Returns a string describing this {@code Method}, including type |
6b31efbf833e
6304578: (reflect) toGenericString fails to print bounds of type variables on generic methods
darcy
parents:
50735
diff
changeset
|
440 |
* parameters. The string is formatted as the method access |
2 | 441 |
* modifiers, if any, followed by an angle-bracketed |
442 |
* comma-separated list of the method's type parameters, if any, |
|
52380
6b31efbf833e
6304578: (reflect) toGenericString fails to print bounds of type variables on generic methods
darcy
parents:
50735
diff
changeset
|
443 |
* including informative bounds of the type parameters, if any, |
2 | 444 |
* followed by the method's generic return type, followed by a |
445 |
* space, followed by the class declaring the method, followed by |
|
446 |
* a period, followed by the method name, followed by a |
|
447 |
* parenthesized, comma-separated list of the method's generic |
|
448 |
* formal parameter types. |
|
449 |
* |
|
450 |
* If this method was declared to take a variable number of |
|
451 |
* arguments, instead of denoting the last parameter as |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
31671
diff
changeset
|
452 |
* "<code><i>Type</i>[]</code>", it is denoted as |
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
31671
diff
changeset
|
453 |
* "<code><i>Type</i>...</code>". |
2 | 454 |
* |
455 |
* A space is used to separate access modifiers from one another |
|
456 |
* and from the type parameters or return type. If there are no |
|
457 |
* type parameters, the type parameter list is elided; if the type |
|
458 |
* parameter list is present, a space separates the list from the |
|
459 |
* class name. If the method is declared to throw exceptions, the |
|
460 |
* parameter list is followed by a space, followed by the word |
|
42228
dd6cc832ffd4
8169479: java.lang.reflect.Constructor class has wrong api documentation
darcy
parents:
41560
diff
changeset
|
461 |
* "{@code throws}" followed by a comma-separated list of the generic |
dd6cc832ffd4
8169479: java.lang.reflect.Constructor class has wrong api documentation
darcy
parents:
41560
diff
changeset
|
462 |
* thrown exception types. |
2 | 463 |
* |
464 |
* <p>The access modifiers are placed in canonical order as |
|
465 |
* specified by "The Java Language Specification". This is |
|
466 |
* {@code public}, {@code protected} or {@code private} first, |
|
467 |
* and then other modifiers in the following order: |
|
16743
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
468 |
* {@code abstract}, {@code default}, {@code static}, {@code final}, |
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
469 |
* {@code synchronized}, {@code native}, {@code strictfp}. |
2 | 470 |
* |
471 |
* @return a string describing this {@code Method}, |
|
472 |
* include type parameters |
|
473 |
* |
|
474 |
* @since 1.5 |
|
16729
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16496
diff
changeset
|
475 |
* |
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16496
diff
changeset
|
476 |
* @jls 8.4.3 Method Modifiers |
54952
a978d86ac389
8224175: Fix inconsistencies in @jls and @jvms tags
darcy
parents:
52427
diff
changeset
|
477 |
* @jls 9.4 Method Declarations |
29125
83b9bf8a6c2a
8073952: Spec of j.l.r.Method.toString/toGenericString need to be clarified
darcy
parents:
26455
diff
changeset
|
478 |
* @jls 9.6.1 Annotation Type Elements |
2 | 479 |
*/ |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
480 |
@Override |
2 | 481 |
public String toGenericString() { |
16729
3b26e313ad81
8004979: java.lang.reflect.Modifier.toString should include "default"
darcy
parents:
16496
diff
changeset
|
482 |
return sharedToGenericString(Modifier.methodModifiers(), isDefault()); |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
483 |
} |
2 | 484 |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
485 |
@Override |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
486 |
void specificToGenericStringHeader(StringBuilder sb) { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
487 |
Type genRetType = getGenericReturnType(); |
16743
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
488 |
sb.append(genRetType.getTypeName()).append(' '); |
b0b34102bb4c
6298888: Add toGenericString to j.l.Class and getTypeName to j.l.reflect.Type
darcy
parents:
16729
diff
changeset
|
489 |
sb.append(getDeclaringClass().getTypeName()).append('.'); |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
490 |
sb.append(getName()); |
2 | 491 |
} |
492 |
||
493 |
/** |
|
494 |
* Invokes the underlying method represented by this {@code Method} |
|
495 |
* object, on the specified object with the specified parameters. |
|
496 |
* Individual parameters are automatically unwrapped to match |
|
497 |
* primitive formal parameters, and both primitive and reference |
|
498 |
* parameters are subject to method invocation conversions as |
|
499 |
* necessary. |
|
500 |
* |
|
501 |
* <p>If the underlying method is static, then the specified {@code obj} |
|
502 |
* argument is ignored. It may be null. |
|
503 |
* |
|
504 |
* <p>If the number of formal parameters required by the underlying method is |
|
505 |
* 0, the supplied {@code args} array may be of length 0 or null. |
|
506 |
* |
|
507 |
* <p>If the underlying method is an instance method, it is invoked |
|
508 |
* using dynamic method lookup as documented in The Java Language |
|
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50091
diff
changeset
|
509 |
* Specification, section 15.12.4.4; in particular, |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50091
diff
changeset
|
510 |
* overriding based on the runtime type of the target object may occur. |
2 | 511 |
* |
512 |
* <p>If the underlying method is static, the class that declared |
|
513 |
* the method is initialized if it has not already been initialized. |
|
514 |
* |
|
515 |
* <p>If the method completes normally, the value it returns is |
|
516 |
* returned to the caller of invoke; if the value has a primitive |
|
517 |
* type, it is first appropriately wrapped in an object. However, |
|
518 |
* if the value has the type of an array of a primitive type, the |
|
519 |
* elements of the array are <i>not</i> wrapped in objects; in |
|
520 |
* other words, an array of primitive type is returned. If the |
|
521 |
* underlying method return type is void, the invocation returns |
|
522 |
* null. |
|
523 |
* |
|
524 |
* @param obj the object the underlying method is invoked from |
|
525 |
* @param args the arguments used for the method call |
|
526 |
* @return the result of dispatching the method represented by |
|
527 |
* this object on {@code obj} with parameters |
|
528 |
* {@code args} |
|
529 |
* |
|
530 |
* @exception IllegalAccessException if this {@code Method} object |
|
9022
b2e8758b10fd
6543593: (reflect) Clarify private final field mutability
darcy
parents:
5506
diff
changeset
|
531 |
* is enforcing Java language access control and the underlying |
2 | 532 |
* method is inaccessible. |
533 |
* @exception IllegalArgumentException if the method is an |
|
534 |
* instance method and the specified object argument |
|
535 |
* is not an instance of the class or interface |
|
536 |
* declaring the underlying method (or of a subclass |
|
537 |
* or implementor thereof); if the number of actual |
|
538 |
* and formal parameters differ; if an unwrapping |
|
539 |
* conversion for primitive arguments fails; or if, |
|
540 |
* after possible unwrapping, a parameter value |
|
541 |
* cannot be converted to the corresponding formal |
|
542 |
* parameter type by a method invocation conversion. |
|
543 |
* @exception InvocationTargetException if the underlying method |
|
544 |
* throws an exception. |
|
545 |
* @exception NullPointerException if the specified object is null |
|
546 |
* and the method is an instance method. |
|
547 |
* @exception ExceptionInInitializerError if the initialization |
|
548 |
* provoked by this method fails. |
|
549 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16743
diff
changeset
|
550 |
@CallerSensitive |
40175
8df87018d96a
8161379: Force inline methods calling Reflection.getCallerClass
redestad
parents:
38882
diff
changeset
|
551 |
@ForceInline // to ensure Reflection.getCallerClass optimization |
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
29125
diff
changeset
|
552 |
@HotSpotIntrinsicCandidate |
2 | 553 |
public Object invoke(Object obj, Object... args) |
554 |
throws IllegalAccessException, IllegalArgumentException, |
|
555 |
InvocationTargetException |
|
556 |
{ |
|
557 |
if (!override) { |
|
36511 | 558 |
Class<?> caller = Reflection.getCallerClass(); |
41560
a66e7ee16cf9
6378384: (reflect) subclass can’t access superclass’s protected fields and methods by reflection
plevart
parents:
40175
diff
changeset
|
559 |
checkAccess(caller, clazz, |
a66e7ee16cf9
6378384: (reflect) subclass can’t access superclass’s protected fields and methods by reflection
plevart
parents:
40175
diff
changeset
|
560 |
Modifier.isStatic(modifiers) ? null : obj.getClass(), |
a66e7ee16cf9
6378384: (reflect) subclass can’t access superclass’s protected fields and methods by reflection
plevart
parents:
40175
diff
changeset
|
561 |
modifiers); |
2 | 562 |
} |
9029
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
563 |
MethodAccessor ma = methodAccessor; // read volatile |
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
564 |
if (ma == null) { |
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
565 |
ma = acquireMethodAccessor(); |
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
566 |
} |
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
567 |
return ma.invoke(obj, args); |
2 | 568 |
} |
569 |
||
570 |
/** |
|
571 |
* Returns {@code true} if this method is a bridge |
|
572 |
* method; returns {@code false} otherwise. |
|
573 |
* |
|
574 |
* @return true if and only if this method is a bridge |
|
575 |
* method as defined by the Java Language Specification. |
|
576 |
* @since 1.5 |
|
577 |
*/ |
|
578 |
public boolean isBridge() { |
|
579 |
return (getModifiers() & Modifier.BRIDGE) != 0; |
|
580 |
} |
|
581 |
||
582 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
583 |
* {@inheritDoc} |
2 | 584 |
* @since 1.5 |
585 |
*/ |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
586 |
@Override |
2 | 587 |
public boolean isVarArgs() { |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
588 |
return super.isVarArgs(); |
2 | 589 |
} |
590 |
||
591 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
592 |
* {@inheritDoc} |
14910 | 593 |
* @jls 13.1 The Form of a Binary |
2 | 594 |
* @since 1.5 |
595 |
*/ |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
596 |
@Override |
2 | 597 |
public boolean isSynthetic() { |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
598 |
return super.isSynthetic(); |
2 | 599 |
} |
600 |
||
14904 | 601 |
/** |
602 |
* Returns {@code true} if this method is a default |
|
603 |
* method; returns {@code false} otherwise. |
|
604 |
* |
|
16496 | 605 |
* A default method is a public non-abstract instance method, that |
606 |
* is, a non-static method with a body, declared in an interface |
|
607 |
* type. |
|
14904 | 608 |
* |
609 |
* @return true if and only if this method is a default |
|
610 |
* method as defined by the Java Language Specification. |
|
611 |
* @since 1.8 |
|
612 |
*/ |
|
613 |
public boolean isDefault() { |
|
16496 | 614 |
// Default methods are public non-abstract instance methods |
615 |
// declared in an interface. |
|
616 |
return ((getModifiers() & (Modifier.ABSTRACT | Modifier.PUBLIC | Modifier.STATIC)) == |
|
617 |
Modifier.PUBLIC) && getDeclaringClass().isInterface(); |
|
14904 | 618 |
} |
619 |
||
2 | 620 |
// NOTE that there is no synchronization used here. It is correct |
621 |
// (though not efficient) to generate more than one MethodAccessor |
|
622 |
// for a given Method. However, avoiding synchronization will |
|
623 |
// probably make the implementation more scalable. |
|
9029
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
624 |
private MethodAccessor acquireMethodAccessor() { |
2 | 625 |
// First check to see if one has been created yet, and take it |
626 |
// if so |
|
627 |
MethodAccessor tmp = null; |
|
628 |
if (root != null) tmp = root.getMethodAccessor(); |
|
629 |
if (tmp != null) { |
|
630 |
methodAccessor = tmp; |
|
9029
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
631 |
} else { |
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
632 |
// Otherwise fabricate one and propagate it up to the root |
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
633 |
tmp = reflectionFactory.newMethodAccessor(this); |
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
634 |
setMethodAccessor(tmp); |
2 | 635 |
} |
9029
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
636 |
|
e92fcf58f684
6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents:
9022
diff
changeset
|
637 |
return tmp; |
2 | 638 |
} |
639 |
||
640 |
// Returns MethodAccessor for this Method object, not looking up |
|
641 |
// the chain to the root |
|
642 |
MethodAccessor getMethodAccessor() { |
|
643 |
return methodAccessor; |
|
644 |
} |
|
645 |
||
646 |
// Sets the MethodAccessor for this Method object and |
|
647 |
// (recursively) its root |
|
648 |
void setMethodAccessor(MethodAccessor accessor) { |
|
649 |
methodAccessor = accessor; |
|
650 |
// Propagate up |
|
651 |
if (root != null) { |
|
652 |
root.setMethodAccessor(accessor); |
|
653 |
} |
|
654 |
} |
|
655 |
||
656 |
/** |
|
657 |
* Returns the default value for the annotation member represented by |
|
658 |
* this {@code Method} instance. If the member is of a primitive type, |
|
659 |
* an instance of the corresponding wrapper type is returned. Returns |
|
660 |
* null if no default is associated with the member, or if the method |
|
661 |
* instance does not represent a declared member of an annotation type. |
|
662 |
* |
|
663 |
* @return the default value for the annotation member represented |
|
664 |
* by this {@code Method} instance. |
|
665 |
* @throws TypeNotPresentException if the annotation is of type |
|
666 |
* {@link Class} and no definition can be found for the |
|
667 |
* default class value. |
|
668 |
* @since 1.5 |
|
669 |
*/ |
|
670 |
public Object getDefaultValue() { |
|
671 |
if (annotationDefault == null) |
|
672 |
return null; |
|
3959
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
3941
diff
changeset
|
673 |
Class<?> memberType = AnnotationType.invocationHandlerReturnType( |
2 | 674 |
getReturnType()); |
675 |
Object result = AnnotationParser.parseMemberValue( |
|
676 |
memberType, ByteBuffer.wrap(annotationDefault), |
|
32834
e1dca5fe4de3
8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents:
32268
diff
changeset
|
677 |
SharedSecrets.getJavaLangAccess(). |
2 | 678 |
getConstantPool(getDeclaringClass()), |
679 |
getDeclaringClass()); |
|
38882
efb06b82374b
5041778: (ann) AnnotationFormatError if "default" Class type not found
darcy
parents:
37363
diff
changeset
|
680 |
if (result instanceof ExceptionProxy) { |
efb06b82374b
5041778: (ann) AnnotationFormatError if "default" Class type not found
darcy
parents:
37363
diff
changeset
|
681 |
if (result instanceof TypeNotPresentExceptionProxy) { |
efb06b82374b
5041778: (ann) AnnotationFormatError if "default" Class type not found
darcy
parents:
37363
diff
changeset
|
682 |
TypeNotPresentExceptionProxy proxy = (TypeNotPresentExceptionProxy)result; |
efb06b82374b
5041778: (ann) AnnotationFormatError if "default" Class type not found
darcy
parents:
37363
diff
changeset
|
683 |
throw new TypeNotPresentException(proxy.typeName(), proxy.getCause()); |
efb06b82374b
5041778: (ann) AnnotationFormatError if "default" Class type not found
darcy
parents:
37363
diff
changeset
|
684 |
} |
2 | 685 |
throw new AnnotationFormatError("Invalid default: " + this); |
38882
efb06b82374b
5041778: (ann) AnnotationFormatError if "default" Class type not found
darcy
parents:
37363
diff
changeset
|
686 |
} |
2 | 687 |
return result; |
688 |
} |
|
689 |
||
690 |
/** |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
691 |
* {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
692 |
* @throws NullPointerException {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
693 |
* @since 1.5 |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
694 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
695 |
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
696 |
return super.getAnnotation(annotationClass); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
697 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
698 |
|
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
699 |
/** |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
700 |
* {@inheritDoc} |
2 | 701 |
* @since 1.5 |
702 |
*/ |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
703 |
public Annotation[] getDeclaredAnnotations() { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
704 |
return super.getDeclaredAnnotations(); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
705 |
} |
2 | 706 |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
707 |
/** |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
708 |
* {@inheritDoc} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
709 |
* @since 1.5 |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
710 |
*/ |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
711 |
@Override |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
712 |
public Annotation[][] getParameterAnnotations() { |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
713 |
return sharedGetParameterAnnotations(parameterTypes, parameterAnnotations); |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
714 |
} |
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
715 |
|
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
716 |
/** |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
717 |
* {@inheritDoc} |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
718 |
* @since 1.8 |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
719 |
*/ |
16058
5b8d8cec6280
8007808: Missing method: Executable.getAnnotatedReturnType()
jfranck
parents:
15510
diff
changeset
|
720 |
@Override |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
721 |
public AnnotatedType getAnnotatedReturnType() { |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
722 |
return getAnnotatedReturnType0(getGenericReturnType()); |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
723 |
} |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
15294
diff
changeset
|
724 |
|
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
725 |
@Override |
45332
9c9e51c44638
8074977: Constructor.getAnnotatedParameterTypes returns wrong value
darcy
parents:
44359
diff
changeset
|
726 |
boolean handleParameterNumberMismatch(int resultLength, int numParameters) { |
10127
c85d1ec57ee7
7007535: (reflect) Please generalize Constructor and Method
darcy
parents:
9266
diff
changeset
|
727 |
throw new AnnotationFormatError("Parameter annotations don't match number of parameters"); |
2 | 728 |
} |
729 |
} |