PUBLIC COMMENTS
Seems harmless but also pointless. Typical processor code would be catching either one or the other exception type at a time:
SomeAnno ann = element.getAnnotation(SomeAnno.class);
try {
ann.someMethodReturningClass();
} catch (MirroredTypeException x) {
TypeMirror theReturnValue = x.getTypeMirror();
// ...
}
try {
ann.someMethodReturningClassArray();
} catch (MirroredTypesException x) {
List<? extends TypeMirror> theReturnValue = x.getTypeMirrors();
// ...
}
For it to be useful for a catch block of MirroredTypesException to also get MirroredTypeException with a singleton list, the calling code would have to have no idea whether the method it was calling returned Class or Class[]. But that would only happen if the calling code were operating reflectively on an annotation type not known to it statically - in which case Element.getAnnotation(Class) is useless, since you would more easily work with Element.getAnnotationMirrors().
As the Javadoc for getAnnotation says, "this method is intended for callers that are written to operate on a known, fixed set of annotation types", exactly the callers that will be catching either MirroredTypeException or MirroredTypesException when calling known, fixed methods.
|