equal
deleted
inserted
replaced
84 // and invoke it to get the contents. |
84 // and invoke it to get the contents. |
85 |
85 |
86 Class<? extends Annotation> containerClass = containerInstance.annotationType(); |
86 Class<? extends Annotation> containerClass = containerInstance.annotationType(); |
87 AnnotationType annoType = AnnotationType.getInstance(containerClass); |
87 AnnotationType annoType = AnnotationType.getInstance(containerClass); |
88 if (annoType == null) |
88 if (annoType == null) |
89 throw new InvalidContainerAnnotationError(containerInstance + " is an invalid container for repeating annotations"); |
89 throw new AnnotationFormatError(containerInstance + " is an invalid container for repeating annotations"); |
90 |
90 |
91 Method m = annoType.members().get("value"); |
91 Method m = annoType.members().get("value"); |
92 if (m == null) |
92 if (m == null) |
93 throw new InvalidContainerAnnotationError(containerInstance + |
93 throw new AnnotationFormatError(containerInstance + |
94 " is an invalid container for repeating annotations"); |
94 " is an invalid container for repeating annotations"); |
95 m.setAccessible(true); |
95 m.setAccessible(true); |
96 |
96 |
97 @SuppressWarnings("unchecked") // not provably safe, but we catch the ClassCastException |
97 @SuppressWarnings("unchecked") // not provably safe, but we catch the ClassCastException |
98 A[] a = (A[])m.invoke(containerInstance); // this will erase to (Annotation[]) but we |
98 A[] a = (A[])m.invoke(containerInstance); // this will erase to (Annotation[]) but we |
101 return a; |
101 return a; |
102 } catch (IllegalAccessException | // couldnt loosen security |
102 } catch (IllegalAccessException | // couldnt loosen security |
103 IllegalArgumentException | // parameters doesn't match |
103 IllegalArgumentException | // parameters doesn't match |
104 InvocationTargetException | // the value method threw an exception |
104 InvocationTargetException | // the value method threw an exception |
105 ClassCastException e) { // well, a cast failed ... |
105 ClassCastException e) { // well, a cast failed ... |
106 throw new InvalidContainerAnnotationError( |
106 throw new AnnotationFormatError( |
107 containerInstance + " is an invalid container for repeating annotations", |
107 containerInstance + " is an invalid container for repeating annotations", |
108 e, |
108 e); |
109 containerInstance, |
|
110 null); |
|
111 } |
109 } |
112 } |
110 } |
113 |
111 |
114 /* Sanity check type of and return a list of all the annotation |
112 /* Sanity check type of and return a list of all the annotation |
115 * instances of type {@code annotationClass} from {@code |
113 * instances of type {@code annotationClass} from {@code |
127 for (int i = 0; i < a.length; i++) |
125 for (int i = 0; i < a.length; i++) |
128 l.add(annotationClass.cast(a[i])); |
126 l.add(annotationClass.cast(a[i])); |
129 return l; |
127 return l; |
130 } catch (ClassCastException | |
128 } catch (ClassCastException | |
131 NullPointerException e) { |
129 NullPointerException e) { |
132 throw new InvalidContainerAnnotationError( |
130 throw new AnnotationFormatError( |
133 String.format("%s is an invalid container for repeating annotations of type: %s", |
131 String.format("%s is an invalid container for repeating annotations of type: %s", |
134 containerInstance, annotationClass), |
132 containerInstance, annotationClass), |
135 e, |
133 e); |
136 containerInstance, |
|
137 annotationClass); |
|
138 } |
134 } |
139 } |
135 } |
140 } |
136 } |