mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] remove redundant import when "Remove annotation" quick fix is applied (IDEA-288488)
GitOrigin-RevId: 562cf18eafa636a761c75ae3e9630bdab3eff760
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6f8b8172ac
commit
9c66641799
+10
-1
@@ -9,13 +9,16 @@ import com.intellij.java.analysis.JavaAnalysisBundle;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class RemoveAnnotationQuickFix implements LocalQuickFix {
|
||||
@@ -74,7 +77,13 @@ public class RemoveAnnotationQuickFix implements LocalQuickFix {
|
||||
if (!FileModificationService.getInstance().preparePsiElementsForWrite(physical)) {
|
||||
return;
|
||||
}
|
||||
WriteAction.run(() -> physical.forEach(PsiAnnotation::delete));
|
||||
WriteAction.run(() -> {
|
||||
Set<PsiJavaFile> containingFiles = physical.stream().map(PsiAnnotation::getContainingFile)
|
||||
.filter(PsiJavaFile.class::isInstance).map(PsiJavaFile.class::cast)
|
||||
.collect(Collectors.toSet());
|
||||
physical.forEach(PsiAnnotation::delete);
|
||||
containingFiles.forEach(JavaCodeStyleManager.getInstance(project)::removeRedundantImports);
|
||||
});
|
||||
|
||||
if (qualifiedName != null) {
|
||||
for (PsiModifierListOwner owner : externalOwners) {
|
||||
|
||||
-2
@@ -1,7 +1,5 @@
|
||||
// "Remove annotation" "true"
|
||||
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
class Foo {
|
||||
<caret>int foo(){return 0;}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class RemoveAnnotationWithImportQuickFix {
|
||||
<warning descr="Cannot annotate with both @NotNull and @Nullable">@<caret>NotNull</warning> <warning descr="Cannot annotate with both @Nullable and @NotNull">@Nullable</warning> String s;
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class RemoveAnnotationWithImportQuickFix {
|
||||
@Nullable String s;
|
||||
}
|
||||
-2
@@ -1,5 +1,3 @@
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
interface Foo {
|
||||
long getTime();
|
||||
}
|
||||
|
||||
-2
@@ -1,5 +1,3 @@
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
interface Foo {
|
||||
void getTime(int a);
|
||||
}
|
||||
|
||||
+4
@@ -374,6 +374,10 @@ public class NullableStuffInspectionTest extends LightJavaCodeInsightFixtureTest
|
||||
}
|
||||
}
|
||||
|
||||
public void testRemoveAnnotationWithImportQuickFix() {
|
||||
doTestWithFix("Remove annotation");
|
||||
}
|
||||
|
||||
public void testQuickFixOnTypeArgumentNullable() {
|
||||
DataFlowInspection8Test.setupTypeUseAnnotations("typeUse", myFixture);
|
||||
NullableNotNullManager manager = NullableNotNullManager.getInstance(getProject());
|
||||
|
||||
Reference in New Issue
Block a user