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/element/Element.java
41161 views
1
/*
2
* Copyright (c) 2005, 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.element;
27
28
29
import java.lang.annotation.Annotation;
30
import java.lang.annotation.AnnotationTypeMismatchException;
31
import java.lang.annotation.IncompleteAnnotationException;
32
import java.util.List;
33
import java.util.Set;
34
35
import javax.lang.model.type.*;
36
import javax.lang.model.util.*;
37
38
/**
39
* Represents a program element such as a module, package, class, or method.
40
* Each element represents a compile-time language-level construct
41
* (and not, for example, a runtime construct of the virtual machine).
42
*
43
* <p> Elements should be compared using the {@link #equals(Object)}
44
* method. There is no guarantee that any particular element will
45
* always be represented by the same object.
46
*
47
* <p> To implement operations based on the class of an {@code
48
* Element} object, either use a {@linkplain ElementVisitor visitor} or
49
* use the result of the {@link #getKind} method. Using {@code
50
* instanceof} is <em>not</em> necessarily a reliable idiom for
51
* determining the effective class of an object in this modeling
52
* hierarchy since an implementation may choose to have a single object
53
* implement multiple {@code Element} subinterfaces.
54
*
55
* @author Joseph D. Darcy
56
* @author Scott Seligman
57
* @author Peter von der Ah&eacute;
58
* @see Elements
59
* @see TypeMirror
60
* @since 1.6
61
*/
62
public interface Element extends javax.lang.model.AnnotatedConstruct {
63
/**
64
* {@return the type defined by this element}
65
*
66
* @see Types
67
* @see ExecutableElement#asType
68
* @see ModuleElement#asType
69
* @see PackageElement#asType
70
* @see TypeElement#asType
71
* @see TypeParameterElement#asType
72
* @see VariableElement#asType
73
*/
74
TypeMirror asType();
75
76
/**
77
* {@return the {@code kind} of this element}
78
*
79
* <ul>
80
*
81
* <li> The kind of a {@linkplain PackageElement package} is
82
* {@link ElementKind#PACKAGE PACKAGE}.
83
*
84
* <li> The kind of a {@linkplain ModuleElement module} is {@link
85
* ElementKind#MODULE MODULE}.
86
*
87
* <li> The kind of a {@linkplain TypeElement type element} is one
88
* of {@link ElementKind#ANNOTATION_TYPE ANNOTATION_TYPE}, {@link
89
* ElementKind#CLASS CLASS}, {@link ElementKind#ENUM ENUM}, {@link
90
* ElementKind#INTERFACE INTERFACE}, or {@link ElementKind#RECORD
91
* RECORD}.
92
*
93
* <li> The kind of a {@linkplain VariableElement variable} is one
94
* of {@link ElementKind#ENUM_CONSTANT ENUM_CONSTANT}, {@link
95
* ElementKind#EXCEPTION_PARAMETER EXCEPTION_PARAMETER}, {@link
96
* ElementKind#FIELD FIELD}, {@link ElementKind#LOCAL_VARIABLE
97
* LOCAL_VARIABLE}, {@link ElementKind#PARAMETER PARAMETER},
98
* {@link ElementKind#RESOURCE_VARIABLE RESOURCE_VARIABLE}, or
99
* {@link ElementKind#BINDING_VARIABLE BINDING_VARIABLE}.
100
*
101
* <li> The kind of an {@linkplain ExecutableElement executable}
102
* is one of {@link ElementKind#CONSTRUCTOR CONSTRUCTOR}, {@link
103
* ElementKind#INSTANCE_INIT INSTANCE_INIT}, {@link
104
* ElementKind#METHOD METHOD}, or {@link ElementKind#STATIC_INIT
105
* STATIC_INIT}.
106
*
107
* <li> The kind of a {@linkplain TypeParameterElement type parameter} is
108
* {@link ElementKind#TYPE_PARAMETER TYPE_PARAMETER}.
109
*
110
* <li> The kind of a {@linkplain RecordComponentElement record
111
* component} is {@link ElementKind#RECORD_COMPONENT
112
* RECORD_COMPONENT}.
113
*
114
* </ul>
115
*/
116
ElementKind getKind();
117
118
/**
119
* Returns the modifiers of this element, excluding annotations.
120
* Implicit modifiers, such as the {@code public} and {@code static}
121
* modifiers of interface members, are included.
122
*
123
* @return the modifiers of this element, or an empty set if there are none
124
*/
125
Set<Modifier> getModifiers();
126
127
/**
128
* {@return the simple (unqualified) name of this element} The
129
* name of a generic class or interface does not include any
130
* reference to its formal type parameters.
131
*
132
* For example, the simple name of the type element representing
133
* {@code java.util.Set<E>} is {@code "Set"}.
134
*
135
* If this element represents an unnamed {@linkplain
136
* PackageElement#getSimpleName package} or unnamed {@linkplain
137
* ModuleElement#getSimpleName module}, an <a
138
* href=Name.html#empty_name>empty name</a> is returned.
139
*
140
* If it represents a {@linkplain ExecutableElement#getSimpleName
141
* constructor}, the name "{@code <init>}" is returned. If it
142
* represents a {@linkplain ExecutableElement#getSimpleName static
143
* initializer}, the name "{@code <clinit>}" is returned.
144
*
145
* If it represents an {@linkplain TypeElement#getSimpleName
146
* anonymous class} or {@linkplain ExecutableElement#getSimpleName
147
* instance initializer}, an <a href=Name.html#empty_name>empty
148
* name</a> is returned.
149
*
150
* @see PackageElement#getSimpleName
151
* @see ExecutableElement#getSimpleName
152
* @see TypeElement#getSimpleName
153
* @see VariableElement#getSimpleName
154
* @see ModuleElement#getSimpleName
155
* @see RecordComponentElement#getSimpleName
156
* @revised 9
157
*/
158
Name getSimpleName();
159
160
/**
161
* Returns the innermost element
162
* within which this element is, loosely speaking, enclosed.
163
* <ul>
164
* <li> If this element is one whose declaration is lexically enclosed
165
* immediately within the declaration of another element, that other
166
* element is returned.
167
*
168
* <li> If this is a {@linkplain TypeElement#getEnclosingElement
169
* top-level class or interface}, its package is returned.
170
*
171
* <li> If this is a {@linkplain
172
* PackageElement#getEnclosingElement package}, its module is
173
* returned if such a module exists. Otherwise, {@code null} is returned.
174
*
175
* <li> If this is a {@linkplain
176
* TypeParameterElement#getEnclosingElement type parameter},
177
* {@linkplain TypeParameterElement#getGenericElement the
178
* generic element} of the type parameter is returned.
179
*
180
* <li> If this is a {@linkplain
181
* VariableElement#getEnclosingElement method or constructor
182
* parameter}, {@linkplain ExecutableElement the executable
183
* element} which declares the parameter is returned.
184
*
185
* <li> If this is a {@linkplain
186
* RecordComponentElement#getEnclosingElement record component},
187
* {@linkplain TypeElement the record class} which declares the
188
* record component is returned.
189
*
190
* <li> If this is a {@linkplain ModuleElement#getEnclosingElement
191
* module}, {@code null} is returned.
192
*
193
* </ul>
194
*
195
* @return the enclosing element, or {@code null} if there is none
196
* @see Elements#getPackageOf
197
* @revised 9
198
*/
199
Element getEnclosingElement();
200
201
/**
202
* Returns the elements that are, loosely speaking, directly
203
* enclosed by this element.
204
*
205
* A {@linkplain TypeElement#getEnclosedElements class or
206
* interface} is considered to enclose the fields, methods,
207
* constructors, record components, and member classes and interfaces that it directly declares.
208
*
209
* A {@linkplain PackageElement#getEnclosedElements package}
210
* encloses the top-level classes and interfaces within it, but is
211
* not considered to enclose subpackages.
212
*
213
* A {@linkplain ModuleElement#getEnclosedElements module}
214
* encloses packages within it.
215
*
216
* Enclosed elements may include implicitly declared {@linkplain
217
* Elements.Origin#MANDATED mandated} elements.
218
*
219
* Other kinds of elements are not currently considered to enclose
220
* any elements; however, that may change as this API or the
221
* programming language evolves.
222
*
223
* @apiNote Elements of certain kinds can be isolated using
224
* methods in {@link ElementFilter}.
225
*
226
* @return the enclosed elements, or an empty list if none
227
* @see TypeElement#getEnclosedElements
228
* @see PackageElement#getEnclosedElements
229
* @see ModuleElement#getEnclosedElements
230
* @see Elements#getAllMembers
231
* @jls 8.8.9 Default Constructor
232
* @jls 8.9 Enum Classes
233
* @revised 9
234
*/
235
List<? extends Element> getEnclosedElements();
236
237
/**
238
* {@return {@code true} if the argument represents the same
239
* element as {@code this}, or {@code false} otherwise}
240
*
241
* @apiNote The identity of an element involves implicit state
242
* not directly accessible from the element's methods, including
243
* state about the presence of unrelated types. Element objects
244
* created by different implementations of these interfaces should
245
* <i>not</i> be expected to be equal even if &quot;the same&quot;
246
* element is being modeled; this is analogous to the inequality
247
* of {@code Class} objects for the same class file loaded through
248
* different class loaders.
249
*
250
* @param obj the object to be compared with this element
251
*/
252
@Override
253
boolean equals(Object obj);
254
255
/**
256
* Obeys the general contract of {@link Object#hashCode Object.hashCode}.
257
*
258
* @see #equals
259
*/
260
@Override
261
int hashCode();
262
263
/**
264
* {@inheritDoc}
265
*
266
* <p>To get inherited annotations as well, use {@link
267
* Elements#getAllAnnotationMirrors(Element)
268
* getAllAnnotationMirrors}.
269
*
270
* <p>Note that any annotations returned by this method are
271
* declaration annotations.
272
*
273
* @since 1.6
274
*/
275
@Override
276
List<? extends AnnotationMirror> getAnnotationMirrors();
277
278
/**
279
* {@inheritDoc}
280
*
281
* <p>Note that any annotation returned by this method is a
282
* declaration annotation.
283
*
284
* @since 1.6
285
*/
286
@Override
287
<A extends Annotation> A getAnnotation(Class<A> annotationType);
288
289
/**
290
* {@inheritDoc}
291
*
292
* <p>Note that any annotations returned by this method are
293
* declaration annotations.
294
*
295
* @since 8
296
*/
297
@Override
298
<A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType);
299
300
/**
301
* Applies a visitor to this element.
302
*
303
* @param <R> the return type of the visitor's methods
304
* @param <P> the type of the additional parameter to the visitor's methods
305
* @param v the visitor operating on this element
306
* @param p additional parameter to the visitor
307
* @return a visitor-specified result
308
*/
309
<R, P> R accept(ElementVisitor<R, P> v, P p);
310
}
311
312