-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
PsiClass.java
404 lines (355 loc) · 13 KB
/
PsiClass.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.psi;
import com.intellij.lang.jvm.JvmClass;
import com.intellij.lang.jvm.JvmClassKind;
import com.intellij.lang.jvm.JvmMethod;
import com.intellij.lang.jvm.types.JvmReferenceType;
import com.intellij.openapi.util.NlsSafe;
import com.intellij.openapi.util.Pair;
import com.intellij.pom.PomRenameableTarget;
import com.intellij.util.ArrayFactory;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.List;
/**
* Represents a Java class or interface.
*
* @see PsiJavaFile#getClasses()
*/
public interface PsiClass
extends PsiNameIdentifierOwner, PsiModifierListOwner, PsiDocCommentOwner, PsiTypeParameterListOwner,
PsiQualifiedNamedElement, PsiTarget, PomRenameableTarget<PsiElement>, JvmClass {
/**
* The empty array of PSI classes which can be reused to avoid unnecessary allocations.
*/
PsiClass @NotNull [] EMPTY_ARRAY = new PsiClass[0];
ArrayFactory<PsiClass> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new PsiClass[count];
/**
* Returns the fully qualified name of the class.
*
* @return the qualified name of the class, or null for anonymous and local classes, and for type parameters
*/
@Override
@Nullable @NlsSafe
String getQualifiedName();
/**
* Checks if the class is an interface.
*
* @return true if the class is an interface, false otherwise.
*/
boolean isInterface();
/**
* Checks if the class is an annotation type.
*
* @return true if the class is an annotation type, false otherwise
*/
boolean isAnnotationType();
/**
* Checks if the class is an enumeration.
*
* @return true if the class is an enumeration, false otherwise.
*/
boolean isEnum();
/**
* Checks if the class is a record.
*
* @return true if the class is a record, false otherwise.
*/
default boolean isRecord() {
return false;
}
/**
* Returns the list of classes that this class or interface extends.
*
* @return the extends list, or null for anonymous classes and unnamed classes.
*/
@Nullable
PsiReferenceList getExtendsList();
/**
* Returns the list of interfaces that this class implements.
*
* @return the implements list, or null for anonymous classes and unnamed classes
*/
@Nullable
PsiReferenceList getImplementsList();
/**
* Returns the array of class types for the classes that this class or interface extends.
*
* @return the array of extended class types, or an empty list for anonymous classes and implicitly declared classes.
*/
PsiClassType @NotNull [] getExtendsListTypes();
/**
* Returns the array of class types for the interfaces that this class implements.
*
* @return the array of extended class types, or an empty list for anonymous classes,
* enums, annotation types and implicitly declared classes
*/
PsiClassType @NotNull [] getImplementsListTypes();
/**
* Returns the list of classes that this class or interface explicitly permits.
*
* @return the permits list, or null if there's none.
*/
@Nullable
default PsiReferenceList getPermitsList() {
return null;
}
/**
* Returns the array of class types that this class or interface explicitly permits.
*
* @return the array of explicitly permitted classes.
*/
default PsiClassType @NotNull [] getPermitsListTypes() {
PsiReferenceList permitsList = getPermitsList();
if (permitsList != null) {
return permitsList.getReferencedTypes();
}
return PsiClassType.EMPTY_ARRAY;
}
/**
* Returns the base class of this class.
*
* @return the base class. May return null when jdk is not configured, so no java.lang.Object is found,
* or for java.lang.Object itself
*/
@Nullable
PsiClass getSuperClass();
/**
* Returns the array of interfaces implemented by the class, or extended by the interface.
*
* @return the array of interfaces.
*/
PsiClass @NotNull [] getInterfaces();
/**
* Returns the array of classes and interfaces extended or implemented by the class.
*
* @return the array of classes or interfaces. May return zero elements when jdk is
* not configured, so no java.lang.Object is found
*/
PsiClass @NotNull [] getSupers();
/**
* Returns the array of class types for the classes and interfaces extended or
* implemented by the class.
*
* @return the array of class types for the classes or interfaces.
* For the class with no explicit extends list, the returned list always contains at least one element for the java.lang.Object type.
* If psiClass is java.lang.Object, returned list is empty.
*/
PsiClassType @NotNull [] getSuperTypes();
/**
* Returns the array of fields in the class.
*
* @return the array of fields.
*/
@Override
PsiField @NotNull [] getFields();
/**
* Returns the array of methods in the class.
*
* @return the array of methods.
*/
@Override
PsiMethod @NotNull [] getMethods();
/**
* Returns the array of constructors for the class.
*
* @return the array of constructors,
*/
PsiMethod @NotNull [] getConstructors();
/**
* Returns the array of inner classes for the class.
*
* @return the array of inner classes.
*/
@Override
PsiClass @NotNull [] getInnerClasses();
/**
* Returns the array of class initializers for the class.
*
* @return the array of class initializers.
*/
PsiClassInitializer @NotNull [] getInitializers();
/**
* Returns the array of fields in the class and all its superclasses.
*
* @return the array of fields.
*/
PsiField @NotNull [] getAllFields();
/**
* Returns the array of methods in the class and all its superclasses.
*
* @return the array of methods.
*/
PsiMethod @NotNull [] getAllMethods();
/**
* Returns the array of inner classes for the class and all its superclasses.
*
* @return the array of inner classes.
*/
PsiClass @NotNull [] getAllInnerClasses();
/**
* Searches the class (and optionally its superclasses) for the field with the specified name.
*
* @param name the name of the field to find.
* @param checkBases if true, the field is also searched in the base classes of the class.
* @return the field instance, or null if the field cannot be found.
*/
@Nullable
PsiField findFieldByName(@NonNls String name, boolean checkBases);
/**
* Searches the class (and optionally its superclasses) for the method with
* the signature matching the signature of the specified method.
*
* @param patternMethod the method used as a pattern for the search.
* @param checkBases if true, the method is also searched in the base classes of the class.
* @return the method instance, or null if the method cannot be found.
*/
@Nullable
PsiMethod findMethodBySignature(@NotNull PsiMethod patternMethod, boolean checkBases);
/**
* Searches the class (and optionally its superclasses) for the methods with the signature
* matching the signature of the specified method. If the superclasses are not searched,
* the method returns multiple results only in case of a syntax error (duplicate method).
*
* @param patternMethod the method used as a pattern for the search.
* @param checkBases if true, the method is also searched in the base classes of the class.
* @return the found methods, or an empty array if no methods are found.
*/
PsiMethod @NotNull [] findMethodsBySignature(@NotNull PsiMethod patternMethod, boolean checkBases);
@Override
default JvmMethod @NotNull [] findMethodsByName(@NotNull String methodName) {
return findMethodsByName(methodName, false);
}
/**
* Searches the class (and optionally its superclasses) for the methods with the specified name.
*
* @param name the name of the methods to find.
* @param checkBases if true, the methods are also searched in the base classes of the class.
* @return the found methods, or an empty array if no methods are found.
*/
PsiMethod @NotNull [] findMethodsByName(@NonNls String name, boolean checkBases);
/**
* Searches the class (and optionally its superclasses) for the methods with the specified name
* and returns the methods along with their substitutors.
*
* @param name the name of the methods to find.
* @param checkBases if true, the methods are also searched in the base classes of the class.
* @return the found methods and their substitutors, or an empty list if no methods are found.
*/
@NotNull
List<Pair<PsiMethod, PsiSubstitutor>> findMethodsAndTheirSubstitutorsByName(@NonNls @NotNull String name, boolean checkBases);
/**
* Returns the list of methods in the class and all its superclasses, along with their
* substitutors.
*
* @return the list of methods and their substitutors
*/
@NotNull
List<Pair<PsiMethod, PsiSubstitutor>> getAllMethodsAndTheirSubstitutors();
/**
* Searches the class (and optionally its superclasses) for the inner class with the specified name.
*
* @param name the name of the inner class to find.
* @param checkBases if true, the inner class is also searched in the base classes of the class.
* @return the inner class instance, or null if the inner class cannot be found.
*/
@Nullable
PsiClass findInnerClassByName(@NonNls String name, boolean checkBases);
/**
* Returns the token representing the opening curly brace of the class.
*
* @return the token instance, or null if the token is absent in the source code file.
*/
@Nullable
PsiElement getLBrace();
/**
* Returns the token representing the closing curly brace of the class.
*
* @return the token instance, or null if the token is absent in the source code file.
*/
@Nullable
PsiElement getRBrace();
/**
* Returns the name identifier of the class.
*
* @return the name identifier, or null if the class is anonymous, synthetic jsp class or unnamed class
*/
@Override
@Nullable
PsiIdentifier getNameIdentifier();
/**
* Returns the PSI member in which the class has been declared (for example,
* the method containing the anonymous inner class, or the file containing a regular
* class, or the class owning a type parameter).
*
* @return the member in which the class has been declared.
*/
PsiElement getScope();
/**
* Checks if this class is an inheritor of the specified base class.
* Only java inheritance rules are considered.
* Note that {@link com.intellij.psi.search.searches.ClassInheritorsSearch}
* may return classes that are inheritors in broader, e.g. in ejb sense, but not in java sense.
*
* @param baseClass the base class to check the inheritance.
* @param checkDeep if false, only direct inheritance is checked; if true, the base class is
* searched in the entire inheritance chain
* @return true if the class is an inheritor, false otherwise
*/
boolean isInheritor(@NotNull PsiClass baseClass, boolean checkDeep);
/**
* Checks if this class is a deep inheritor of the specified base class possibly bypassing a class
* when checking inheritance chain.
* Only java inheritance rules are considered.
* Note that {@link com.intellij.psi.search.searches.ClassInheritorsSearch}
* may return classes that are inheritors in broader, e.g. in ejb sense, but not in java sense.
*
* @param baseClass the base class to check the inheritance.
* searched in the entire inheritance chain
* @param classToByPass class to bypass the inheritance check for
* @return true if the class is an inheritor, false otherwise
*/
boolean isInheritorDeep(@NotNull PsiClass baseClass, @Nullable PsiClass classToByPass);
/**
* For an inner class, returns its containing class.
*
* @return the containing class, or null if the class is not an inner class.
*/
@Override
@Nullable
PsiClass getContainingClass();
/**
* Returns the hierarchical signatures for all methods in the specified class and
* its superclasses and superinterfaces.
*
* @return the collection of signatures.
*/
@NotNull
Collection<HierarchicalMethodSignature> getVisibleSignatures();
@Override
PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException;
@NotNull
@Override
default JvmClassKind getClassKind() {
return PsiJvmConversionHelper.getJvmClassKind(this);
}
@Nullable
@Override
default JvmReferenceType getSuperClassType() {
return PsiJvmConversionHelper.getClassSuperType(this);
}
@Override
default JvmReferenceType @NotNull [] getInterfaceTypes() {
return PsiJvmConversionHelper.getClassInterfaces(this);
}
default PsiRecordComponent @NotNull [] getRecordComponents() {
return PsiRecordComponent.EMPTY_ARRAY;
}
@Nullable
default PsiRecordHeader getRecordHeader() {
return null;
}
}