Skip to content

Commit 787bab4

Browse files
committed
Refactoring and localizing users of EP_NAME (part 14).
1 parent bf45a44 commit 787bab4

16 files changed

Lines changed: 116 additions & 160 deletions

File tree

java-analysis-impl/src/main/java/com/intellij/java/analysis/impl/codeInsight/daemon/impl/UnusedSymbolUtil.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,10 @@ public static boolean processUsages(
245245
}
246246

247247
// if we've resolved all references, find usages will be fast
248-
PsiSearchHelper.SearchCostResult cheapEnough = RefResolveService.ENABLED && RefResolveService.getInstance
249-
(project).isUpToDate() ? PsiSearchHelper.SearchCostResult.FEW_OCCURRENCES : searchHelper
250-
.isCheapEnoughToSearch(name, (GlobalSearchScope)useScope, ignoreFile, progress);
248+
PsiSearchHelper.SearchCostResult cheapEnough =
249+
RefResolveService.ENABLED && RefResolveService.getInstance(project).isUpToDate()
250+
? PsiSearchHelper.SearchCostResult.FEW_OCCURRENCES
251+
: searchHelper.isCheapEnoughToSearch(name, globalSearchScope, ignoreFile, progress);
251252
if (cheapEnough == TOO_MANY_OCCURRENCES) {
252253
log("* " + member.getName() + " too many usages; false");
253254
return false;
@@ -263,18 +264,11 @@ public static boolean processUsages(
263264

264265
if (member instanceof PsiMethod) {
265266
String propertyName = PropertyUtil.getPropertyName(member);
266-
if (propertyName != null) {
267-
SearchScope fileScope = containingFile.getUseScope();
268-
if (fileScope instanceof GlobalSearchScope
269-
&& searchHelper.isCheapEnoughToSearch(
270-
propertyName,
271-
(GlobalSearchScope)fileScope,
272-
ignoreFile,
273-
progress
274-
) == TOO_MANY_OCCURRENCES) {
275-
log("* " + member.getName() + " too many prop usages; false");
276-
return false;
277-
}
267+
if (propertyName != null
268+
&& containingFile.getUseScope() instanceof GlobalSearchScope fileScope
269+
&& searchHelper.isCheapEnoughToSearch(propertyName, fileScope, ignoreFile, progress) == TOO_MANY_OCCURRENCES) {
270+
log("* " + member.getName() + " too many prop usages; false");
271+
return false;
278272
}
279273
}
280274
}

java-analysis-impl/src/main/java/com/intellij/java/analysis/impl/codeInsight/daemon/impl/analysis/HighlightUtil.java

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,17 +1984,16 @@ else if (resolved != null) {
19841984
return HighlightClassUtil.reportIllegalEnclosingUsage(expr, null, aClass, expr);
19851985
}
19861986

1987-
if (expr instanceof PsiSuperExpression) {
1988-
PsiElement resolved = ((PsiReferenceExpression)expr.getParent()).resolve();
1989-
//15.11.2
1990-
//The form T.super.Identifier refers to the field named Identifier of the lexically enclosing instance corresponding to T,
1991-
//but with that instance viewed as an instance of the superclass of T.
1992-
if (resolved instanceof PsiField) {
1993-
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
1994-
.range(expr)
1995-
.descriptionAndTooltip(JavaErrorLocalize.isNotAnEnclosingClass(formatClass(aClass)))
1996-
.create();
1997-
}
1987+
//15.11.2
1988+
//The form T.super.Identifier refers to the field named Identifier of the lexically enclosing instance corresponding to T,
1989+
//but with that instance viewed as an instance of the superclass of T.
1990+
if (expr instanceof PsiSuperExpression
1991+
&& expr.getParent() instanceof PsiReferenceExpression refExpr
1992+
&& refExpr.resolve() instanceof PsiField) {
1993+
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
1994+
.range(expr)
1995+
.descriptionAndTooltip(JavaErrorLocalize.isNotAnEnclosingClass(formatClass(aClass)))
1996+
.create();
19981997
}
19991998
}
20001999

@@ -2157,7 +2156,7 @@ private static boolean isInstanceReference(@Nonnull PsiJavaCodeReferenceElement
21572156
if (q != null) {
21582157
return true;
21592158
}
2160-
String qname = ((PsiJavaCodeReferenceElement)qualifier).getQualifiedName();
2159+
String qname = codeReferenceElement.getQualifiedName();
21612160
return qname == null || !Character.isLowerCase(qname.charAt(0));
21622161
}
21632162

@@ -2527,18 +2526,15 @@ public static Collection<HighlightInfo> checkSwitchLabelValues(@Nonnull PsiSwitc
25272526
LocalizeValue message = values.isEmpty()
25282527
? JavaErrorLocalize.switchExprEmpty()
25292528
: JavaErrorLocalize.switchExprIncomplete();
2530-
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
2529+
QuickFixFactory factory = QuickFixFactory.getInstance();
2530+
HighlightInfo.Builder hlBuilder = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
25312531
.range(ObjectUtil.notNull(selectorExpression, switchBlock))
2532-
.descriptionAndTooltip(message)
2533-
.create();
2532+
.descriptionAndTooltip(message);
25342533
if (!missingConstants.isEmpty()) {
2535-
QuickFixAction.registerQuickFixAction(
2536-
info,
2537-
QuickFixFactory.getInstance().createAddMissingEnumBranchesFix(switchBlock, missingConstants)
2538-
);
2534+
hlBuilder.registerFix(factory.createAddMissingEnumBranchesFix(switchBlock, missingConstants));
25392535
}
2540-
QuickFixAction.registerQuickFixAction(info, QuickFixFactory.getInstance().createAddSwitchDefaultFix(switchBlock, null));
2541-
results.add(info);
2536+
hlBuilder.registerFix(factory.createAddSwitchDefaultFix(switchBlock, null));
2537+
results.add(hlBuilder.create());
25422538
}
25432539
}
25442540

@@ -3764,19 +3760,11 @@ private static IntentionAction getChangeParameterClassFix(PsiType lType, PsiType
37643760
PsiClass lClass = PsiUtil.resolveClassInClassTypeOnly(lType);
37653761
PsiClass rClass = PsiUtil.resolveClassInClassTypeOnly(rType);
37663762

3767-
if (rClass == null || lClass == null) {
3768-
return null;
3769-
}
3770-
if (rClass instanceof PsiAnonymousClass) {
3771-
return null;
3772-
}
3773-
if (rClass.isInheritor(lClass, true)) {
3774-
return null;
3775-
}
3776-
if (lClass.isInheritor(rClass, true)) {
3777-
return null;
3778-
}
3779-
if (lClass == rClass) {
3763+
if (rClass == null || lClass == null
3764+
|| rClass instanceof PsiAnonymousClass
3765+
|| rClass.isInheritor(lClass, true)
3766+
|| lClass.isInheritor(rClass, true)
3767+
|| lClass == rClass) {
37803768
return null;
37813769
}
37823770

java-analysis-impl/src/main/java/com/intellij/java/analysis/impl/find/findUsages/JavaFindUsagesHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,12 +611,12 @@ private static boolean addResult(
611611

612612
@RequiredReadAction
613613
private static boolean filterUsage(PsiElement usage, @Nonnull FindUsagesOptions options) {
614-
if (!(usage instanceof PsiJavaCodeReferenceElement)) {
614+
if (!(usage instanceof PsiJavaCodeReferenceElement javaCodeRef)) {
615615
return true;
616616
}
617617
if (options instanceof JavaPackageFindUsagesOptions packageOptions
618618
&& !packageOptions.isIncludeSubpackages
619-
&& ((PsiReference)usage).resolve() instanceof PsiPackage
619+
&& javaCodeRef.resolve() instanceof PsiPackage
620620
&& usage.getParent() instanceof PsiJavaCodeReferenceElement codeRef
621621
&& codeRef.resolve() instanceof PsiPackage) {
622622
return false;

java-coverage-impl/src/main/java/com/intellij/java/coverage/JavaCoverageEngine.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import consulo.language.psi.PsiPackage;
3030
import consulo.language.psi.scope.GlobalSearchScope;
3131
import consulo.language.psi.util.PsiTreeUtil;
32-
import consulo.language.util.ModuleUtilCore;
3332
import consulo.logging.Logger;
3433
import consulo.module.Module;
3534
import consulo.module.content.ModuleRootManager;
@@ -155,7 +154,7 @@ public boolean coverageEditorHighlightingApplicableTo(@Nonnull PsiFile psiFile)
155154
return false;
156155
}
157156
// let's show coverage only for module files
158-
Module module = psiFile.getApplication().runReadAction((Supplier<Module>)() -> ModuleUtilCore.findModuleForPsiElement(psiFile));
157+
Module module = psiFile.getApplication().runReadAction((Supplier<Module>)psiFile::getModule);
159158
return module != null;
160159
}
161160

java-debugger-api/src/main/java/com/intellij/java/debugger/engine/DebuggerUtils.java

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public static String getValueAsString(EvaluationContext evaluationContext, Value
7272
if (value == null) {
7373
return "null";
7474
}
75-
if (value instanceof StringReference) {
76-
return ((StringReference)value).value();
75+
if (value instanceof StringReference stringRef) {
76+
return stringRef.value();
7777
}
7878
if (isInteger(value)) {
7979
long v = ((PrimitiveValue)value).longValue();
@@ -83,19 +83,19 @@ public static String getValueAsString(EvaluationContext evaluationContext, Value
8383
double v = ((PrimitiveValue)value).doubleValue();
8484
return String.valueOf(v);
8585
}
86-
if (value instanceof BooleanValue) {
87-
boolean v = ((PrimitiveValue)value).booleanValue();
86+
if (value instanceof BooleanValue booleanValue) {
87+
boolean v = booleanValue.booleanValue();
8888
return String.valueOf(v);
8989
}
90-
if (value instanceof CharValue) {
91-
char v = ((PrimitiveValue)value).charValue();
90+
if (value instanceof CharValue charValue) {
91+
char v = charValue.charValue();
9292
return String.valueOf(v);
9393
}
94-
if (value instanceof ObjectReference) {
95-
if (value instanceof ArrayReference) {
94+
if (value instanceof ObjectReference objRef) {
95+
if (objRef instanceof ArrayReference arrayRef) {
9696
StringBuilder builder = new StringBuilder();
9797
builder.append("[");
98-
for (Iterator<Value> iterator = ((ArrayReference)value).getValues().iterator(); iterator.hasNext(); ) {
98+
for (Iterator<Value> iterator = arrayRef.getValues().iterator(); iterator.hasNext(); ) {
9999
Value element = iterator.next();
100100
builder.append(getValueAsString(evaluationContext, element));
101101
if (iterator.hasNext()) {
@@ -106,7 +106,6 @@ public static String getValueAsString(EvaluationContext evaluationContext, Value
106106
return builder.toString();
107107
}
108108

109-
ObjectReference objRef = (ObjectReference)value;
110109
DebugProcess debugProcess = evaluationContext.getDebugProcess();
111110
Method toStringMethod = debugProcess.getUserData(TO_STRING_METHOD_KEY);
112111
if (toStringMethod == null) {
@@ -133,7 +132,7 @@ public static String getValueAsString(EvaluationContext evaluationContext, Value
133132
if (result == null) {
134133
return "null";
135134
}
136-
return result instanceof StringReference ? ((StringReference)result).value() : result.toString();
135+
return result instanceof StringReference stringRef ? stringRef.value() : result.toString();
137136
}
138137
throw EvaluateExceptionUtil.createEvaluateException(JavaDebuggerLocalize.evaluationErrorUnsupportedExpressionType());
139138
}
@@ -170,8 +169,8 @@ public static Method findMethod(@Nonnull ReferenceType refType, String methodNam
170169

171170
Method method = null;
172171
if (methodSignature != null) {
173-
if (refType instanceof ClassType) {
174-
method = ((ClassType)refType).concreteMethodByName(methodName, methodSignature);
172+
if (refType instanceof ClassType classType) {
173+
method = classType.concreteMethodByName(methodName, methodSignature);
175174
}
176175
if (method == null) {
177176
List<Method> methods = refType.methodsByName(methodName, methodSignature);
@@ -193,16 +192,12 @@ public static Method findMethod(@Nonnull ReferenceType refType, String methodNam
193192
}
194193

195194
public static boolean isNumeric(Value value) {
196-
return value != null && (isInteger(value) ||
197-
value instanceof FloatValue ||
198-
value instanceof DoubleValue);
195+
return value != null && (isInteger(value) || value instanceof FloatValue || value instanceof DoubleValue);
199196
}
200197

201198
public static boolean isInteger(Value value) {
202-
return value != null && (value instanceof ByteValue ||
203-
value instanceof ShortValue ||
204-
value instanceof LongValue ||
205-
value instanceof IntegerValue);
199+
return value != null
200+
&& (value instanceof ByteValue || value instanceof ShortValue || value instanceof LongValue || value instanceof IntegerValue);
206201
}
207202

208203
public static String translateStringValue(String str) {

java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/DebuggerSession.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,8 @@ public void contextAction() throws Exception {
657657
boolean sourceMissing = foundFile instanceof PsiCompiledElement;
658658
for (Pair<Breakpoint, consulo.internal.com.sun.jdi.event.Event> eventDescriptor : eventDescriptors) {
659659
Breakpoint breakpoint = eventDescriptor.getFirst();
660-
if (breakpoint instanceof LineBreakpoint) {
661-
SourcePosition breakpointPosition = ((BreakpointWithHighlighter)breakpoint).getSourcePosition();
660+
if (breakpoint instanceof LineBreakpoint lineBreakpoint) {
661+
SourcePosition breakpointPosition = lineBreakpoint.getSourcePosition();
662662
if (breakpointPosition == null || (!sourceMissing && breakpointPosition.getLine() != position.getLine())) {
663663
requestsManager.deleteRequest(breakpoint);
664664
requestsManager.setInvalid(breakpoint, JavaDebuggerLocalize.errorInvalidBreakpointSourceChanged().get());

java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/engine/DebugProcessImpl.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,15 +1088,15 @@ private E invokeMethodAndFork(SuspendContextImpl context)
10881088
if (lastIndex >= 0 && myArgs.size() > lastIndex) { // at least one varargs param
10891089
Object firstVararg = myArgs.get(lastIndex);
10901090
if (myArgs.size() == lastIndex + 1) { // only one vararg param
1091-
if (firstVararg instanceof ArrayReference arrayRef) {
1092-
if (((ArrayType)arrayRef.referenceType()).componentType() instanceof InterfaceType) {
1093-
List<String> argTypes = myMethod.argumentTypeNames();
1094-
if (argTypes.size() > lastIndex
1095-
&& argTypes.get(lastIndex).startsWith(JavaClassNames.JAVA_LANG_OBJECT)) {
1096-
// unwrap array of interfaces for vararg param
1097-
myArgs.remove(lastIndex);
1098-
myArgs.addAll(arrayRef.getValues());
1099-
}
1091+
if (firstVararg instanceof ArrayReference arrayRef
1092+
&& arrayRef.referenceType() instanceof ArrayType arrayType
1093+
&& arrayType.componentType() instanceof InterfaceType) {
1094+
List<String> argTypes = myMethod.argumentTypeNames();
1095+
if (argTypes.size() > lastIndex
1096+
&& argTypes.get(lastIndex).startsWith(JavaClassNames.JAVA_LANG_OBJECT)) {
1097+
// unwrap array of interfaces for vararg param
1098+
myArgs.remove(lastIndex);
1099+
myArgs.addAll(arrayRef.getValues());
11001100
}
11011101
}
11021102
}

java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/engine/JavaStackFrame.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ else if (location != null) {
240240
Set<ObjectReference> exceptions = new HashSet<>();
241241
for (Pair<Breakpoint, Event> pair : DebuggerUtilsEx.getEventDescriptors(debuggerContext.getSuspendContext())) {
242242
Event debugEvent = pair.getSecond();
243-
if (debugEvent instanceof ExceptionEvent) {
244-
ObjectReference exception = ((ExceptionEvent)debugEvent).exception();
243+
if (debugEvent instanceof ExceptionEvent exceptionEvent) {
244+
ObjectReference exception = exceptionEvent.exception();
245245
if (exception != null) {
246246
exceptions.add(exception);
247247
}
@@ -523,8 +523,8 @@ public void visitReferenceExpression(PsiReferenceExpression reference) {
523523
if (var instanceof PsiField field) {
524524
if (myCollectExpressions && !DebuggerUtils.hasSideEffectsOrReferencesMissingVars(reference, myVisibleLocals)) {
525525
/*
526-
if (var instanceof PsiEnumConstant && reference.getQualifier() == null) {
527-
PsiClass enumClass = ((PsiEnumConstant)var).getContainingClass();
526+
if (var instanceof PsiEnumConstant enumConst && reference.getQualifier() == null) {
527+
PsiClass enumClass = enumConst.getContainingClass();
528528
if (enumClass != null) {
529529
PsiExpression expression = JavaPsiFacade.getInstance(var.getProject()).getParserFacade()
530530
.createExpressionFromText(enumClass.getName() + "." + var.getName(), var);

java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/settings/NodeRendererSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ public ListObjectRenderer(NodeRendererSettings rendererSettings) {
564564

565565
@Override
566566
public PsiElement getChildValueExpression(DebuggerTreeNode node, DebuggerContext context) throws EvaluateException {
567-
LOG.assertTrue(node.getDescriptor() instanceof ArrayElementDescriptorImpl);
567+
LOG.assertTrue(node.getDescriptor() instanceof ArrayElementDescriptorImpl arrayElementDescriptor);
568568
try {
569569
return getChildValueExpression(
570570
"this.get(" + ((ArrayElementDescriptorImpl)node.getDescriptor()).getIndex() + ")",

0 commit comments

Comments
 (0)