269 * parameter types of the underlying executable, in declaration order
270 * @throws GenericSignatureFormatError
271 * if the generic method signature does not conform to the format
272 * specified in
273 * <cite>The Java™ Virtual Machine Specification</cite>
274 * @throws TypeNotPresentException if any of the parameter
275 * types of the underlying executable refers to a non-existent type
276 * declaration
277 * @throws MalformedParameterizedTypeException if any of
278 * the underlying executable's parameter types refer to a parameterized
279 * type that cannot be instantiated for any reason
280 */
281 public Type[] getGenericParameterTypes() {
282 if (hasGenericInformation())
283 return getGenericInfo().getParameterTypes();
284 else
285 return getParameterTypes();
286 }
287
288 /**
289 * Returns an array of {@code Parameter} objects that represent
290 * all the parameters to the underlying executable represented by
291 * this object. Returns an array of length 0 if the executable
292 * has no parameters.
293 *
294 * <p>The parameters of the underlying executable do not necessarily
295 * have unique names, or names that are legal identifiers in the
296 * Java programming language (JLS 3.8).
297 *
298 * @throws MalformedParametersException if the class file contains
299 * a MethodParameters attribute that is improperly formatted.
300 * @return an array of {@code Parameter} objects representing all
301 * the parameters to the executable this object represents.
302 */
303 public Parameter[] getParameters() {
304 // TODO: This may eventually need to be guarded by security
305 // mechanisms similar to those in Field, Method, etc.
306 //
307 // Need to copy the cached array to prevent users from messing
308 // with it. Since parameters are immutable, we can
629 /**
630 * Returns an array of {@code AnnotatedType} objects that represent the use
631 * of types to specify formal parameter types of the method/constructor
632 * represented by this Executable. The order of the objects in the array
633 * corresponds to the order of the formal parameter types in the
634 * declaration of the method/constructor.
635 *
636 * Returns an array of length 0 if the method/constructor declares no
637 * parameters.
638 *
639 * @return an array of objects representing the types of the
640 * formal parameters of the method or constructor represented by this
641 * {@code Executable}
642 */
643 public AnnotatedType[] getAnnotatedParameterTypes() {
644 return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes0(),
645 sun.misc.SharedSecrets.getJavaLangAccess().
646 getConstantPool(getDeclaringClass()),
647 this,
648 getDeclaringClass(),
649 getGenericParameterTypes(),
650 TypeAnnotation.TypeAnnotationTarget.METHOD_FORMAL_PARAMETER);
651 }
652
653 /**
654 * Returns an array of {@code AnnotatedType} objects that represent the use
655 * of types to specify the declared exceptions of the method/constructor
656 * represented by this Executable. The order of the objects in the array
657 * corresponds to the order of the exception types in the declaration of
658 * the method/constructor.
659 *
660 * Returns an array of length 0 if the method/constructor declares no
661 * exceptions.
662 *
663 * @return an array of objects representing the declared
664 * exceptions of the method or constructor represented by this {@code
665 * Executable}
666 */
667 public AnnotatedType[] getAnnotatedExceptionTypes() {
668 return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes0(),
669 sun.misc.SharedSecrets.getJavaLangAccess().
|
269 * parameter types of the underlying executable, in declaration order
270 * @throws GenericSignatureFormatError
271 * if the generic method signature does not conform to the format
272 * specified in
273 * <cite>The Java™ Virtual Machine Specification</cite>
274 * @throws TypeNotPresentException if any of the parameter
275 * types of the underlying executable refers to a non-existent type
276 * declaration
277 * @throws MalformedParameterizedTypeException if any of
278 * the underlying executable's parameter types refer to a parameterized
279 * type that cannot be instantiated for any reason
280 */
281 public Type[] getGenericParameterTypes() {
282 if (hasGenericInformation())
283 return getGenericInfo().getParameterTypes();
284 else
285 return getParameterTypes();
286 }
287
288 /**
289 * Behaves like {@code getGenericParameterTypes}, but returns type
290 * information for all parameters, including synthetic parameters.
291 */
292 Type[] getAllGenericParameterTypes() {
293 Type[] tmp = allGenericParams;
294 if (tmp == null) {
295 tmp = privateGetAllGenericParameterTypes();
296 allGenericParams = tmp;
297 }
298 return tmp;
299 }
300
301 private Type[] privateGetAllGenericParameterTypes() {
302 final boolean genericInfo = hasGenericInformation();
303
304 // Easy case: we don't have generic parameter information. In
305 // this case, we just return the result of
306 // getParameterTypes().
307 if (!genericInfo) {
308 return getParameterTypes();
309 } else {
310 final boolean realParamData = hasRealParameterData();
311 final Type[] genericParamTypes = getGenericParameterTypes();
312 final Type[] nonGenericParamTypes = getParameterTypes();
313 final Type[] out = new Type[nonGenericParamTypes.length];
314 final Parameter[] params = getParameters();
315 int fromidx = 0;
316 // If we have real parameter data, then we use the
317 // synthetic and mandate flags to our advantage.
318 if (realParamData) {
319 for (int i = 0; i < out.length; i++) {
320 final Parameter param = params[i];
321 if (param.isSynthetic() || param.isImplicit()) {
322 // If we hit a synthetic or mandated parameter,
323 // use the non generic parameter info.
324 out[i] = nonGenericParamTypes[i];
325 } else {
326 // Otherwise, use the generic parameter info.
327 out[i] = genericParamTypes[fromidx];
328 fromidx++;
329 }
330 }
331 } else {
332 // Otherwise, use the non-generic parameter data.
333 // Without method parameter reflection data, we have
334 // no way to figure out which parameters are
335 // synthetic/mandated, thus, no way to match up the
336 // indexes.
337 return genericParamTypes.length == nonGenericParamTypes.length ?
338 genericParamTypes : nonGenericParamTypes;
339 }
340 return out;
341 }
342 }
343
344 private transient volatile Type[] allGenericParams;
345
346 /**
347 * Returns an array of {@code Parameter} objects that represent
348 * all the parameters to the underlying executable represented by
349 * this object. Returns an array of length 0 if the executable
350 * has no parameters.
351 *
352 * <p>The parameters of the underlying executable do not necessarily
353 * have unique names, or names that are legal identifiers in the
354 * Java programming language (JLS 3.8).
355 *
356 * @throws MalformedParametersException if the class file contains
357 * a MethodParameters attribute that is improperly formatted.
358 * @return an array of {@code Parameter} objects representing all
359 * the parameters to the executable this object represents.
360 */
361 public Parameter[] getParameters() {
362 // TODO: This may eventually need to be guarded by security
363 // mechanisms similar to those in Field, Method, etc.
364 //
365 // Need to copy the cached array to prevent users from messing
366 // with it. Since parameters are immutable, we can
687 /**
688 * Returns an array of {@code AnnotatedType} objects that represent the use
689 * of types to specify formal parameter types of the method/constructor
690 * represented by this Executable. The order of the objects in the array
691 * corresponds to the order of the formal parameter types in the
692 * declaration of the method/constructor.
693 *
694 * Returns an array of length 0 if the method/constructor declares no
695 * parameters.
696 *
697 * @return an array of objects representing the types of the
698 * formal parameters of the method or constructor represented by this
699 * {@code Executable}
700 */
701 public AnnotatedType[] getAnnotatedParameterTypes() {
702 return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes0(),
703 sun.misc.SharedSecrets.getJavaLangAccess().
704 getConstantPool(getDeclaringClass()),
705 this,
706 getDeclaringClass(),
707 getAllGenericParameterTypes(),
708 TypeAnnotation.TypeAnnotationTarget.METHOD_FORMAL_PARAMETER);
709 }
710
711 /**
712 * Returns an array of {@code AnnotatedType} objects that represent the use
713 * of types to specify the declared exceptions of the method/constructor
714 * represented by this Executable. The order of the objects in the array
715 * corresponds to the order of the exception types in the declaration of
716 * the method/constructor.
717 *
718 * Returns an array of length 0 if the method/constructor declares no
719 * exceptions.
720 *
721 * @return an array of objects representing the declared
722 * exceptions of the method or constructor represented by this {@code
723 * Executable}
724 */
725 public AnnotatedType[] getAnnotatedExceptionTypes() {
726 return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes0(),
727 sun.misc.SharedSecrets.getJavaLangAccess().
|