author | stuefe |
Wed, 24 Oct 2018 10:42:12 +0200 | |
changeset 52233 | d682023cdd8c |
parent 47216 | 71c04702a3d5 |
child 54952 | a978d86ac389 |
permissions | -rw-r--r-- |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
1 |
/* |
43567
d0d89c3da7be
8173676: Improvements to javax.annotation.processing and javax.lang.model doc
darcy
parents:
25874
diff
changeset
|
2 |
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
4 |
* |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
10 |
* |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
15 |
* accompanied this code). |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
16 |
* |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
20 |
* |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
23 |
* questions. |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
24 |
*/ |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
25 |
|
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
26 |
package javax.lang.model; |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
27 |
|
16559 | 28 |
import java.lang.annotation.*; |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
29 |
import java.util.List; |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
30 |
import javax.lang.model.element.*; |
16559 | 31 |
import javax.lang.model.type.*; |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
32 |
|
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
33 |
/** |
16563
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
34 |
* Represents a construct that can be annotated. |
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
35 |
* |
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
36 |
* A construct is either an {@linkplain |
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
37 |
* javax.lang.model.element.Element element} or a {@linkplain |
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
38 |
* javax.lang.model.type.TypeMirror type}. Annotations on an element |
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
39 |
* are on a <em>declaration</em>, whereas annotations on a type are on |
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
40 |
* a specific <em>use</em> of a type name. |
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
41 |
* |
17802
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
42 |
* The terms <em>directly present</em>, <em>present</em>, |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
43 |
* <em>indirectly present</em>, and <em>associated </em> are used |
16563
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
44 |
* throughout this interface to describe precisely which annotations |
17802
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
45 |
* are returned by the methods defined herein. |
16563
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
46 |
* |
17802
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
47 |
* <p>In the definitions below, an annotation <i>A</i> has an |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
48 |
* annotation type <i>AT</i>. If <i>AT</i> is a repeatable annotation |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
49 |
* type, the type of the containing annotation is <i>ATC</i>. |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
50 |
* |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
51 |
* <p>Annotation <i>A</i> is <em>directly present</em> on a construct |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
52 |
* <i>C</i> if either: |
16563
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
53 |
* |
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
54 |
* <ul> |
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
55 |
* |
17802
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
56 |
* <li><i>A</i> is explicitly or implicitly declared as applying to |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
57 |
* the source code representation of <i>C</i>. |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
58 |
* |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
59 |
* <p>Typically, if exactly one annotation of type <i>AT</i> appears in |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
60 |
* the source code of representation of <i>C</i>, then <i>A</i> is |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
61 |
* explicitly declared as applying to <i>C</i>. |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
62 |
* |
17802
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
63 |
* If there are multiple annotations of type <i>AT</i> present on |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
64 |
* <i>C</i>, then if <i>AT</i> is repeatable annotation type, an |
43567
d0d89c3da7be
8173676: Improvements to javax.annotation.processing and javax.lang.model doc
darcy
parents:
25874
diff
changeset
|
65 |
* annotation of type <i>ATC</i> is {@linkplain javax.lang.model.util.Elements#getOrigin(AnnotatedConstruct, AnnotationMirror) implicitly declared} on <i>C</i>. |
17802
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
66 |
* |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
67 |
* <li> A representation of <i>A</i> appears in the executable output |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
68 |
* for <i>C</i>, such as the {@code RuntimeVisibleAnnotations} or |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
69 |
* {@code RuntimeVisibleParameterAnnotations} attributes of a class |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
70 |
* file. |
16563
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
71 |
* |
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
72 |
* </ul> |
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
73 |
* |
17802
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
74 |
* <p>An annotation <i>A</i> is <em>present</em> on a |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
75 |
* construct <i>C</i> if either: |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
76 |
* <ul> |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
77 |
* |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
78 |
* <li><i>A</i> is directly present on <i>C</i>. |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
79 |
* |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
80 |
* <li>No annotation of type <i>AT</i> is directly present on |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
81 |
* <i>C</i>, and <i>C</i> is a class and <i>AT</i> is inheritable |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
82 |
* and <i>A</i> is present on the superclass of <i>C</i>. |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
83 |
* |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
84 |
* </ul> |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
85 |
* |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
86 |
* An annotation <i>A</i> is <em>indirectly present</em> on a construct |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
87 |
* <i>C</i> if both: |
16563
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
88 |
* |
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
89 |
* <ul> |
17802
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
90 |
* |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
91 |
* <li><i>AT</i> is a repeatable annotation type with a containing |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
92 |
* annotation type <i>ATC</i>. |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
93 |
* |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
94 |
* <li>An annotation of type <i>ATC</i> is directly present on |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
95 |
* <i>C</i> and <i>A</i> is an annotation included in the result of |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
96 |
* calling the {@code value} method of the directly present annotation |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
97 |
* of type <i>ATC</i>. |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
98 |
* |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
99 |
* </ul> |
16563
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
100 |
* |
17802
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
101 |
* An annotation <i>A</i> is <em>associated</em> with a construct |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
102 |
* <i>C</i> if either: |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
103 |
* |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
104 |
* <ul> |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
105 |
* |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
106 |
* <li> <i>A</i> is directly or indirectly present on <i>C</i>. |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
107 |
* |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
108 |
* <li> No annotation of type <i>AT</i> is directly or indirectly |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
109 |
* present on <i>C</i>, and <i>C</i> is a class, and <i>AT</i> is |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
110 |
* inheritable, and <i>A</i> is associated with the superclass of |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
111 |
* <i>C</i>. |
16563
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
112 |
* |
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
113 |
* </ul> |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
114 |
* |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
115 |
* @since 1.8 |
16563
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
116 |
* @jls 9.6 Annotation Types |
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
117 |
* @jls 9.6.3.3 @Inherited |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
118 |
*/ |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
119 |
public interface AnnotatedConstruct { |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
120 |
/** |
16563
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
121 |
* Returns the annotations that are <em>directly present</em> on |
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
122 |
* this construct. |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
123 |
* |
16563
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
124 |
* @return the annotations <em>directly present</em> on this |
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
125 |
* construct; an empty list if there are none |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
126 |
*/ |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
127 |
List<? extends AnnotationMirror> getAnnotationMirrors(); |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
128 |
|
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
129 |
/** |
17802
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
130 |
* Returns this construct's annotation of the specified type if |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
131 |
* such an annotation is <em>present</em>, else {@code null}. |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
132 |
* |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
133 |
* <p> The annotation returned by this method could contain an element |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
134 |
* whose value is of type {@code Class}. |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
135 |
* This value cannot be returned directly: information necessary to |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
136 |
* locate and load a class (such as the class loader to use) is |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
137 |
* not available, and the class might not be loadable at all. |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
138 |
* Attempting to read a {@code Class} object by invoking the relevant |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
139 |
* method on the returned annotation |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
140 |
* will result in a {@link MirroredTypeException}, |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
141 |
* from which the corresponding {@link TypeMirror} may be extracted. |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
142 |
* Similarly, attempting to read a {@code Class[]}-valued element |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
143 |
* will result in a {@link MirroredTypesException}. |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
144 |
* |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
145 |
* <blockquote> |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
146 |
* <i>Note:</i> This method is unlike others in this and related |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
147 |
* interfaces. It operates on runtime reflective information — |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
148 |
* representations of annotation types currently loaded into the |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
149 |
* VM — rather than on the representations defined by and used |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
150 |
* throughout these interfaces. Consequently, calling methods on |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
151 |
* the returned annotation object can throw many of the exceptions |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
152 |
* that can be thrown when calling methods on an annotation object |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
153 |
* returned by core reflection. This method is intended for |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
154 |
* callers that are written to operate on a known, fixed set of |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
155 |
* annotation types. |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
156 |
* </blockquote> |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
157 |
* |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
158 |
* @param <A> the annotation type |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
159 |
* @param annotationType the {@code Class} object corresponding to |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
160 |
* the annotation type |
17802
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
161 |
* @return this construct's annotation for the specified |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
162 |
* annotation type if present, else {@code null} |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
163 |
* |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
164 |
* @see #getAnnotationMirrors() |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
165 |
* @see java.lang.reflect.AnnotatedElement#getAnnotation |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
166 |
* @see EnumConstantNotPresentException |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
167 |
* @see AnnotationTypeMismatchException |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
168 |
* @see IncompleteAnnotationException |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
169 |
* @see MirroredTypeException |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
170 |
* @see MirroredTypesException |
16563
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
171 |
* @jls 9.6.1 Annotation Type Elements |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
172 |
*/ |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
173 |
<A extends Annotation> A getAnnotation(Class<A> annotationType); |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
174 |
|
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
175 |
/** |
17802
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
176 |
* Returns annotations that are <em>associated</em> with this construct. |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
177 |
* |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
178 |
* If there are no annotations associated with this construct, the |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
179 |
* return value is an array of length 0. |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
180 |
* |
17802
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
181 |
* The order of annotations which are directly or indirectly |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
182 |
* present on a construct <i>C</i> is computed as if indirectly present |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
183 |
* annotations on <i>C</i> are directly present on <i>C</i> in place of their |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
184 |
* container annotation, in the order in which they appear in the |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
185 |
* value element of the container annotation. |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
186 |
* |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
187 |
* The difference between this method and {@link #getAnnotation(Class)} |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
188 |
* is that this method detects if its argument is a <em>repeatable |
16563
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
189 |
* annotation type</em>, and if so, attempts to find one or more |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
190 |
* annotations of that type by "looking through" a container annotation. |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
191 |
* |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
192 |
* <p> The annotations returned by this method could contain an element |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
193 |
* whose value is of type {@code Class}. |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
194 |
* This value cannot be returned directly: information necessary to |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
195 |
* locate and load a class (such as the class loader to use) is |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
196 |
* not available, and the class might not be loadable at all. |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
197 |
* Attempting to read a {@code Class} object by invoking the relevant |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
198 |
* method on the returned annotation |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
199 |
* will result in a {@link MirroredTypeException}, |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
200 |
* from which the corresponding {@link TypeMirror} may be extracted. |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
201 |
* Similarly, attempting to read a {@code Class[]}-valued element |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
202 |
* will result in a {@link MirroredTypesException}. |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
203 |
* |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
204 |
* <blockquote> |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
205 |
* <i>Note:</i> This method is unlike others in this and related |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
206 |
* interfaces. It operates on runtime reflective information — |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
207 |
* representations of annotation types currently loaded into the |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
208 |
* VM — rather than on the representations defined by and used |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
209 |
* throughout these interfaces. Consequently, calling methods on |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
210 |
* the returned annotation object can throw many of the exceptions |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
211 |
* that can be thrown when calling methods on an annotation object |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
212 |
* returned by core reflection. This method is intended for |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
213 |
* callers that are written to operate on a known, fixed set of |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
214 |
* annotation types. |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
215 |
* </blockquote> |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
216 |
* |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
217 |
* @param <A> the annotation type |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
218 |
* @param annotationType the {@code Class} object corresponding to |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
219 |
* the annotation type |
17802
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
220 |
* @return this construct's annotations for the specified annotation |
83c53847fc7e
8010680: Clarify "present" and annotation ordering in javax.lang.model
darcy
parents:
17548
diff
changeset
|
221 |
* type if present on this construct, else an empty array |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
222 |
* |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
223 |
* @see #getAnnotationMirrors() |
21041 | 224 |
* @see #getAnnotation(Class) |
225 |
* @see java.lang.reflect.AnnotatedElement#getAnnotationsByType(Class) |
|
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
226 |
* @see EnumConstantNotPresentException |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
227 |
* @see AnnotationTypeMismatchException |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
228 |
* @see IncompleteAnnotationException |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
229 |
* @see MirroredTypeException |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
230 |
* @see MirroredTypesException |
16563
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
231 |
* @jls 9.6 Annotation Types |
c0b12eae2488
8010364: Clarify javax.lang.model API for Type Annotations
darcy
parents:
16559
diff
changeset
|
232 |
* @jls 9.6.1 Annotation Type Elements |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
233 |
*/ |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
234 |
<A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType); |
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
diff
changeset
|
235 |
} |