From 12bf35d795cfe9b97e7157ed258e0d5a4f306108 Mon Sep 17 00:00:00 2001 From: darcy Date: Mon, 4 Feb 2013 17:56:29 -0800 Subject: [PATCH] 8007113: Upgrade AnnotatedElement.isAnnotionPresent to be a default method Reviewed-by: chegar, jfranck --- src/share/classes/java/lang/Class.java | 10 ---------- src/share/classes/java/lang/Package.java | 11 +---------- .../classes/java/lang/reflect/AccessibleObject.java | 8 -------- .../classes/java/lang/reflect/AnnotatedElement.java | 7 ++++++- src/share/classes/java/lang/reflect/Parameter.java | 8 -------- .../sun/reflect/annotation/AnnotatedTypeFactory.java | 5 ----- .../generics/reflectiveObjects/TypeVariableImpl.java | 5 ----- 7 files changed, 7 insertions(+), 47 deletions(-) diff --git a/src/share/classes/java/lang/Class.java b/src/share/classes/java/lang/Class.java index 31e2294eb..dab6c98e4 100644 --- a/src/share/classes/java/lang/Class.java +++ b/src/share/classes/java/lang/Class.java @@ -3083,16 +3083,6 @@ public final return (A) annotations.get(annotationClass); } - /** - * @throws NullPointerException {@inheritDoc} - * @since 1.5 - */ - public boolean isAnnotationPresent(Class annotationClass) { - Objects.requireNonNull(annotationClass); - - return getAnnotation(annotationClass) != null; - } - /** * @throws NullPointerException {@inheritDoc} * @since 1.8 diff --git a/src/share/classes/java/lang/Package.java b/src/share/classes/java/lang/Package.java index 744a292d6..234f80718 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 @@ -385,15 +385,6 @@ public class Package implements java.lang.reflect.AnnotatedElement { return getPackageInfo().getAnnotation(annotationClass); } - /** - * @throws NullPointerException {@inheritDoc} - * @since 1.5 - */ - public boolean isAnnotationPresent( - Class annotationClass) { - return getPackageInfo().isAnnotationPresent(annotationClass); - } - /** * @throws NullPointerException {@inheritDoc} * @since 1.8 diff --git a/src/share/classes/java/lang/reflect/AccessibleObject.java b/src/share/classes/java/lang/reflect/AccessibleObject.java index baaec298a..9986aef6c 100644 --- a/src/share/classes/java/lang/reflect/AccessibleObject.java +++ b/src/share/classes/java/lang/reflect/AccessibleObject.java @@ -180,14 +180,6 @@ public class AccessibleObject implements AnnotatedElement { throw new AssertionError("All subclasses should override this method"); } - /** - * @throws NullPointerException {@inheritDoc} - * @since 1.5 - */ - public boolean isAnnotationPresent(Class annotationClass) { - return getAnnotation(annotationClass) != null; - } - /** * @throws NullPointerException {@inheritDoc} * @since 1.8 diff --git a/src/share/classes/java/lang/reflect/AnnotatedElement.java b/src/share/classes/java/lang/reflect/AnnotatedElement.java index e7de9429b..85472ff5b 100644 --- a/src/share/classes/java/lang/reflect/AnnotatedElement.java +++ b/src/share/classes/java/lang/reflect/AnnotatedElement.java @@ -91,6 +91,9 @@ public interface AnnotatedElement { *

The truth value returned by this method is equivalent to: * {@code getAnnotation(annotationClass) != null} * + *

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 @@ public interface AnnotatedElement { * @throws NullPointerException if the given annotation class is null * @since 1.5 */ - boolean isAnnotationPresent(Class annotationClass); + default boolean isAnnotationPresent(Class 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 4fda579c5..04bc274ca 100644 --- a/src/share/classes/java/lang/reflect/Parameter.java +++ b/src/share/classes/java/lang/reflect/Parameter.java @@ -280,14 +280,6 @@ public final class Parameter implements AnnotatedElement { return getDeclaredAnnotations(); } - /** - * @throws NullPointerException {@inheritDoc} - */ - public boolean isAnnotationPresent( - Class annotationClass) { - return getAnnotation(annotationClass) != null; - } - private transient Map, Annotation> declaredAnnotations; private synchronized Map, Annotation> declaredAnnotations() { diff --git a/src/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java b/src/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java index afb4c4865..e0524e849 100644 --- a/src/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java +++ b/src/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java @@ -137,11 +137,6 @@ public class AnnotatedTypeFactory { } // AnnotatedElement - @Override - public final boolean isAnnotationPresent(Class 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 4bc335627..528658d0d 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 @@ public class TypeVariableImpl } // Implementations of AnnotatedElement methods. - public boolean isAnnotationPresent(Class annotationClass) { - Objects.requireNonNull(annotationClass); - return false; - } - @SuppressWarnings("unchecked") public T getAnnotation(Class annotationClass) { Objects.requireNonNull(annotationClass); -- GitLab