mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-18 12:31:26 +07:00
[Java] IDEA-384756 Handle incorrect resolve to parameter and field when detecting optimize imports intention
Space-RevId: 7d5d281c8a8e96e61eeb068b8149a5d98cfc52c1 GitOrigin-RevId: edc24ae68af9ff7e0ca1e1939bb6670672b63dc3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6d7d21e825
commit
5539f3af78
@@ -377,7 +377,7 @@ public final class LocalRefUseInfo {
|
||||
if (resolveResult.getCurrentFileResolveScope() instanceof PsiImportStatementBase importStatement) {
|
||||
registerImportStatement(importStatement);
|
||||
} else if (ref instanceof PsiJavaCodeReferenceElement javaRef &&
|
||||
isMethodCallResolvedToLocalVariable(refElement, javaRef)) {
|
||||
isMethodCallResolvedToVariable(refElement, javaRef)) {
|
||||
for (PsiImportStatementBase potentialImport : IncompleteModelUtil.getPotentialImports(javaRef, false)) {
|
||||
registerImportStatement(potentialImport);
|
||||
}
|
||||
@@ -469,9 +469,13 @@ public final class LocalRefUseInfo {
|
||||
registerConstructorCall(enumConstant);
|
||||
}
|
||||
|
||||
private static boolean isMethodCallResolvedToLocalVariable(@Nullable PsiElement refElement, @NotNull PsiJavaCodeReferenceElement javaRef) {
|
||||
private static boolean isMethodCallResolvedToVariable(@Nullable PsiElement refElement, @NotNull PsiJavaCodeReferenceElement javaRef) {
|
||||
return javaRef.getParent() instanceof PsiMethodCallExpression &&
|
||||
refElement instanceof PsiLocalVariable;
|
||||
(
|
||||
refElement instanceof PsiLocalVariable ||
|
||||
refElement instanceof PsiField ||
|
||||
refElement instanceof PsiParameter
|
||||
);
|
||||
}
|
||||
|
||||
private void registerConstructorCall(@NotNull PsiConstructorCall constructorCall) {
|
||||
|
||||
@@ -271,7 +271,7 @@ public class UnusedImportsVisitor extends JavaElementVisitor {
|
||||
|
||||
myState.builderList.add(builder);
|
||||
|
||||
if (!predefinedImport && !myState.requiresFix/* && importStatement.resolve() != null*/) {
|
||||
if (!predefinedImport && !myState.requiresFix) {
|
||||
myState.requiresFix = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user