8007113: Upgrade AnnotatedElement.isAnnotionPresent to be a default method
Reviewed-by: chegar, jfranck
--- a/jdk/src/share/classes/java/lang/Class.java Mon Feb 04 11:58:43 2013 -0800
+++ b/jdk/src/share/classes/java/lang/Class.java Mon Feb 04 17:56:29 2013 -0800
@@ -3085,16 +3085,6 @@
/**
* @throws NullPointerException {@inheritDoc}
- * @since 1.5
- */
- public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
- Objects.requireNonNull(annotationClass);
-
- return getAnnotation(annotationClass) != null;
- }
-
- /**
- * @throws NullPointerException {@inheritDoc}
* @since 1.8
*/
public <A extends Annotation> A[] getAnnotations(Class<A> annotationClass) {
--- a/jdk/src/share/classes/java/lang/Package.java Mon Feb 04 11:58:43 2013 -0800
+++ b/jdk/src/share/classes/java/lang/Package.java Mon Feb 04 17:56:29 2013 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -387,15 +387,6 @@
/**
* @throws NullPointerException {@inheritDoc}
- * @since 1.5
- */
- public boolean isAnnotationPresent(
- Class<? extends Annotation> annotationClass) {
- return getPackageInfo().isAnnotationPresent(annotationClass);
- }
-
- /**
- * @throws NullPointerException {@inheritDoc}
* @since 1.8
*/
public <A extends Annotation> A[] getAnnotations(Class<A> annotationClass) {
--- a/jdk/src/share/classes/java/lang/reflect/AccessibleObject.java Mon Feb 04 11:58:43 2013 -0800
+++ b/jdk/src/share/classes/java/lang/reflect/AccessibleObject.java Mon Feb 04 17:56:29 2013 -0800
@@ -182,14 +182,6 @@
/**
* @throws NullPointerException {@inheritDoc}
- * @since 1.5
- */
- public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
- return getAnnotation(annotationClass) != null;
- }
-
- /**
- * @throws NullPointerException {@inheritDoc}
* @since 1.8
*/
public <T extends Annotation> T[] getAnnotations(Class<T> annotationClass) {
--- a/jdk/src/share/classes/java/lang/reflect/AnnotatedElement.java Mon Feb 04 11:58:43 2013 -0800
+++ b/jdk/src/share/classes/java/lang/reflect/AnnotatedElement.java Mon Feb 04 17:56:29 2013 -0800
@@ -91,6 +91,9 @@
* <p>The truth value returned by this method is equivalent to:
* {@code getAnnotation(annotationClass) != null}
*
+ * <p>The body of the default method is specified to be the code
+ * above.
+ *
* @param annotationClass the Class object corresponding to the
* annotation type
* @return true if an annotation for the specified annotation
@@ -98,7 +101,9 @@
* @throws NullPointerException if the given annotation class is null
* @since 1.5
*/
- boolean isAnnotationPresent(Class<? extends Annotation> annotationClass);
+ default boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
+ return getAnnotation(annotationClass) != null;
+ }
/**
* Returns this element's annotation for the specified type if
--- a/jdk/src/share/classes/java/lang/reflect/Parameter.java Mon Feb 04 11:58:43 2013 -0800
+++ b/jdk/src/share/classes/java/lang/reflect/Parameter.java Mon Feb 04 17:56:29 2013 -0800
@@ -280,14 +280,6 @@
return getDeclaredAnnotations();
}
- /**
- * @throws NullPointerException {@inheritDoc}
- */
- public boolean isAnnotationPresent(
- Class<? extends Annotation> annotationClass) {
- return getAnnotation(annotationClass) != null;
- }
-
private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
private synchronized Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
--- a/jdk/src/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java Mon Feb 04 11:58:43 2013 -0800
+++ b/jdk/src/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java Mon Feb 04 17:56:29 2013 -0800
@@ -138,11 +138,6 @@
// AnnotatedElement
@Override
- public final boolean isAnnotationPresent(Class<? extends Annotation> annotation) {
- return annotations.get(annotation) != null;
- }
-
- @Override
public final Annotation[] getAnnotations() {
return getDeclaredAnnotations();
}
--- a/jdk/src/share/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java Mon Feb 04 11:58:43 2013 -0800
+++ b/jdk/src/share/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java Mon Feb 04 17:56:29 2013 -0800
@@ -188,11 +188,6 @@
}
// Implementations of AnnotatedElement methods.
- public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
- Objects.requireNonNull(annotationClass);
- return false;
- }
-
@SuppressWarnings("unchecked")
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
Objects.requireNonNull(annotationClass);