提交 12bf35d7 编写于 作者: D darcy

8007113: Upgrade AnnotatedElement.isAnnotionPresent to be a default method

Reviewed-by: chegar, jfranck
上级 2f47435a
...@@ -3083,16 +3083,6 @@ public final ...@@ -3083,16 +3083,6 @@ public final
return (A) annotations.get(annotationClass); return (A) annotations.get(annotationClass);
} }
/**
* @throws NullPointerException {@inheritDoc}
* @since 1.5
*/
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
Objects.requireNonNull(annotationClass);
return getAnnotation(annotationClass) != null;
}
/** /**
* @throws NullPointerException {@inheritDoc} * @throws NullPointerException {@inheritDoc}
* @since 1.8 * @since 1.8
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 { ...@@ -385,15 +385,6 @@ public class Package implements java.lang.reflect.AnnotatedElement {
return getPackageInfo().getAnnotation(annotationClass); return getPackageInfo().getAnnotation(annotationClass);
} }
/**
* @throws NullPointerException {@inheritDoc}
* @since 1.5
*/
public boolean isAnnotationPresent(
Class<? extends Annotation> annotationClass) {
return getPackageInfo().isAnnotationPresent(annotationClass);
}
/** /**
* @throws NullPointerException {@inheritDoc} * @throws NullPointerException {@inheritDoc}
* @since 1.8 * @since 1.8
......
...@@ -180,14 +180,6 @@ public class AccessibleObject implements AnnotatedElement { ...@@ -180,14 +180,6 @@ public class AccessibleObject implements AnnotatedElement {
throw new AssertionError("All subclasses should override this method"); throw new AssertionError("All subclasses should override this method");
} }
/**
* @throws NullPointerException {@inheritDoc}
* @since 1.5
*/
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
return getAnnotation(annotationClass) != null;
}
/** /**
* @throws NullPointerException {@inheritDoc} * @throws NullPointerException {@inheritDoc}
* @since 1.8 * @since 1.8
......
...@@ -91,6 +91,9 @@ public interface AnnotatedElement { ...@@ -91,6 +91,9 @@ public interface AnnotatedElement {
* <p>The truth value returned by this method is equivalent to: * <p>The truth value returned by this method is equivalent to:
* {@code getAnnotation(annotationClass) != null} * {@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 * @param annotationClass the Class object corresponding to the
* annotation type * annotation type
* @return true if an annotation for the specified annotation * @return true if an annotation for the specified annotation
...@@ -98,7 +101,9 @@ public interface AnnotatedElement { ...@@ -98,7 +101,9 @@ public interface AnnotatedElement {
* @throws NullPointerException if the given annotation class is null * @throws NullPointerException if the given annotation class is null
* @since 1.5 * @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 * Returns this element's annotation for the specified type if
......
...@@ -280,14 +280,6 @@ public final class Parameter implements AnnotatedElement { ...@@ -280,14 +280,6 @@ public final class Parameter implements AnnotatedElement {
return getDeclaredAnnotations(); 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 transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
private synchronized Map<Class<? extends Annotation>, Annotation> declaredAnnotations() { private synchronized Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
......
...@@ -137,11 +137,6 @@ public class AnnotatedTypeFactory { ...@@ -137,11 +137,6 @@ public class AnnotatedTypeFactory {
} }
// AnnotatedElement // AnnotatedElement
@Override
public final boolean isAnnotationPresent(Class<? extends Annotation> annotation) {
return annotations.get(annotation) != null;
}
@Override @Override
public final Annotation[] getAnnotations() { public final Annotation[] getAnnotations() {
return getDeclaredAnnotations(); return getDeclaredAnnotations();
......
...@@ -188,11 +188,6 @@ public class TypeVariableImpl<D extends GenericDeclaration> ...@@ -188,11 +188,6 @@ public class TypeVariableImpl<D extends GenericDeclaration>
} }
// Implementations of AnnotatedElement methods. // Implementations of AnnotatedElement methods.
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
Objects.requireNonNull(annotationClass);
return false;
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
Objects.requireNonNull(annotationClass); Objects.requireNonNull(annotationClass);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册