changeset 7431:e04467fa13af

8007113: Upgrade AnnotatedElement.isAnnotionPresent to be a default method Reviewed-by: chegar, jfranck
author darcy
date Mon, 04 Feb 2013 17:56:29 -0800
parents e202f43a8b8a
children fd37f0846653
files src/share/classes/java/lang/Class.java src/share/classes/java/lang/Package.java src/share/classes/java/lang/reflect/AccessibleObject.java src/share/classes/java/lang/reflect/AnnotatedElement.java src/share/classes/java/lang/reflect/Parameter.java src/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java src/share/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java
diffstat 7 files changed, 7 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/lang/Class.java	Mon Feb 04 11:58:43 2013 -0800
+++ b/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/src/share/classes/java/lang/Package.java	Mon Feb 04 11:58:43 2013 -0800
+++ b/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/src/share/classes/java/lang/reflect/AccessibleObject.java	Mon Feb 04 11:58:43 2013 -0800
+++ b/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/src/share/classes/java/lang/reflect/AnnotatedElement.java	Mon Feb 04 11:58:43 2013 -0800
+++ b/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/src/share/classes/java/lang/reflect/Parameter.java	Mon Feb 04 11:58:43 2013 -0800
+++ b/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/src/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java	Mon Feb 04 11:58:43 2013 -0800
+++ b/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/src/share/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java	Mon Feb 04 11:58:43 2013 -0800
+++ b/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);