8007113: Upgrade AnnotatedElement.isAnnotionPresent to be a default method
Reviewed-by: chegar, jfranck
diff --git a/src/share/classes/java/lang/Class.java b/src/share/classes/java/lang/Class.java
index 31e2294..dab6c98 100644
--- a/src/share/classes/java/lang/Class.java
+++ b/src/share/classes/java/lang/Class.java
@@ -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) {
diff --git a/src/share/classes/java/lang/Package.java b/src/share/classes/java/lang/Package.java
index 744a292..234f807 100644
--- a/src/share/classes/java/lang/Package.java
+++ b/src/share/classes/java/lang/Package.java
@@ -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) {
diff --git a/src/share/classes/java/lang/reflect/AccessibleObject.java b/src/share/classes/java/lang/reflect/AccessibleObject.java
index baaec29..9986aef 100644
--- a/src/share/classes/java/lang/reflect/AccessibleObject.java
+++ b/src/share/classes/java/lang/reflect/AccessibleObject.java
@@ -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) {
diff --git a/src/share/classes/java/lang/reflect/AnnotatedElement.java b/src/share/classes/java/lang/reflect/AnnotatedElement.java
index e7de942..85472ff 100644
--- a/src/share/classes/java/lang/reflect/AnnotatedElement.java
+++ b/src/share/classes/java/lang/reflect/AnnotatedElement.java
@@ -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
diff --git a/src/share/classes/java/lang/reflect/Parameter.java b/src/share/classes/java/lang/reflect/Parameter.java
index 4fda579..04bc274 100644
--- a/src/share/classes/java/lang/reflect/Parameter.java
+++ b/src/share/classes/java/lang/reflect/Parameter.java
@@ -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() {
diff --git a/src/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java b/src/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java
index afb4c48..e0524e8 100644
--- a/src/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java
+++ b/src/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java
@@ -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();
}
diff --git a/src/share/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java b/src/share/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java
index 4bc3356..528658d 100644
--- a/src/share/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java
+++ b/src/share/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java
@@ -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);