526 * parameters, a nested array of length zero is returned for each 527 * parameter with no annotations. The annotation objects contained 528 * in the returned arrays are serializable. The caller of this 529 * method is free to modify the returned arrays; it will have no 530 * effect on the arrays returned to other callers. 531 * 532 * A compiler may add extra parameters that are implicitly 533 * declared in source ("mandated"), as well as parameters that 534 * are neither implicitly nor explicitly declared in source 535 * ("synthetic") to the parameter list for a method. See {@link 536 * java.lang.reflect.Parameter} for more information. 537 * 538 * @see java.lang.reflect.Parameter 539 * @see java.lang.reflect.Parameter#getAnnotations 540 * @return an array of arrays that represent the annotations on 541 * the formal and implicit parameters, in declaration order, of 542 * the executable represented by this object 543 */ 544 public abstract Annotation[][] getParameterAnnotations(); 545 546 Annotation[][] sharedGetParameterAnnotations(Class<?>[] parameterTypes, 547 byte[] parameterAnnotations) { 548 int numParameters = parameterTypes.length; 549 if (parameterAnnotations == null) 550 return new Annotation[numParameters][0]; 551 552 Annotation[][] result = parseParameterAnnotations(parameterAnnotations); 553 554 if (result.length != numParameters) 555 handleParameterNumberMismatch(result.length, numParameters); 556 return result; 557 } 558 559 abstract void handleParameterNumberMismatch(int resultLength, int numParameters); 560 561 /** 562 * {@inheritDoc} 563 * @throws NullPointerException {@inheritDoc} 564 */ 565 public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { 566 Objects.requireNonNull(annotationClass); 567 return annotationClass.cast(declaredAnnotations().get(annotationClass)); 568 } 569 570 /** 571 * {@inheritDoc} 572 * @throws NullPointerException {@inheritDoc} 573 */ 574 @Override 575 public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) { 576 Objects.requireNonNull(annotationClass); 577 578 return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass); 579 } | 526 * parameters, a nested array of length zero is returned for each 527 * parameter with no annotations. The annotation objects contained 528 * in the returned arrays are serializable. The caller of this 529 * method is free to modify the returned arrays; it will have no 530 * effect on the arrays returned to other callers. 531 * 532 * A compiler may add extra parameters that are implicitly 533 * declared in source ("mandated"), as well as parameters that 534 * are neither implicitly nor explicitly declared in source 535 * ("synthetic") to the parameter list for a method. See {@link 536 * java.lang.reflect.Parameter} for more information. 537 * 538 * @see java.lang.reflect.Parameter 539 * @see java.lang.reflect.Parameter#getAnnotations 540 * @return an array of arrays that represent the annotations on 541 * the formal and implicit parameters, in declaration order, of 542 * the executable represented by this object 543 */ 544 public abstract Annotation[][] getParameterAnnotations(); 545 546 void throwParameterAnnotationsDontMatchNumberOfParameters() { 547 throw new AnnotationFormatError("Parameter annotations don't match number of parameters"); 548 } 549 550 /** 551 * {@inheritDoc} 552 * @throws NullPointerException {@inheritDoc} 553 */ 554 public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { 555 Objects.requireNonNull(annotationClass); 556 return annotationClass.cast(declaredAnnotations().get(annotationClass)); 557 } 558 559 /** 560 * {@inheritDoc} 561 * @throws NullPointerException {@inheritDoc} 562 */ 563 @Override 564 public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) { 565 Objects.requireNonNull(annotationClass); 566 567 return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass); 568 } |