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 } | 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 // System.out.println("\t Calling sharedGetParameterAnnotations"); 549 int numParameters = parameterTypes.length; 550 if (parameterAnnotations == null) 551 return new Annotation[numParameters][0]; 552 553 Annotation[][] result = parseParameterAnnotations(parameterAnnotations); 554 // System.out.println("\t" + java.util.Arrays.deepToString(result)); 555 556 //System.out.println("\tresult.length " + 557 // result.length + "\tnumParameters " + numParameters); 558 if (result.length != numParameters && 559 handleParameterNumberMismatch(result.length, numParameters)) { 560 Annotation[][] tmp = new Annotation[result.length+1][]; 561 // Shift annotations down one to account for an implicit leading parameter 562 System.arraycopy(result, 0, tmp, 1, result.length); 563 tmp[0] = new Annotation[0]; 564 result = tmp; 565 } 566 return result; 567 } 568 569 abstract boolean handleParameterNumberMismatch(int resultLength, int numParameters); 570 571 /** 572 * {@inheritDoc} 573 * @throws NullPointerException {@inheritDoc} 574 */ 575 public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { 576 Objects.requireNonNull(annotationClass); 577 return annotationClass.cast(declaredAnnotations().get(annotationClass)); 578 } 579 580 /** 581 * {@inheritDoc} 582 * @throws NullPointerException {@inheritDoc} 583 */ 584 @Override 585 public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) { 586 Objects.requireNonNull(annotationClass); 587 588 return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass); 589 } |