Skip to content

Commit dbe219f

Browse files
committed
Fixing compilation after platform update. Some refactoring.
1 parent 0d64dad commit dbe219f

3 files changed

Lines changed: 165 additions & 135 deletions

File tree

‎java-language-api/src/main/java/com/intellij/java/language/psi/PsiExpression.java‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,26 @@
1818
import consulo.util.collection.ArrayFactory;
1919

2020
import org.jspecify.annotations.Nullable;
21+
2122
import java.util.function.Function;
2223

2324
/**
2425
* Represents a Java expression.
2526
*/
2627
public interface PsiExpression extends PsiAnnotationMemberValue, PsiCaseLabelElement {
27-
/**
28-
* The empty array of PSI expressions which can be reused to avoid unnecessary allocations.
29-
*/
30-
PsiExpression[] EMPTY_ARRAY = new PsiExpression[0];
28+
/**
29+
* The empty array of PSI expressions which can be reused to avoid unnecessary allocations.
30+
*/
31+
PsiExpression[] EMPTY_ARRAY = new PsiExpression[0];
3132

32-
ArrayFactory<PsiExpression> ARRAY_FACTORY = count -> count == 0 ? PsiExpression.EMPTY_ARRAY : new PsiExpression[count];
33+
ArrayFactory<PsiExpression> ARRAY_FACTORY = count -> count == 0 ? PsiExpression.EMPTY_ARRAY : new PsiExpression[count];
3334

34-
Function<PsiExpression, PsiType> EXPRESSION_TO_TYPE = PsiExpression::getType;
35+
Function<PsiExpression, PsiType> EXPRESSION_TO_TYPE = PsiExpression::getType;
3536

36-
/**
37-
* Returns the type of the expression.
38-
*
39-
* @return the expression type, or null if the type is not known.
40-
*/
41-
@Nullable
42-
PsiType getType();
37+
/**
38+
* Returns the type of the expression.
39+
*
40+
* @return the expression type, or null if the type is not known.
41+
*/
42+
@Nullable PsiType getType();
4343
}

‎java-language-api/src/main/java/com/intellij/java/language/psi/util/InheritanceUtil.java‎

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
package com.intellij.java.language.psi.util;
1717

1818
import com.intellij.java.language.psi.*;
19-
import consulo.application.util.function.Processor;
19+
import consulo.annotation.access.RequiredReadAction;
2020
import consulo.language.psi.PsiElement;
2121
import consulo.language.psi.PsiFile;
2222
import consulo.language.psi.PsiManager;
23-
import consulo.util.lang.function.Condition;
24-
import org.jspecify.annotations.Nullable;
2523
import org.jetbrains.annotations.Contract;
24+
import org.jspecify.annotations.Nullable;
2625

2726
import java.util.HashSet;
2827
import java.util.LinkedHashSet;
@@ -64,12 +63,12 @@ private static boolean processSupers(PsiClass aClass, Predicate<PsiClass> superP
6463
return true;
6564
}
6665

