mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
[java-intentions] RemoveAllUnusedImportsFix: support static imports; tests
Fixes IDEA-353352 "Remove unused imports" does nothing for static imports GitOrigin-RevId: ae20983342012414568af9ca68db67994832443c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
209c9d230e
commit
2909ce4932
@@ -9,7 +9,7 @@ import com.intellij.modcommand.ModCommand;
|
||||
import com.intellij.modcommand.ModCommandAction;
|
||||
import com.intellij.modcommand.Presentation;
|
||||
import com.intellij.psi.PsiImportList;
|
||||
import com.intellij.psi.PsiImportStatement;
|
||||
import com.intellij.psi.PsiImportStatementBase;
|
||||
import com.intellij.psi.PsiJavaFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -36,12 +36,12 @@ public class RemoveAllUnusedImportsFix implements ModCommandAction {
|
||||
if (!(context.file() instanceof PsiJavaFile javaFile)) return ModCommand.nop();
|
||||
PsiImportList importList = javaFile.getImportList();
|
||||
if (importList == null) return ModCommand.nop();
|
||||
List<PsiImportStatement> importStatements = new ArrayList<>();
|
||||
List<PsiImportStatementBase> importStatements = new ArrayList<>();
|
||||
DaemonCodeAnalyzerEx.processHighlights(javaFile.getViewProvider().getDocument(), context.project(), HighlightSeverity.INFORMATION,
|
||||
importList.getTextRange().getStartOffset(),
|
||||
importList.getTextRange().getEndOffset(), info -> {
|
||||
if (UnusedImportsVisitor.isUnusedImportHighlightInfo(javaFile, info)) {
|
||||
PsiImportStatement importStatement = PsiTreeUtil.findElementOfClassAtOffset(javaFile, info.getActualStartOffset(), PsiImportStatement.class, false);
|
||||
PsiImportStatementBase importStatement = PsiTreeUtil.findElementOfClassAtOffset(javaFile, info.getActualStartOffset(), PsiImportStatementBase.class, false);
|
||||
if (importStatement != null) {
|
||||
importStatements.add(importStatement);
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class RemoveAllUnusedImportsFix implements ModCommandAction {
|
||||
|
||||
if (importStatements.isEmpty()) return ModCommand.nop();
|
||||
return ModCommand.psiUpdate(context, updater -> {
|
||||
for (PsiImportStatement statement : ContainerUtil.map(importStatements, updater::getWritable)) {
|
||||
for (PsiImportStatementBase statement : ContainerUtil.map(importStatements, updater::getWritable)) {
|
||||
new CommentTracker().deleteAndRestoreComments(statement);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Remove unused imports" "true-preview"
|
||||
import java.util.Set;
|
||||
|
||||
class Main {
|
||||
void test(Set<String> set) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Remove unused imports" "true-preview"
|
||||
import java.util.Set;
|
||||
|
||||
class Main {
|
||||
void test(Set<String> set) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Remove unused imports" "true-preview"
|
||||
import java.util.Set;
|
||||
|
||||
class Main {
|
||||
void test(Set<String> set) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Remove unused imports" "true-preview"
|
||||
import java.util.L<caret>ist;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.lang.Integer;
|
||||
|
||||
class Main {
|
||||
void test(Set<String> set) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Remove unused imports" "true-preview"
|
||||
import java.util.L<caret>ist;
|
||||
import java.util.Set;
|
||||
|
||||
class Main {
|
||||
void test(Set<String> set) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Remove unused imports" "true-preview"
|
||||
import static java.util.Arrays.<caret>asList;
|
||||
import java.util.Set;
|
||||
|
||||
class Main {
|
||||
void test(Set<String> set) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInspection.unusedImport.UnusedImportInspection;
|
||||
|
||||
public final class RemoveAllUnusedImportsTest extends LightQuickFixParameterizedTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
enableInspectionTool(new UnusedImportInspection());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/highlight/remove_imports";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user