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