jdk/src/java.base/share/classes/java/lang/reflect/AnnotatedElement.java
author jjg
Wed, 26 Apr 2017 16:05:55 -0700
changeset 44846 b3f9f5bf40b2
parent 25859 3317bb8137f4
child 45124 144479e89cdb
permissions -rw-r--r--
8179367: update use of align, valign attributes in java.base to use style attribute Reviewed-by: martin, mchung
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;
21419
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
    30
import java.lang.annotation.Repeatable;
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
    31
import java.util.Arrays;
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
    32
import java.util.LinkedHashMap;
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
    33
import java.util.Map;
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
    34
import java.util.Objects;
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
    35
import java.util.function.Function;
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
    36
import java.util.stream.Collectors;
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
    37
import sun.reflect.annotation.AnnotationSupport;
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
    38
import sun.reflect.annotation.AnnotationType;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Represents an annotated element of the program currently running in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * VM.  This interface allows annotations to be read reflectively.  All
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * annotations returned by methods in this interface are immutable and
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    44
 * serializable. The arrays returned by methods of this interface may be modified
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    45
 * by callers without affecting the arrays returned to other callers.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    47
 * <p>The {@link #getAnnotationsByType(Class)} and {@link
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    48
 * #getDeclaredAnnotationsByType(Class)} methods support multiple
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    49
 * annotations of the same type on an element. If the argument to
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    50
 * either method is a repeatable annotation type (JLS 9.6), then the
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    51
 * method will "look through" a container annotation (JLS 9.7), if
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    52
 * present, and return any annotations inside the container. Container
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    53
 * annotations may be generated at compile-time to wrap multiple
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    54
 * annotations of the argument type.
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    55
 *
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    56
 * <p>The terms <em>directly present</em>, <em>indirectly present</em>,
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    57
 * <em>present</em>, and <em>associated</em> are used throughout this
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    58
 * interface to describe precisely which annotations are returned by
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    59
 * methods:
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    60
 *
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    61
 * <ul>
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    62
 *
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    63
 * <li> An annotation <i>A</i> is <em>directly present</em> on an
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    64
 * element <i>E</i> if <i>E</i> has a {@code
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    65
 * RuntimeVisibleAnnotations} or {@code
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    66
 * RuntimeVisibleParameterAnnotations} or {@code
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    67
 * RuntimeVisibleTypeAnnotations} attribute, and the attribute
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    68
 * contains <i>A</i>.
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    69
 *
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    70
 * <li>An annotation <i>A</i> is <em>indirectly present</em> on an
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    71
 * element <i>E</i> if <i>E</i> has a {@code RuntimeVisibleAnnotations} or
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    72
 * {@code RuntimeVisibleParameterAnnotations} or {@code RuntimeVisibleTypeAnnotations}
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    73
 * attribute, and <i>A</i> 's type is repeatable, and the attribute contains
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    74
 * exactly one annotation whose value element contains <i>A</i> and whose
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    75
 * type is the containing annotation type of <i>A</i> 's type.
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    76
 *
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    77
 * <li>An annotation <i>A</i> is present on an element <i>E</i> if either:
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    78
 *
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    79
 * <ul>
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    80
 *
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    81
 * <li><i>A</i> is directly present on <i>E</i>; or
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    82
 *
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    83
 * <li>No annotation of <i>A</i> 's type is directly present on
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    84
 * <i>E</i>, and <i>E</i> is a class, and <i>A</i> 's type is
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    85
 * inheritable, and <i>A</i> is present on the superclass of <i>E</i>.
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    86
 *
15511
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
    87
 * </ul>
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
    88
 *
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    89
 * <li>An annotation <i>A</i> is <em>associated</em> with an element <i>E</i>
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    90
 * if either:
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    91
 *
15511
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
    92
 * <ul>
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    93
 *
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    94
 * <li><i>A</i> is directly or indirectly present on <i>E</i>; or
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
    95
 *
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    96
 * <li>No annotation of <i>A</i> 's type is directly or indirectly
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    97
 * present on <i>E</i>, and <i>E</i> is a class, and <i>A</i>'s type
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    98
 * is inheritable, and <i>A</i> is associated with the superclass of
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
    99
 * <i>E</i>.
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   100
 *
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   101
 * </ul>
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   102
 *
15511
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   103
 * </ul>
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   104
 *
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   105
 * <p>The table below summarizes which kind of annotation presence
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   106
 * different methods in this interface examine.
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   107
 *
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   108
 * <table border>
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   109
 * <caption>Overview of kind of presence detected by different AnnotatedElement methods</caption>
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   110
 * <tr><th colspan=2></th><th colspan=4>Kind of Presence</th>
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   111
 * <tr><th colspan=2>Method</th><th>Directly Present</th><th>Indirectly Present</th><th>Present</th><th>Associated</th>
44846
b3f9f5bf40b2 8179367: update use of align, valign attributes in java.base to use style attribute
jjg
parents: 25859
diff changeset
   112
 * <tr><td style="text-align:right">{@code T}</td><td>{@link #getAnnotation(Class) getAnnotation(Class&lt;T&gt;)}
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   113
 * <td></td><td></td><td>X</td><td></td>
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   114
 * </tr>
44846
b3f9f5bf40b2 8179367: update use of align, valign attributes in java.base to use style attribute
jjg
parents: 25859
diff changeset
   115
 * <tr><td style="text-align:right">{@code Annotation[]}</td><td>{@link #getAnnotations getAnnotations()}
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   116
 * <td></td><td></td><td>X</td><td></td>
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   117
 * </tr>
44846
b3f9f5bf40b2 8179367: update use of align, valign attributes in java.base to use style attribute
jjg
parents: 25859
diff changeset
   118
 * <tr><td style="text-align:right">{@code T[]}</td><td>{@link #getAnnotationsByType(Class) getAnnotationsByType(Class&lt;T&gt;)}
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   119
 * <td></td><td></td><td></td><td>X</td>
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   120
 * </tr>
44846
b3f9f5bf40b2 8179367: update use of align, valign attributes in java.base to use style attribute
jjg
parents: 25859
diff changeset
   121
 * <tr><td style="text-align:right">{@code T}</td><td>{@link #getDeclaredAnnotation(Class) getDeclaredAnnotation(Class&lt;T&gt;)}
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   122
 * <td>X</td><td></td><td></td><td></td>
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   123
 * </tr>
44846
b3f9f5bf40b2 8179367: update use of align, valign attributes in java.base to use style attribute
jjg
parents: 25859
diff changeset
   124
 * <tr><td style="text-align:right">{@code Annotation[]}</td><td>{@link #getDeclaredAnnotations getDeclaredAnnotations()}
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   125
 * <td>X</td><td></td><td></td><td></td>
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   126
 * </tr>
44846
b3f9f5bf40b2 8179367: update use of align, valign attributes in java.base to use style attribute
jjg
parents: 25859
diff changeset
   127
 * <tr><td style="text-align:right">{@code T[]}</td><td>{@link #getDeclaredAnnotationsByType(Class) getDeclaredAnnotationsByType(Class&lt;T&gt;)}
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   128
 * <td>X</td><td>X</td><td></td><td></td>
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   129
 * </tr>
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   130
 * </table>
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   131
 *
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   132
 * <p>For an invocation of {@code get[Declared]AnnotationsByType( Class <
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   133
 * T >)}, the order of annotations which are directly or indirectly
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   134
 * present on an element <i>E</i> is computed as if indirectly present
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   135
 * annotations on <i>E</i> are directly present on <i>E</i> in place
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   136
 * of their container annotation, in the order in which they appear in
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   137
 * the value element of the container annotation.
22080
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   138
 *
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   139
 * <p>There are several compatibility concerns to keep in mind if an
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   140
 * annotation type <i>T</i> is originally <em>not</em> repeatable and
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   141
 * later modified to be repeatable.
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   142
 *
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   143
 * The containing annotation type for <i>T</i> is <i>TC</i>.
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   144
 *
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   145
 * <ul>
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   146
 *
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   147
 * <li>Modifying <i>T</i> to be repeatable is source and binary
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   148
 * compatible with existing uses of <i>T</i> and with existing uses
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   149
 * of <i>TC</i>.
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   150
 *
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   151
 * That is, for source compatibility, source code with annotations of
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   152
 * type <i>T</i> or of type <i>TC</i> will still compile. For binary
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   153
 * compatibility, class files with annotations of type <i>T</i> or of
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   154
 * type <i>TC</i> (or with other kinds of uses of type <i>T</i> or of
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   155
 * type <i>TC</i>) will link against the modified version of <i>T</i>
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   156
 * if they linked against the earlier version.
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   157
 *
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   158
 * (An annotation type <i>TC</i> may informally serve as an acting
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   159
 * containing annotation type before <i>T</i> is modified to be
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   160
 * formally repeatable. Alternatively, when <i>T</i> is made
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   161
 * repeatable, <i>TC</i> can be introduced as a new type.)
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   162
 *
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   163
 * <li>If an annotation type <i>TC</i> is present on an element, and
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   164
 * <i>T</i> is modified to be repeatable with <i>TC</i> as its
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   165
 * containing annotation type then:
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   166
 *
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   167
 * <ul>
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   168
 *
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   169
 * <li>The change to <i>T</i> is behaviorally compatible with respect
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   170
 * to the {@code get[Declared]Annotation(Class<T>)} (called with an
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   171
 * argument of <i>T</i> or <i>TC</i>) and {@code
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   172
 * get[Declared]Annotations()} methods because the results of the
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   173
 * methods will not change due to <i>TC</i> becoming the containing
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   174
 * annotation type for <i>T</i>.
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   175
 *
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   176
 * <li>The change to <i>T</i> changes the results of the {@code
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   177
 * get[Declared]AnnotationsByType(Class<T>)} methods called with an
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   178
 * argument of <i>T</i>, because those methods will now recognize an
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   179
 * annotation of type <i>TC</i> as a container annotation for <i>T</i>
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   180
 * and will "look through" it to expose annotations of type <i>T</i>.
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   181
 *
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   182
 * </ul>
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   183
 *
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   184
 * <li>If an annotation of type <i>T</i> is present on an
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   185
 * element and <i>T</i> is made repeatable and more annotations of
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   186
 * type <i>T</i> are added to the element:
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   187
 *
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   188
 * <ul>
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   189
 *
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   190
 * <li> The addition of the annotations of type <i>T</i> is both
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   191
 * source compatible and binary compatible.
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   192
 *
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   193
 * <li>The addition of the annotations of type <i>T</i> changes the results
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   194
 * of the {@code get[Declared]Annotation(Class<T>)} methods and {@code
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   195
 * get[Declared]Annotations()} methods, because those methods will now
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   196
 * only see a container annotation on the element and not see an
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   197
 * annotation of type <i>T</i>.
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   198
 *
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   199
 * <li>The addition of the annotations of type <i>T</i> changes the
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   200
 * results of the {@code get[Declared]AnnotationsByType(Class<T>)}
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   201
 * methods, because their results will expose the additional
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   202
 * annotations of type <i>T</i> whereas previously they exposed only a
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   203
 * single annotation of type <i>T</i>.
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   204
 *
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   205
 * </ul>
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   206
 *
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   207
 * </ul>
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 21419
diff changeset
   208
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * <p>If an annotation returned by a method in this interface contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 * (directly or indirectly) a {@link Class}-valued member referring to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 * a class that is not accessible in this VM, attempting to read the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 * by calling the relevant Class-returning method on the returned annotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 * will result in a {@link TypeNotPresentException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 * <p>Similarly, attempting to read an enum-valued member will result in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 * a {@link EnumConstantNotPresentException} if the enum constant in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 * annotation is no longer present in the enum type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 *
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   219
 * <p>If an annotation type <i>T</i> is (meta-)annotated with an
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   220
 * {@code @Repeatable} annotation whose value element indicates a type
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   221
 * <i>TC</i>, but <i>TC</i> does not declare a {@code value()} method
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   222
 * with a return type of <i>T</i>{@code []}, then an exception of type
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   223
 * {@link java.lang.annotation.AnnotationFormatError} is thrown.
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   224
 *
15511
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   225
 * <p>Finally, attempting to read a member whose definition has evolved
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 * incompatibly will result in a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
 * java.lang.annotation.AnnotationTypeMismatchException} or an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 * {@link java.lang.annotation.IncompleteAnnotationException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 *
3630
28237c1f0c41 6378701: (enum) Unclear purpose of EnumConstantNotPresentException
darcy
parents: 2
diff changeset
   230
 * @see java.lang.EnumConstantNotPresentException
28237c1f0c41 6378701: (enum) Unclear purpose of EnumConstantNotPresentException
darcy
parents: 2
diff changeset
   231
 * @see java.lang.TypeNotPresentException
16037
1cf21ce98a25 8008279: Remove InvalidContainerAnnotationError.java
darcy
parents: 15659
diff changeset
   232
 * @see AnnotationFormatError
3630
28237c1f0c41 6378701: (enum) Unclear purpose of EnumConstantNotPresentException
darcy
parents: 2
diff changeset
   233
 * @see java.lang.annotation.AnnotationTypeMismatchException
28237c1f0c41 6378701: (enum) Unclear purpose of EnumConstantNotPresentException
darcy
parents: 2
diff changeset
   234
 * @see java.lang.annotation.IncompleteAnnotationException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 * @author Josh Bloch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
public interface AnnotatedElement {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * Returns true if an annotation for the specified type
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   241
     * is <em>present</em> on this element, else false.  This method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * is designed primarily for convenient access to marker annotations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
15511
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   244
     * <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
   245
     * {@code getAnnotation(annotationClass) != null}
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   246
     *
15534
19228f4aedb4 8007113: Upgrade AnnotatedElement.isAnnotionPresent to be a default method
darcy
parents: 15511
diff changeset
   247
     * <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
   248
     * above.
19228f4aedb4 8007113: Upgrade AnnotatedElement.isAnnotionPresent to be a default method
darcy
parents: 15511
diff changeset
   249
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @param annotationClass the Class object corresponding to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *        annotation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @return true if an annotation for the specified annotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *     type is present on this element, else false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @throws NullPointerException if the given annotation class is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
15534
19228f4aedb4 8007113: Upgrade AnnotatedElement.isAnnotionPresent to be a default method
darcy
parents: 15511
diff changeset
   257
    default boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
19228f4aedb4 8007113: Upgrade AnnotatedElement.isAnnotionPresent to be a default method
darcy
parents: 15511
diff changeset
   258
        return getAnnotation(annotationClass) != null;
19228f4aedb4 8007113: Upgrade AnnotatedElement.isAnnotionPresent to be a default method
darcy
parents: 15511
diff changeset
   259
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Returns this element's annotation for the specified type if
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   263
     * such an annotation is <em>present</em>, else null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
18546
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 16037
diff changeset
   265
     * @param <T> the type of the annotation to query for and return if present
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @param annotationClass the Class object corresponding to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *        annotation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @return this element's annotation for the specified annotation type if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *     present on this element, else null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @throws NullPointerException if the given annotation class is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    <T extends Annotation> T getAnnotation(Class<T> annotationClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   276
     * 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
   277
     *
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   278
     * 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
   279
     * 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
   280
     *
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   281
     * The caller of this method is free to modify the returned array; it will
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   282
     * have no effect on the arrays returned to other callers.
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   283
     *
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   284
     * @return annotations present on this element
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   285
     * @since 1.5
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   286
     */
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   287
    Annotation[] getAnnotations();
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   288
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   289
    /**
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   290
     * Returns annotations that are <em>associated</em> with this element.
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   291
     *
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   292
     * If there are no annotations <em>associated</em> with this element, the return
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   293
     * value is an array of length 0.
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   294
     *
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   295
     * 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
   296
     * 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
   297
     * 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
   298
     * 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
   299
     * annotation.
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   300
     *
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   301
     * 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
   302
     * 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
   303
     *
21419
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   304
     * @implSpec The default implementation first calls {@link
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   305
     * #getDeclaredAnnotationsByType(Class)} passing {@code
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   306
     * annotationClass} as the argument. If the returned array has
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   307
     * length greater than zero, the array is returned. If the returned
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   308
     * array is zero-length and this {@code AnnotatedElement} is a
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   309
     * class and the argument type is an inheritable annotation type,
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   310
     * and the superclass of this {@code AnnotatedElement} is non-null,
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   311
     * then the returned result is the result of calling {@link
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   312
     * #getAnnotationsByType(Class)} on the superclass with {@code
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   313
     * annotationClass} as the argument. Otherwise, a zero-length
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   314
     * array is returned.
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   315
     *
18546
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 16037
diff changeset
   316
     * @param <T> the type of the annotation to query for and return if present
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   317
     * @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
   318
     *        annotation type
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   319
     * @return all this element's annotations for the specified annotation type if
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   320
     *     associated with this element, else an array of length zero
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   321
     * @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
   322
     * @since 1.8
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   323
     */
21419
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   324
    default <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   325
         /*
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   326
          * Definition of associated: directly or indirectly present OR
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   327
          * neither directly nor indirectly present AND the element is
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   328
          * a Class, the annotation type is inheritable, and the
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   329
          * annotation type is associated with the superclass of the
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   330
          * element.
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   331
          */
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   332
         T[] result = getDeclaredAnnotationsByType(annotationClass);
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   333
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   334
         if (result.length == 0 && // Neither directly nor indirectly present
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   335
             this instanceof Class && // the element is a class
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   336
             AnnotationType.getInstance(annotationClass).isInherited()) { // Inheritable
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   337
             Class<?> superClass = ((Class<?>) this).getSuperclass();
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   338
             if (superClass != null) {
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   339
                 // Determine if the annotation is associated with the
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   340
                 // superclass
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   341
                 result = superClass.getAnnotationsByType(annotationClass);
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   342
             }
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   343
         }
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   344
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   345
         return result;
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   346
     }
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   347
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   348
    /**
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   349
     * Returns this element's annotation for the specified type if
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   350
     * such an annotation is <em>directly present</em>, else null.
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   351
     *
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   352
     * 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
   353
     * annotations are directly present on this element.)
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   354
     *
21419
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   355
     * @implSpec The default implementation first performs a null check
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   356
     * and then loops over the results of {@link
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   357
     * #getDeclaredAnnotations} returning the first annotation whose
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   358
     * annotation type matches the argument type.
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   359
     *
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   360
     * @param <T> the type of the annotation to query for and return if directly present
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   361
     * @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
   362
     *        annotation type
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   363
     * @return this element's annotation for the specified annotation type if
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   364
     *     directly present on this element, else null
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   365
     * @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
   366
     * @since 1.8
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   367
     */
21419
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   368
    default <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) {
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   369
         Objects.requireNonNull(annotationClass);
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   370
         // Loop over all directly-present annotations looking for a matching one
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   371
         for (Annotation annotation : getDeclaredAnnotations()) {
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   372
             if (annotationClass.equals(annotation.annotationType())) {
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   373
                 // More robust to do a dynamic cast at runtime instead
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   374
                 // of compile-time only.
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   375
                 return annotationClass.cast(annotation);
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   376
             }
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   377
         }
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   378
         return null;
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   379
     }
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   380
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   381
    /**
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   382
     * Returns this element's annotation(s) for the specified type if
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   383
     * such annotations are either <em>directly present</em> or
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   384
     * <em>indirectly present</em>. This method ignores inherited
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   385
     * annotations.
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   386
     *
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   387
     * If there are no specified annotations directly or indirectly
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   388
     * present on this element, the return value is an array of length
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   389
     * 0.
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   390
     *
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   391
     * The difference between this method and {@link
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   392
     * #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
   393
     * 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
   394
     * attempts to find one or more annotations of that type by "looking
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   395
     * through" a container annotation if one is present.
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   396
     *
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   397
     * 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
   398
     * 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
   399
     *
21419
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   400
     * @implSpec The default implementation may call {@link
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   401
     * #getDeclaredAnnotation(Class)} one or more times to find a
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   402
     * directly present annotation and, if the annotation type is
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   403
     * repeatable, to find a container annotation. If annotations of
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   404
     * the annotation type {@code annotationClass} are found to be both
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   405
     * directly and indirectly present, then {@link
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   406
     * #getDeclaredAnnotations()} will get called to determine the
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   407
     * order of the elements in the returned array.
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   408
     *
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   409
     * <p>Alternatively, the default implementation may call {@link
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   410
     * #getDeclaredAnnotations()} a single time and the returned array
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   411
     * examined for both directly and indirectly present
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   412
     * annotations. The results of calling {@link
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   413
     * #getDeclaredAnnotations()} are assumed to be consistent with the
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   414
     * results of calling {@link #getDeclaredAnnotation(Class)}.
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   415
     *
18546
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 16037
diff changeset
   416
     * @param <T> the type of the annotation to query for and return
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   417
     * if directly or indirectly present
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   418
     * @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
   419
     *        annotation type
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   420
     * @return all this element's annotations for the specified annotation type if
18817
0b6120f7f884 8010679: Clarify "present" and annotation ordering in Core Reflection for Annotations
darcy
parents: 18546
diff changeset
   421
     *     directly or indirectly present on this element, else an array of length zero
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   422
     * @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
   423
     * @since 1.8
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   424
     */
21419
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   425
    default <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) {
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   426
        Objects.requireNonNull(annotationClass);
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   427
        return AnnotationSupport.
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   428
            getDirectlyAndIndirectlyPresent(Arrays.stream(getDeclaredAnnotations()).
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   429
                                            collect(Collectors.toMap(Annotation::annotationType,
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   430
                                                                     Function.identity(),
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   431
                                                                     ((first,second) -> first),
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   432
                                                                     LinkedHashMap::new)),
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   433
                                            annotationClass);
a842a3bbee57 8005294: Consider default methods for additions to AnnotatedElement
darcy
parents: 18817
diff changeset
   434
    }
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   435
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 5506
diff changeset
   436
    /**
15511
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   437
     * 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
   438
     * This method ignores inherited annotations.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *
15511
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   440
     * 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
   441
     * 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
   442
     *
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   443
     * 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
   444
     * 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
   445
     *
8f45487ac694 8005712: Simplify support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14676
diff changeset
   446
     * @return annotations directly present on this element
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    Annotation[] getDeclaredAnnotations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
}