39
40 /**
41 * A shared superclass for the common functionality of {@link Method}
42 * and {@link Constructor}.
43 *
44 * @since 1.8
45 */
46 public abstract class Executable extends AccessibleObject
47 implements Member, GenericDeclaration {
48 /*
49 * Only grant package-visibility to the constructor.
50 */
51 Executable() {}
52
53 /**
54 * Accessor method to allow code sharing
55 */
56 abstract byte[] getAnnotationBytes();
57
58 /**
59 * Accessor method to allow code sharing
60 */
61 abstract Executable getRoot();
62
63 /**
64 * Does the Executable have generic information.
65 */
66 abstract boolean hasGenericInformation();
67
68 abstract ConstructorRepository getGenericInfo();
69
70 boolean equalParamTypes(Class<?>[] params1, Class<?>[] params2) {
71 /* Avoid unnecessary cloning */
72 if (params1.length == params2.length) {
73 for (int i = 0; i < params1.length; i++) {
74 if (params1[i] != params2[i])
75 return false;
76 }
77 return true;
78 }
79 return false;
80 }
81
82 Annotation[][] parseParameterAnnotations(byte[] parameterAnnotations) {
83 return AnnotationParser.parseParameterAnnotations(
585 public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
586 Objects.requireNonNull(annotationClass);
587
588 return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass);
589 }
590
591 /**
592 * {@inheritDoc}
593 */
594 public Annotation[] getDeclaredAnnotations() {
595 return AnnotationParser.toArray(declaredAnnotations());
596 }
597
598 private transient volatile Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
599
600 private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
601 Map<Class<? extends Annotation>, Annotation> declAnnos;
602 if ((declAnnos = declaredAnnotations) == null) {
603 synchronized (this) {
604 if ((declAnnos = declaredAnnotations) == null) {
605 Executable root = getRoot();
606 if (root != null) {
607 declAnnos = root.declaredAnnotations();
608 } else {
609 declAnnos = AnnotationParser.parseAnnotations(
610 getAnnotationBytes(),
611 SharedSecrets.getJavaLangAccess().
612 getConstantPool(getDeclaringClass()),
613 getDeclaringClass()
614 );
615 }
616 declaredAnnotations = declAnnos;
617 }
618 }
619 }
620 return declAnnos;
621 }
622
623 /**
624 * Returns an {@code AnnotatedType} object that represents the use of a type to
625 * specify the return type of the method/constructor represented by this
|
39
40 /**
41 * A shared superclass for the common functionality of {@link Method}
42 * and {@link Constructor}.
43 *
44 * @since 1.8
45 */
46 public abstract class Executable extends AccessibleObject
47 implements Member, GenericDeclaration {
48 /*
49 * Only grant package-visibility to the constructor.
50 */
51 Executable() {}
52
53 /**
54 * Accessor method to allow code sharing
55 */
56 abstract byte[] getAnnotationBytes();
57
58 /**
59 * Does the Executable have generic information.
60 */
61 abstract boolean hasGenericInformation();
62
63 abstract ConstructorRepository getGenericInfo();
64
65 boolean equalParamTypes(Class<?>[] params1, Class<?>[] params2) {
66 /* Avoid unnecessary cloning */
67 if (params1.length == params2.length) {
68 for (int i = 0; i < params1.length; i++) {
69 if (params1[i] != params2[i])
70 return false;
71 }
72 return true;
73 }
74 return false;
75 }
76
77 Annotation[][] parseParameterAnnotations(byte[] parameterAnnotations) {
78 return AnnotationParser.parseParameterAnnotations(
580 public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
581 Objects.requireNonNull(annotationClass);
582
583 return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass);
584 }
585
586 /**
587 * {@inheritDoc}
588 */
589 public Annotation[] getDeclaredAnnotations() {
590 return AnnotationParser.toArray(declaredAnnotations());
591 }
592
593 private transient volatile Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
594
595 private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
596 Map<Class<? extends Annotation>, Annotation> declAnnos;
597 if ((declAnnos = declaredAnnotations) == null) {
598 synchronized (this) {
599 if ((declAnnos = declaredAnnotations) == null) {
600 Executable root = (Executable)getRoot();
601 if (root != null) {
602 declAnnos = root.declaredAnnotations();
603 } else {
604 declAnnos = AnnotationParser.parseAnnotations(
605 getAnnotationBytes(),
606 SharedSecrets.getJavaLangAccess().
607 getConstantPool(getDeclaringClass()),
608 getDeclaringClass()
609 );
610 }
611 declaredAnnotations = declAnnos;
612 }
613 }
614 }
615 return declAnnos;
616 }
617
618 /**
619 * Returns an {@code AnnotatedType} object that represents the use of a type to
620 * specify the return type of the method/constructor represented by this
|