mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix duplicate throws quickfix; add test
This commit is contained in:
+18
@@ -65,6 +65,24 @@ public abstract class MethodThrowsFix extends LocalQuickFixOnPsiElement {
|
||||
}
|
||||
}
|
||||
|
||||
public static class RemoveFirst extends MethodThrowsFix {
|
||||
public RemoveFirst(@NotNull PsiMethod method, @NotNull PsiClassType exceptionType, boolean showClassName) {
|
||||
super(method, exceptionType, showClassName);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTextMessageKey() {
|
||||
return "fix.throws.list.remove.exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
|
||||
PsiJavaCodeReferenceElement[] referenceElements = ((PsiMethod) startElement).getThrowsList().getReferenceElements();
|
||||
Arrays.stream(referenceElements).filter(referenceElement -> referenceElement.getCanonicalText().equals(myThrowsCanonicalText)).findFirst().ifPresent(PsiElement::delete);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Remove extends MethodThrowsFix {
|
||||
public Remove(@NotNull PsiMethod method, @NotNull PsiClassType exceptionType, boolean showClassName) {
|
||||
super(method, exceptionType, showClassName);
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ public class DuplicateThrowsInspection extends AbstractBaseJavaLocalInspectionTo
|
||||
}
|
||||
}
|
||||
if (problem != null) {
|
||||
holder.registerProblem(ref, problem, ProblemHighlightType.LIKE_UNUSED_SYMBOL, new MethodThrowsFix.Remove(method, type, false));
|
||||
holder.registerProblem(ref, problem, ProblemHighlightType.LIKE_UNUSED_SYMBOL, new MethodThrowsFix.RemoveFirst(method, type, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Remove 'IOException' from 'execute' throws list" "true"
|
||||
import java.io.*;
|
||||
|
||||
class X {
|
||||
|
||||
void execute() throws XXX, YYY, IOException {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Remove 'IOException' from 'execute' throws list" "true"
|
||||
import java.io.*;
|
||||
|
||||
class X {
|
||||
|
||||
void execute() throws IOException {
|
||||
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Remove 'IOException' from 'execute' throws list" "true"
|
||||
import java.io.*;
|
||||
|
||||
class X {
|
||||
|
||||
void execute() throws XXX, IOE<caret>xception, YYY, IOException {
|
||||
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Remove 'IOException' from 'execute' throws list" "false"
|
||||
import java.io.*;
|
||||
|
||||
class X {
|
||||
|
||||
void execute() throws XXX, IOException, YYY, IOEx<caret>ception {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Remove 'IOException' from 'execute' throws list" "true"
|
||||
import java.io.*;
|
||||
|
||||
class X {
|
||||
|
||||
void execute() throws IOE<caret>xception, IOException {
|
||||
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.java.codeInspection;
|
||||
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.duplicateThrows.DuplicateThrowsInspection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DuplicateThrowsInspectionFixTest extends LightQuickFixParameterizedTestCase {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LocalInspectionTool[] configureLocalInspectionTools() {
|
||||
return new LocalInspectionTool[]{new DuplicateThrowsInspection()};
|
||||
}
|
||||
|
||||
public void test() { doAllTests(); }
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/inspection/duplicateThrows/quickFix";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user