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