527 * represent the annotations on the formal parameters, in 528 * declaration order, of the {@code Executable} represented by 529 * this object. Synthetic and mandated parameters (see 530 * explanation below), such as the outer "this" parameter to an 531 * inner class constructor will be represented in the returned 532 * array. If the executable has no parameters (meaning no formal, 533 * no synthetic, and no mandated parameters), a zero-length array 534 * will be returned. If the {@code Executable} has one or more 535 * parameters, a nested array of length zero is returned for each 536 * parameter with no annotations. The annotation objects contained 537 * in the returned arrays are serializable. The caller of this 538 * method is free to modify the returned arrays; it will have no 539 * effect on the arrays returned to other callers. 540 * 541 * A compiler may add extra parameters that are implicitly 542 * declared in source ("mandated"), as well as parameters that 543 * are neither implicitly nor explicitly declared in source 544 * ("synthetic") to the parameter list for a method. See {@link 545 * java.lang.reflect.Parameter} for more information. 546 * 547 * @see java.lang.reflect.Parameter 548 * @see java.lang.reflect.Parameter#getAnnotations 549 * @return an array of arrays that represent the annotations on 550 * the formal and implicit parameters, in declaration order, of 551 * the executable represented by this object 552 */ 553 public abstract Annotation[][] getParameterAnnotations(); 554 555 Annotation[][] sharedGetParameterAnnotations(Class<?>[] parameterTypes, 556 byte[] parameterAnnotations) { 557 int numParameters = parameterTypes.length; 558 if (parameterAnnotations == null) 559 return new Annotation[numParameters][0]; 560 561 Annotation[][] result = parseParameterAnnotations(parameterAnnotations); 562 563 if (result.length != numParameters && 564 handleParameterNumberMismatch(result.length, numParameters)) { 565 Annotation[][] tmp = new Annotation[result.length+1][]; 566 // Shift annotations down one to account for an implicit leading parameter 567 System.arraycopy(result, 0, tmp, 1, result.length); 568 tmp[0] = new Annotation[0]; 569 result = tmp; 570 } 571 return result; 572 } 573 574 abstract boolean handleParameterNumberMismatch(int resultLength, int numParameters); 575 576 /** 577 * {@inheritDoc} 578 * @throws NullPointerException {@inheritDoc} 579 */ 580 public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { 581 Objects.requireNonNull(annotationClass); 582 return annotationClass.cast(declaredAnnotations().get(annotationClass)); 583 } 584 585 /** 586 * {@inheritDoc} 587 * @throws NullPointerException {@inheritDoc} 588 */ 589 @Override 590 public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) { 591 Objects.requireNonNull(annotationClass); 592 593 return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass); 594 } 595 596 /** 597 * {@inheritDoc} 598 */ 599 public Annotation[] getDeclaredAnnotations() { 600 return AnnotationParser.toArray(declaredAnnotations()); 601 } 602 603 private transient volatile Map<Class<? extends Annotation>, Annotation> declaredAnnotations; 604 605 private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() { 606 Map<Class<? extends Annotation>, Annotation> declAnnos; 607 if ((declAnnos = declaredAnnotations) == null) { 608 synchronized (this) { 609 if ((declAnnos = declaredAnnotations) == null) { 610 Executable root = (Executable)getRoot(); 611 if (root != null) { 612 declAnnos = root.declaredAnnotations(); 613 } else { 614 declAnnos = AnnotationParser.parseAnnotations( 615 getAnnotationBytes(), 616 SharedSecrets.getJavaLangAccess(). 617 getConstantPool(getDeclaringClass()), 618 getDeclaringClass() | 527 * represent the annotations on the formal parameters, in 528 * declaration order, of the {@code Executable} represented by 529 * this object. Synthetic and mandated parameters (see 530 * explanation below), such as the outer "this" parameter to an 531 * inner class constructor will be represented in the returned 532 * array. If the executable has no parameters (meaning no formal, 533 * no synthetic, and no mandated parameters), a zero-length array 534 * will be returned. If the {@code Executable} has one or more 535 * parameters, a nested array of length zero is returned for each 536 * parameter with no annotations. The annotation objects contained 537 * in the returned arrays are serializable. The caller of this 538 * method is free to modify the returned arrays; it will have no 539 * effect on the arrays returned to other callers. 540 * 541 * A compiler may add extra parameters that are implicitly 542 * declared in source ("mandated"), as well as parameters that 543 * are neither implicitly nor explicitly declared in source 544 * ("synthetic") to the parameter list for a method. See {@link 545 * java.lang.reflect.Parameter} for more information. 546 * 547 * <p>Note that any annotations returned by this method are 548 * declaration annotations. 549 * 550 * @see java.lang.reflect.Parameter 551 * @see java.lang.reflect.Parameter#getAnnotations 552 * @return an array of arrays that represent the annotations on 553 * the formal and implicit parameters, in declaration order, of 554 * the executable represented by this object 555 */ 556 public abstract Annotation[][] getParameterAnnotations(); 557 558 Annotation[][] sharedGetParameterAnnotations(Class<?>[] parameterTypes, 559 byte[] parameterAnnotations) { 560 int numParameters = parameterTypes.length; 561 if (parameterAnnotations == null) 562 return new Annotation[numParameters][0]; 563 564 Annotation[][] result = parseParameterAnnotations(parameterAnnotations); 565 566 if (result.length != numParameters && 567 handleParameterNumberMismatch(result.length, numParameters)) { 568 Annotation[][] tmp = new Annotation[result.length+1][]; 569 // Shift annotations down one to account for an implicit leading parameter 570 System.arraycopy(result, 0, tmp, 1, result.length); 571 tmp[0] = new Annotation[0]; 572 result = tmp; 573 } 574 return result; 575 } 576 577 abstract boolean handleParameterNumberMismatch(int resultLength, int numParameters); 578 579 /** 580 * {@inheritDoc} 581 * @throws NullPointerException {@inheritDoc} 582 */ 583 @Override 584 public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { 585 Objects.requireNonNull(annotationClass); 586 return annotationClass.cast(declaredAnnotations().get(annotationClass)); 587 } 588 589 /** 590 * {@inheritDoc} 591 * 592 * @throws NullPointerException {@inheritDoc} 593 */ 594 @Override 595 public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) { 596 Objects.requireNonNull(annotationClass); 597 598 return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass); 599 } 600 601 /** 602 * {@inheritDoc} 603 */ 604 @Override 605 public Annotation[] getDeclaredAnnotations() { 606 return AnnotationParser.toArray(declaredAnnotations()); 607 } 608 609 private transient volatile Map<Class<? extends Annotation>, Annotation> declaredAnnotations; 610 611 private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() { 612 Map<Class<? extends Annotation>, Annotation> declAnnos; 613 if ((declAnnos = declaredAnnotations) == null) { 614 synchronized (this) { 615 if ((declAnnos = declaredAnnotations) == null) { 616 Executable root = (Executable)getRoot(); 617 if (root != null) { 618 declAnnos = root.declaredAnnotations(); 619 } else { 620 declAnnos = AnnotationParser.parseAnnotations( 621 getAnnotationBytes(), 622 SharedSecrets.getJavaLangAccess(). 623 getConstantPool(getDeclaringClass()), 624 getDeclaringClass() |