67-
for (final PsiClass intf : aClass.getInterfaces()) {
66+
for (PsiClass intf : aClass.getInterfaces()) {
6867
if (!superProcessor.test(intf) || !processSupers(intf, superProcessor, visited)) {
6968
return false;
7069
}
7170
}
72-
final PsiClass superClass = aClass.getSuperClass();
71+
PsiClass superClass = aClass.getSuperClass();
7372
if (superClass != null) {
7473
if (!superProcessor.test(superClass) || !processSupers(superClass, superProcessor, visited)) {
7574
return false;
@@ -79,13 +78,13 @@ private static boolean processSupers(PsiClass aClass, Predicate<PsiClass> superP
7978
}
8079

8180
@Contract("null, _ -> false")
82-
public static boolean isInheritor(@Nullable PsiType type, final String baseClassName) {
83-
if (type instanceof PsiClassType) {
84-
return isInheritor(((PsiClassType) type).resolve(), baseClassName);
81+
public static boolean isInheritor(@Nullable PsiType type, String baseClassName) {
82+
if (type instanceof PsiClassType classType) {
83+
return isInheritor(classType.resolve(), baseClassName);
8584
}
8685

87-
if (type instanceof PsiIntersectionType) {
88-
for (PsiType conjunct : ((PsiIntersectionType) type).getConjuncts()) {
86+
if (type instanceof PsiIntersectionType intersectionType) {
87+
for (PsiType conjunct : intersectionType.getConjuncts()) {
8988
if (isInheritor(conjunct, baseClassName)) {
9089
return true;
9190
}
@@ -96,17 +95,17 @@ public static boolean isInheritor(@Nullable PsiType type, final String baseClass
9695
}
9796

9897
@Contract("null, _ -> false")
99-
public static boolean isInheritor(@Nullable PsiClass psiClass, final String baseClassName) {
98+
public static boolean isInheritor(@Nullable PsiClass psiClass, String baseClassName) {
10099
return isInheritor(psiClass, false, baseClassName);
101100
}
102101

103102
@Contract("null, _, _ -> false")
104-
public static boolean isInheritor(@Nullable PsiClass psiClass, final boolean strict, final String baseClassName) {
103+
public static boolean isInheritor(@Nullable PsiClass psiClass, boolean strict, String baseClassName) {
105104
if (psiClass == null) {
106105
return false;
107106
}
108107

109-
final PsiClass base = JavaPsiFacade.getInstance(psiClass.getProject()).findClass(baseClassName, psiClass.getResolveScope());
108+
PsiClass base = JavaPsiFacade.getInstance(psiClass.getProject()).findClass(baseClassName, psiClass.getResolveScope());
110109
if (base == null) {
111110
return false;
112111
}
@@ -131,8 +130,13 @@ public static LinkedHashSet<PsiClass> getSuperClasses(PsiClass aClass) {
131130
return result;
132131
}
133132

134-
135-
private static void getSuperClassesOfList(PsiClassType[] types, Set<PsiClass> results, boolean includeNonProject, Set<PsiClass> visited, PsiManager manager) {
133+
private static void getSuperClassesOfList(
134+
PsiClassType[] types,
135+
Set<PsiClass> results,
136+
boolean includeNonProject,
137+
Set<PsiClass> visited,
138+
PsiManager manager
139+
) {
136140
for (PsiClassType type : types) {
137141
PsiClass resolved = type.resolve();
138142
if (resolved != null && visited.add(resolved)) {
@@ -144,31 +148,42 @@ private static void getSuperClassesOfList(PsiClassType[] types, Set<PsiClass> re
144148
}
145149
}
146150

147-
public static boolean hasEnclosingInstanceInScope(PsiClass aClass, PsiElement scope, boolean isSuperClassAccepted, boolean isTypeParamsAccepted) {
151+
@RequiredReadAction
152+
public static boolean hasEnclosingInstanceInScope(
153+
PsiClass aClass,
154+
PsiElement scope,
155+
boolean isSuperClassAccepted,
156+
boolean isTypeParamsAccepted
157+
) {
148158
return hasEnclosingInstanceInScope(aClass, scope, psiClass -> isSuperClassAccepted, isTypeParamsAccepted);
149159
}
150160

151-
public static boolean hasEnclosingInstanceInScope(PsiClass aClass, PsiElement scope, Condition<PsiClass> isSuperClassAccepted, boolean isTypeParamsAccepted) {
161+
@RequiredReadAction
162+
public static boolean hasEnclosingInstanceInScope(
163+
PsiClass aClass,
164+
PsiElement scope,
165+
Predicate<PsiClass> isSuperClassAccepted,
166+
boolean isTypeParamsAccepted
167+
) {
152168
PsiManager manager = aClass.getManager();
153169
PsiElement place = scope;
154170
while (place != null && place != aClass && !(place instanceof PsiFile)) {
155-
if (place instanceof PsiClass) {
156-
if (isSuperClassAccepted.value((PsiClass) place)) {
157-
if (isInheritorOrSelf((PsiClass) place, aClass, true)) {
171+
if (place instanceof PsiClass psiClass) {
172+
if (isSuperClassAccepted.test(psiClass)) {
173+
if (isInheritorOrSelf(psiClass, aClass, true)) {
158174
return true;
159175
}
160176
}
161-
else {
162-
if (manager.areElementsEquivalent(place, aClass)) {
163-
return true;
164-
}
177+
else if (manager.areElementsEquivalent(place, aClass)) {
178+
return true;
165179
}
180+
166181
if (isTypeParamsAccepted && place instanceof PsiTypeParameter) {
167182
return true;
168183
}
169184
}
170-
if (place instanceof PsiModifierListOwner) {
171-
final PsiModifierList modifierList = ((PsiModifierListOwner) place).getModifierList();
185+
if (place instanceof PsiModifierListOwner modifierListOwner) {
186+
PsiModifierList modifierList = modifierListOwner.getModifierList();
172187
if (modifierList != null && modifierList.hasModifierProperty(PsiModifier.STATIC)) {
173188
return false;
174189
}
@@ -178,19 +193,19 @@ public static boolean hasEnclosingInstanceInScope(PsiClass aClass, PsiElement sc
178193
return place == aClass;
179194
}
180195

181-
public static boolean processSuperTypes(PsiType type, boolean includeSelf, Processor<PsiType> processor) {
182-
if (includeSelf && !processor.process(type)) {
196+
public static boolean processSuperTypes(PsiType type, boolean includeSelf, Predicate<PsiType> processor) {
197+
if (includeSelf && !processor.test(type)) {
183198
return false;
184199
}
185200
return processSuperTypes(type, processor, new HashSet<>());
186201
}
187202

188-
private static boolean processSuperTypes(PsiType type, Processor<PsiType> processor, Set<PsiType> visited) {
203+
private static boolean processSuperTypes(PsiType type, Predicate<PsiType> processor, Set<PsiType> visited) {
189204
if (!visited.add(type)) {
190205
return true;
191206
}
192207
for (PsiType superType : type.getSuperTypes()) {
193-
if (!processor.process(superType)) {
208+
if (!processor.test(superType)) {
194209
return false;
195210
}
196211
processSuperTypes(superType, processor, visited);

0 commit comments

Comments
 (0)