jdk/src/share/classes/java/lang/reflect/AnnotatedElement.java
author darcy
Tue, 26 Feb 2013 17:38:29 -0800
changeset 16037 1cf21ce98a25
parent 15659 e575dab44ff5
child 18546 862067c6481c
permissions -rw-r--r--
8008279: Remove InvalidContainerAnnotationError.java Reviewed-by: jfranck
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
15511
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
     2
 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3630
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3630
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3630
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3630
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3630
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang.reflect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.lang.annotation.Annotation;
16037
1cf21ce98a25 8008279: Remove InvalidContainerAnnotationError.java
darcy
parents: 15659
diff changeset
    29
import java.lang.annotation.AnnotationFormatError;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * Represents an annotated element of the program currently running in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * VM.  This interface allows annotations to be read reflectively.  All
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * annotations returned by methods in this interface are immutable and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * serializable.  It is permissible for the caller to modify the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * arrays returned by accessors for array-valued enum members; it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * have no affect on the arrays returned to other callers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    39
 * <p>The {@link #getAnnotationsByType(Class)} and {@link
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    40
 * #getDeclaredAnnotationsByType(Class)} methods support multiple
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    41
 * annotations of the same type on an element. If the argument to either method
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    42
 * is a repeatable annotation type (JLS 9.6), then the method will "look
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    43
 * through" a container annotation (JLS 9.7) which was generated at
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    44
 * compile-time to wrap multiple annotations of the argument type.
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    45
 *
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    46
 * <p>The terms <em>directly present</em> and <em>present</em> are used
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    47
 * throughout this interface to describe precisely which annotations are
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    48
 * returned by methods:
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    49
 *
15511
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
    50
 * <ul>
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    51
 * <li>An annotation A is <em>directly present</em> on an element E if E is
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    52
 * associated with a RuntimeVisibleAnnotations or
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    53
 * RuntimeVisibleParameterAnnotations attribute, and:
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    54
 *
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    55
 * <ul>
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    56
 * <li>for an invocation of {@code get[Declared]Annotation(Class<T>)} or
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    57
 * {@code get[Declared]Annotations()}, the attribute contains A.
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    58
 *
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    59
 * <li>for an invocation of {@code get[Declared]AnnotationsByType(Class<T>)}, the
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    60
 * attribute either contains A or, if the type of A is repeatable, contains
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    61
 * exactly one annotation whose value element contains A and whose type is the
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    62
 * containing annotation type of A's type (JLS 9.6).
15511
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
    63
 * </ul>
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
    64
 *
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    65
 * <p>
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    66
 * <li>An annotation A is <em>present</em> on an element E if either:
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    67
 *
15511
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
    68
 * <ul>
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
    69
 * <li>A is <em>directly present</em> on E; or
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    70
 *
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    71
 * <li>A is not <em>directly present</em> on E, and E is a class, and A's type
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    72
 * is inheritable (JLS 9.6.3.3), and A is <em>present</em> on the superclass of
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    73
 * E.
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    74
 * </ul>
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    75
 *
15511
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
    76
 * </ul>
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
    77
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <p>If an annotation returned by a method in this interface contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * (directly or indirectly) a {@link Class}-valued member referring to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * a class that is not accessible in this VM, attempting to read the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * by calling the relevant Class-returning method on the returned annotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * will result in a {@link TypeNotPresentException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * <p>Similarly, attempting to read an enum-valued member will result in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * a {@link EnumConstantNotPresentException} if the enum constant in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * annotation is no longer present in the enum type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
    88
 * <p>Attempting to read annotations of a repeatable annotation type T
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
    89
 * that are contained in an annotation whose type is not, in fact, the
16037
1cf21ce98a25 8008279: Remove InvalidContainerAnnotationError.java
darcy
parents: 15659
diff changeset
    90
 * containing annotation type of T, will result in an {@link
1cf21ce98a25 8008279: Remove InvalidContainerAnnotationError.java
darcy
parents: 15659
diff changeset
    91
 * AnnotationFormatError}.
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
    92
 *
15511
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
    93
 * <p>Finally, attempting to read a member whose definition has evolved
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * incompatibly will result in a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * java.lang.annotation.AnnotationTypeMismatchException} or an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * {@link java.lang.annotation.IncompleteAnnotationException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *
3630
28237c1f0c41 6378701: (enum) Unclear purpose of EnumConstantNotPresentException
darcy
parents: 2
diff changeset
    98
 * @see java.lang.EnumConstantNotPresentException
28237c1f0c41 6378701: (enum) Unclear purpose of EnumConstantNotPresentException
darcy
parents: 2
diff changeset
    99
 * @see java.lang.TypeNotPresentException
16037
1cf21ce98a25 8008279: Remove InvalidContainerAnnotationError.java
darcy
parents: 15659
diff changeset
   100
 * @see AnnotationFormatError
3630
28237c1f0c41 6378701: (enum) Unclear purpose of EnumConstantNotPresentException
darcy
parents: 2
diff changeset
   101
 * @see java.lang.annotation.AnnotationTypeMismatchException
28237c1f0c41 6378701: (enum) Unclear purpose of EnumConstantNotPresentException
darcy
parents: 2
diff changeset
   102
 * @see java.lang.annotation.IncompleteAnnotationException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * @author Josh Bloch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
public interface AnnotatedElement {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Returns true if an annotation for the specified type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * is present on this element, else false.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * is designed primarily for convenient access to marker annotations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
15511
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   112
     * <p>The truth value returned by this method is equivalent to:
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   113
     * {@code getAnnotation(annotationClass) != null}
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   114
     *
15534
19228f4aedb4 8007113: Upgrade AnnotatedElement.isAnnotionPresent to be a default method
darcy
parents: 15511
diff changeset
   115
     * <p>The body of the default method is specified to be the code
19228f4aedb4 8007113: Upgrade AnnotatedElement.isAnnotionPresent to be a default method
darcy
parents: 15511
diff changeset
   116
     * above.
19228f4aedb4 8007113: Upgrade AnnotatedElement.isAnnotionPresent to be a default method
darcy
parents: 15511
diff changeset
   117
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @param annotationClass the Class object corresponding to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *        annotation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @return true if an annotation for the specified annotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *     type is present on this element, else false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @throws NullPointerException if the given annotation class is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
15534
19228f4aedb4 8007113: Upgrade AnnotatedElement.isAnnotionPresent to be a default method
darcy
parents: 15511
diff changeset
   125
    default boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
19228f4aedb4 8007113: Upgrade AnnotatedElement.isAnnotionPresent to be a default method
darcy
parents: 15511
diff changeset
   126
        return getAnnotation(annotationClass) != null;
19228f4aedb4 8007113: Upgrade AnnotatedElement.isAnnotionPresent to be a default method
darcy
parents: 15511
diff changeset
   127
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Returns this element's annotation for the specified type if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * such an annotation is present, else null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @param annotationClass the Class object corresponding to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *        annotation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @return this element's annotation for the specified annotation type if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *     present on this element, else null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @throws NullPointerException if the given annotation class is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    <T extends Annotation> T getAnnotation(Class<T> annotationClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   143
     * Returns annotations that are <em>present</em> on this element.
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   144
     *
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   145
     * If there are no annotations <em>present</em> on this element, the return
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   146
     * value is an array of length 0.
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   147
     *
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   148
     * The difference between this method and {@link #getAnnotation(Class)}
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   149
     * is that this method detects if its argument is a <em>repeatable
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   150
     * annotation type</em> (JLS 9.6), and if so, attempts to find one or
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   151
     * more annotations of that type by "looking through" a container
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   152
     * annotation.
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   153
     *
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   154
     * The caller of this method is free to modify the returned array; it will
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   155
     * have no effect on the arrays returned to other callers.
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   156
     *
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   157
     * @param annotationClass the Class object corresponding to the
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   158
     *        annotation type
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   159
     * @return all this element's annotations for the specified annotation type if
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   160
     *     present on this element, else an array of length zero
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   161
     * @throws NullPointerException if the given annotation class is null
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   162
     * @since 1.8
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   163
     */
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   164
    <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass);
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   165
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   166
    /**
15511
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   167
     * Returns annotations that are <em>present</em> on this element.
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   168
     *
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   169
     * If there are no annotations <em>present</em> on this element, the return
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   170
     * value is an array of length 0.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
15511
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   172
     * The caller of this method is free to modify the returned array; it will
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   173
     * have no effect on the arrays returned to other callers.
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   174
     *
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   175
     * @return annotations present on this element
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    Annotation[] getAnnotations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   181
     * Returns this element's annotation for the specified type if
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   182
     * such an annotation is present, else null.
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   183
     *
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   184
     * This method ignores inherited annotations. (Returns null if no
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   185
     * annotations are directly present on this element.)
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   186
     *
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   187
     * @param annotationClass the Class object corresponding to the
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   188
     *        annotation type
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   189
     * @return this element's annotation for the specified annotation type if
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   190
     *     present on this element, else null
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   191
     * @throws NullPointerException if the given annotation class is null
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   192
     * @since 1.8
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   193
     */
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   194
    <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass);
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   195
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   196
    /**
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   197
     * Returns annotations that are <em>directly present</em> on this element.
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   198
     * This method ignores inherited annotations.
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   199
     *
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   200
     * If there are no annotations <em>directly present</em> on this element,
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   201
     * the return value is an array of length 0.
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   202
     *
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   203
     * The difference between this method and {@link
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   204
     * #getDeclaredAnnotation(Class)} is that this method detects if its
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   205
     * argument is a <em>repeatable annotation type</em> (JLS 9.6), and if so,
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   206
     * attempts to find one or more annotations of that type by "looking
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   207
     * through" a container annotation.
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   208
     *
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   209
     * The caller of this method is free to modify the returned array; it will
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   210
     * have no effect on the arrays returned to other callers.
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   211
     *
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   212
     * @param annotationClass the Class object corresponding to the
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   213
     *        annotation type
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   214
     * @return all this element's annotations for the specified annotation type if
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   215
     *     present on this element, else an array of length zero
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   216
     * @throws NullPointerException if the given annotation class is null
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   217
     * @since 1.8
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   218
     */
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   219
    <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass);
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   220
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   221
    /**
15511
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   222
     * Returns annotations that are <em>directly present</em> on this element.
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   223
     * This method ignores inherited annotations.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
15511
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   225
     * If there are no annotations <em>directly present</em> on this element,
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   226
     * the return value is an array of length 0.
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   227
     *
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   228
     * The caller of this method is free to modify the returned array; it will
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   229
     * have no effect on the arrays returned to other callers.
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   230
     *
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   231
     * @return annotations directly present on this element
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    Annotation[] getDeclaredAnnotations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
}