158 // |
161 // |
159 // Routines used by java.lang.reflect |
162 // Routines used by java.lang.reflect |
160 // |
163 // |
161 // |
164 // |
162 |
165 |
163 /** Called only by java.lang.reflect.Modifier's static initializer */ |
166 /* |
164 public void setLangReflectAccess(LangReflectAccess access) { |
|
165 langReflectAccess = access; |
|
166 } |
|
167 |
|
168 /** |
|
169 * Note: this routine can cause the declaring class for the field |
167 * Note: this routine can cause the declaring class for the field |
170 * be initialized and therefore must not be called until the |
168 * be initialized and therefore must not be called until the |
171 * first get/set of this field. |
169 * first get/set of this field. |
172 * @param field the field |
170 * @param field the field |
173 * @param override true if caller has overridden accessibility |
171 * @param override true if caller has overridden accessibility |
174 */ |
172 */ |
175 public FieldAccessor newFieldAccessor(Field field, boolean override) { |
173 public FieldAccessor newFieldAccessor(Field field, boolean override) { |
176 checkInitted(); |
174 checkInitted(); |
177 |
175 |
178 Field root = langReflectAccess().getRoot(field); |
176 Field root = langReflectAccess.getRoot(field); |
179 if (root != null) { |
177 if (root != null) { |
180 // FieldAccessor will use the root unless the modifiers have |
178 // FieldAccessor will use the root unless the modifiers have |
181 // been overrridden |
179 // been overrridden |
182 if (root.getModifiers() == field.getModifiers() || !override) { |
180 if (root.getModifiers() == field.getModifiers() || !override) { |
183 field = root; |
181 field = root; |
266 // |
264 // |
267 // Routines used by java.lang |
265 // Routines used by java.lang |
268 // |
266 // |
269 // |
267 // |
270 |
268 |
271 /** Creates a new java.lang.reflect.Field. Access checks as per |
|
272 java.lang.reflect.AccessibleObject are not overridden. */ |
|
273 public Field newField(Class<?> declaringClass, |
|
274 String name, |
|
275 Class<?> type, |
|
276 int modifiers, |
|
277 int slot, |
|
278 String signature, |
|
279 byte[] annotations) |
|
280 { |
|
281 return langReflectAccess().newField(declaringClass, |
|
282 name, |
|
283 type, |
|
284 modifiers, |
|
285 slot, |
|
286 signature, |
|
287 annotations); |
|
288 } |
|
289 |
|
290 /** Creates a new java.lang.reflect.Method. Access checks as per |
|
291 java.lang.reflect.AccessibleObject are not overridden. */ |
|
292 public Method newMethod(Class<?> declaringClass, |
|
293 String name, |
|
294 Class<?>[] parameterTypes, |
|
295 Class<?> returnType, |
|
296 Class<?>[] checkedExceptions, |
|
297 int modifiers, |
|
298 int slot, |
|
299 String signature, |
|
300 byte[] annotations, |
|
301 byte[] parameterAnnotations, |
|
302 byte[] annotationDefault) |
|
303 { |
|
304 return langReflectAccess().newMethod(declaringClass, |
|
305 name, |
|
306 parameterTypes, |
|
307 returnType, |
|
308 checkedExceptions, |
|
309 modifiers, |
|
310 slot, |
|
311 signature, |
|
312 annotations, |
|
313 parameterAnnotations, |
|
314 annotationDefault); |
|
315 } |
|
316 |
|
317 /** Creates a new java.lang.reflect.Constructor. Access checks as |
269 /** Creates a new java.lang.reflect.Constructor. Access checks as |
318 per java.lang.reflect.AccessibleObject are not overridden. */ |
270 per java.lang.reflect.AccessibleObject are not overridden. */ |
319 public Constructor<?> newConstructor(Class<?> declaringClass, |
271 public Constructor<?> newConstructor(Class<?> declaringClass, |
320 Class<?>[] parameterTypes, |
272 Class<?>[] parameterTypes, |
321 Class<?>[] checkedExceptions, |
273 Class<?>[] checkedExceptions, |
323 int slot, |
275 int slot, |
324 String signature, |
276 String signature, |
325 byte[] annotations, |
277 byte[] annotations, |
326 byte[] parameterAnnotations) |
278 byte[] parameterAnnotations) |
327 { |
279 { |
328 return langReflectAccess().newConstructor(declaringClass, |
280 return langReflectAccess.newConstructor(declaringClass, |
329 parameterTypes, |
281 parameterTypes, |
330 checkedExceptions, |
282 checkedExceptions, |
331 modifiers, |
283 modifiers, |
332 slot, |
284 slot, |
333 signature, |
285 signature, |
334 annotations, |
286 annotations, |
335 parameterAnnotations); |
287 parameterAnnotations); |
336 } |
|
337 |
|
338 /** Gets the MethodAccessor object for a java.lang.reflect.Method */ |
|
339 public MethodAccessor getMethodAccessor(Method m) { |
|
340 return langReflectAccess().getMethodAccessor(m); |
|
341 } |
|
342 |
|
343 /** Sets the MethodAccessor object for a java.lang.reflect.Method */ |
|
344 public void setMethodAccessor(Method m, MethodAccessor accessor) { |
|
345 langReflectAccess().setMethodAccessor(m, accessor); |
|
346 } |
288 } |
347 |
289 |
348 /** Gets the ConstructorAccessor object for a |
290 /** Gets the ConstructorAccessor object for a |
349 java.lang.reflect.Constructor */ |
291 java.lang.reflect.Constructor */ |
350 public ConstructorAccessor getConstructorAccessor(Constructor<?> c) { |
292 public ConstructorAccessor getConstructorAccessor(Constructor<?> c) { |
351 return langReflectAccess().getConstructorAccessor(c); |
293 return langReflectAccess.getConstructorAccessor(c); |
352 } |
294 } |
353 |
295 |
354 /** Sets the ConstructorAccessor object for a |
296 /** Sets the ConstructorAccessor object for a |
355 java.lang.reflect.Constructor */ |
297 java.lang.reflect.Constructor */ |
356 public void setConstructorAccessor(Constructor<?> c, |
298 public void setConstructorAccessor(Constructor<?> c, |
357 ConstructorAccessor accessor) |
299 ConstructorAccessor accessor) |
358 { |
300 { |
359 langReflectAccess().setConstructorAccessor(c, accessor); |
301 langReflectAccess.setConstructorAccessor(c, accessor); |
360 } |
302 } |
361 |
303 |
362 /** Makes a copy of the passed method. The returned method is a |
304 /** Makes a copy of the passed method. The returned method is a |
363 "child" of the passed one; see the comments in Method.java for |
305 "child" of the passed one; see the comments in Method.java for |
364 details. */ |
306 details. */ |
365 public Method copyMethod(Method arg) { |
307 public Method copyMethod(Method arg) { |
366 return langReflectAccess().copyMethod(arg); |
308 return langReflectAccess.copyMethod(arg); |
367 } |
309 } |
368 |
310 |
369 /** Makes a copy of the passed method. The returned method is NOT |
311 /** Makes a copy of the passed method. The returned method is NOT |
370 * a "child" but a "sibling" of the Method in arg. Should only be |
312 * a "child" but a "sibling" of the Method in arg. Should only be |
371 * used on non-root methods. */ |
313 * used on non-root methods. */ |
372 public Method leafCopyMethod(Method arg) { |
314 public Method leafCopyMethod(Method arg) { |
373 return langReflectAccess().leafCopyMethod(arg); |
315 return langReflectAccess.leafCopyMethod(arg); |
374 } |
316 } |
375 |
317 |
376 |
318 |
377 /** Makes a copy of the passed field. The returned field is a |
319 /** Makes a copy of the passed field. The returned field is a |
378 "child" of the passed one; see the comments in Field.java for |
320 "child" of the passed one; see the comments in Field.java for |
379 details. */ |
321 details. */ |
380 public Field copyField(Field arg) { |
322 public Field copyField(Field arg) { |
381 return langReflectAccess().copyField(arg); |
323 return langReflectAccess.copyField(arg); |
382 } |
324 } |
383 |
325 |
384 /** Makes a copy of the passed constructor. The returned |
326 /** Makes a copy of the passed constructor. The returned |
385 constructor is a "child" of the passed one; see the comments |
327 constructor is a "child" of the passed one; see the comments |
386 in Constructor.java for details. */ |
328 in Constructor.java for details. */ |
387 public <T> Constructor<T> copyConstructor(Constructor<T> arg) { |
329 public <T> Constructor<T> copyConstructor(Constructor<T> arg) { |
388 return langReflectAccess().copyConstructor(arg); |
330 return langReflectAccess.copyConstructor(arg); |
389 } |
331 } |
390 |
332 |
391 /** Gets the byte[] that encodes TypeAnnotations on an executable. |
333 /** Gets the byte[] that encodes TypeAnnotations on an executable. |
392 */ |
334 */ |
393 public byte[] getExecutableTypeAnnotationBytes(Executable ex) { |
335 public byte[] getExecutableTypeAnnotationBytes(Executable ex) { |
394 return langReflectAccess().getExecutableTypeAnnotationBytes(ex); |
336 return langReflectAccess.getExecutableTypeAnnotationBytes(ex); |
395 } |
337 } |
396 |
338 |
397 public Class<?>[] getExecutableSharedParameterTypes(Executable ex) { |
339 public Class<?>[] getExecutableSharedParameterTypes(Executable ex) { |
398 return langReflectAccess().getExecutableSharedParameterTypes(ex); |
340 return langReflectAccess.getExecutableSharedParameterTypes(ex); |
399 } |
341 } |
400 |
342 |
401 public <T> T newInstance(Constructor<T> ctor, Object[] args, Class<?> caller) |
343 public <T> T newInstance(Constructor<T> ctor, Object[] args, Class<?> caller) |
402 throws IllegalAccessException, InstantiationException, InvocationTargetException |
344 throws IllegalAccessException, InstantiationException, InvocationTargetException |
403 { |
345 { |
404 return langReflectAccess().newInstance(ctor, args, caller); |
346 return langReflectAccess.newInstance(ctor, args, caller); |
405 } |
347 } |
406 |
348 |
407 //-------------------------------------------------------------------------- |
349 //-------------------------------------------------------------------------- |
408 // |
350 // |
409 // Routines used by serialization |
351 // Routines used by serialization |
524 constructorToCall.getDeclaringClass()); |
466 constructorToCall.getDeclaringClass()); |
525 Constructor<?> c = newConstructor(constructorToCall.getDeclaringClass(), |
467 Constructor<?> c = newConstructor(constructorToCall.getDeclaringClass(), |
526 constructorToCall.getParameterTypes(), |
468 constructorToCall.getParameterTypes(), |
527 constructorToCall.getExceptionTypes(), |
469 constructorToCall.getExceptionTypes(), |
528 constructorToCall.getModifiers(), |
470 constructorToCall.getModifiers(), |
529 langReflectAccess(). |
471 langReflectAccess. |
530 getConstructorSlot(constructorToCall), |
472 getConstructorSlot(constructorToCall), |
531 langReflectAccess(). |
473 langReflectAccess. |
532 getConstructorSignature(constructorToCall), |
474 getConstructorSignature(constructorToCall), |
533 langReflectAccess(). |
475 langReflectAccess. |
534 getConstructorAnnotations(constructorToCall), |
476 getConstructorAnnotations(constructorToCall), |
535 langReflectAccess(). |
477 langReflectAccess. |
536 getConstructorParameterAnnotations(constructorToCall)); |
478 getConstructorParameterAnnotations(constructorToCall)); |
537 setConstructorAccessor(c, acc); |
479 setConstructorAccessor(c, acc); |
538 c.setAccessible(true); |
480 c.setAccessible(true); |
539 return c; |
481 return c; |
540 } |
482 } |