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