diff -r 17224d0282f1 -r 985410ec95e3 jdk/src/share/classes/java/lang/Class.java
--- a/jdk/src/share/classes/java/lang/Class.java Wed Nov 28 05:18:57 2012 -0800
+++ b/jdk/src/share/classes/java/lang/Class.java Wed Nov 28 09:21:37 2012 -0800
@@ -48,6 +48,7 @@
import java.util.Set;
import java.util.Map;
import java.util.HashMap;
+import java.util.Objects;
import sun.misc.Unsafe;
import sun.reflect.ConstantPool;
import sun.reflect.Reflection;
@@ -3044,34 +3045,62 @@
* @throws NullPointerException {@inheritDoc}
* @since 1.5
*/
- @SuppressWarnings("unchecked")
public A getAnnotation(Class annotationClass) {
- if (annotationClass == null)
- throw new NullPointerException();
+ Objects.requireNonNull(annotationClass);
initAnnotationsIfNecessary();
- return (A) annotations.get(annotationClass);
+ return AnnotationSupport.getOneAnnotation(annotations, annotationClass);
}
/**
* @throws NullPointerException {@inheritDoc}
* @since 1.5
*/
- public boolean isAnnotationPresent(
- Class extends Annotation> annotationClass) {
- if (annotationClass == null)
- throw new NullPointerException();
+ public boolean isAnnotationPresent(Class extends Annotation> annotationClass) {
+ Objects.requireNonNull(annotationClass);
return getAnnotation(annotationClass) != null;
}
+ /**
+ * @throws NullPointerException {@inheritDoc}
+ * @since 1.8
+ */
+ public A[] getAnnotations(Class annotationClass) {
+ Objects.requireNonNull(annotationClass);
+
+ initAnnotationsIfNecessary();
+ return AnnotationSupport.getMultipleAnnotations(annotations, annotationClass);
+ }
/**
* @since 1.5
*/
public Annotation[] getAnnotations() {
initAnnotationsIfNecessary();
- return AnnotationParser.toArray(annotations);
+ return AnnotationSupport.unpackToArray(annotations);
+ }
+
+ /**
+ * @throws NullPointerException {@inheritDoc}
+ * @since 1.8
+ */
+ public A getDeclaredAnnotation(Class annotationClass) {
+ Objects.requireNonNull(annotationClass);
+
+ initAnnotationsIfNecessary();
+ return AnnotationSupport.getOneAnnotation(declaredAnnotations, annotationClass);
+ }
+
+ /**
+ * @throws NullPointerException {@inheritDoc}
+ * @since 1.8
+ */
+ public A[] getDeclaredAnnotations(Class annotationClass) {
+ Objects.requireNonNull(annotationClass);
+
+ initAnnotationsIfNecessary();
+ return AnnotationSupport.getMultipleAnnotations(declaredAnnotations, annotationClass);
}
/**
@@ -3079,7 +3108,17 @@
*/
public Annotation[] getDeclaredAnnotations() {
initAnnotationsIfNecessary();
- return AnnotationParser.toArray(declaredAnnotations);
+ return AnnotationSupport.unpackToArray(declaredAnnotations);
+ }
+
+ /** Returns one "directly" present annotation or null */
+ A getDirectDeclaredAnnotation(Class annotationClass) {
+ Objects.requireNonNull(annotationClass);
+
+ initAnnotationsIfNecessary();
+ @SuppressWarnings("unchecked") // TODO check safe
+ A ret = (A)declaredAnnotations.get(annotationClass);
+ return ret;
}
// Annotations cache