Remove GeneralizeCatchFix as more general alternative exists

This commit is contained in:
Roman.Ivanov
2019-04-03 12:37:11 +07:00
parent 6d37214f4d
commit 0f8d589a14
12 changed files with 0 additions and 250 deletions
@@ -153,9 +153,6 @@ public abstract class QuickFixFactory {
@NotNull
public abstract IntentionAction createAddExceptionToExistingCatch(@NotNull PsiElement element);
@NotNull
public abstract IntentionAction createGeneralizeCatchFix(@NotNull PsiElement element, @NotNull PsiClassType type);
@NotNull
public abstract IntentionAction createChangeToAppendFix(@NotNull IElementType sign,
@NotNull PsiType type,
@@ -192,9 +192,6 @@ public class HighlightFixUtil {
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createAddExceptionFromFieldInitializerToConstructorThrowsFix(element));
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createSurroundWithTryCatchFix(element));
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createAddExceptionToExistingCatch(element));
if (unhandled.size() == 1) {
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createGeneralizeCatchFix(element, unhandled.get(0)));
}
}
static void registerStaticProblemQuickFixAction(@NotNull PsiElement refElement, HighlightInfo errorResult, @NotNull PsiJavaCodeReferenceElement place) {
@@ -1,99 +0,0 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
public class GeneralizeCatchFix implements IntentionAction {
private final PsiElement myElement;
private final PsiClassType myUnhandledException;
private PsiTryStatement myTryStatement;
private PsiParameter myCatchParameter;
public GeneralizeCatchFix(@NotNull PsiElement element, @NotNull PsiClassType unhandledException) {
myElement = element;
myUnhandledException = unhandledException;
}
@Override
@NotNull
public String getText() {
return QuickFixBundle.message("generalize.catch.text",
JavaHighlightUtil.formatType(myCatchParameter == null ? null : myCatchParameter.getType()),
JavaHighlightUtil.formatType(myUnhandledException));
}
@Override
@NotNull
public String getFamilyName() {
return QuickFixBundle.message("generalize.catch.family");
}
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (!(myElement.isValid()
&& myUnhandledException.isValid()
&& BaseIntentionAction.canModify(myElement))) return false;
// find enclosing try
PsiElement element = myElement;
while (element != null) {
if (PsiUtil.isTryBlock(element) || element instanceof PsiResourceList) {
myTryStatement = (PsiTryStatement)element.getParent();
break;
}
if (element instanceof PsiMethod || element instanceof PsiFunctionalExpression || (element instanceof PsiClass && !(element instanceof PsiAnonymousClass))) break;
element = element.getParent();
}
if (myTryStatement == null) return false;
// check we can generalize at least one catch
PsiParameter[] catchBlockParameters = myTryStatement.getCatchBlockParameters();
for (PsiParameter catchBlockParameter : catchBlockParameters) {
PsiType type = catchBlockParameter.getType();
if (myUnhandledException.isAssignableFrom(type)) {
myCatchParameter = catchBlockParameter;
break;
}
}
return myCatchParameter != null;
}
@NotNull
@Override
public PsiElement getElementToMakeWritable(@NotNull PsiFile file) {
return myElement;
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
PsiElementFactory factory = JavaPsiFacade.getElementFactory(myElement.getProject());
PsiTypeElement type = factory.createTypeElement(myUnhandledException);
myCatchParameter.getTypeElement().replace(type);
}
@Override
public boolean startInWriteAction() {
return true;
}
}
@@ -230,12 +230,6 @@ public class QuickFixFactoryImpl extends QuickFixFactory {
return new AddExceptionToExistingCatchFix(element);
}
@NotNull
@Override
public IntentionAction createGeneralizeCatchFix(@NotNull PsiElement element, @NotNull PsiClassType type) {
return new GeneralizeCatchFix(element, type);
}
@NotNull
@Override
public IntentionAction createChangeToAppendFix(@NotNull IElementType sign,
@@ -1,16 +0,0 @@
// "Generalize catch for 'java.io.FileNotFoundException' to 'java.io.IOException'" "true"
import java.io.*;
public class c1 {
void f() {
FileInputStream fis = null;
try {
fis = new FileInputStream("");
DataInputStream dis = new DataInputStream(fis);
dis.<caret>readInt();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@@ -1,17 +0,0 @@
// "Generalize catch for 'C.E1' to 'C.E'" "true"
class C {
static class E extends Exception { }
static class E1 extends E { }
static class MyResource implements AutoCloseable {
public MyResource() throws E1 { }
public void close() throws E { }
}
void f() {
try (MyResource r = new MyResource()) {
} catch (E e) {
e.printStackTrace();
}
}
}
@@ -1,16 +0,0 @@
// "Generalize catch for 'java.io.FileNotFoundException' to 'java.io.IOException'" "true"
import java.io.*;
public class c1 {
void f() {
FileInputStream fis = null;
try {
fis = new FileInputStream("");
DataInputStream dis = new DataInputStream(fis);
dis.<caret>readInt();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
@@ -1,16 +0,0 @@
// "Generalize catch for 'java.io.FileNotFoundException' to 'java.lang.IllegalAccessException'" "false"
import java.io.*;
public class c1 {
void f() {
FileInputStream fis = null;
try {
fis = new FileInputStream("");
DataInputStream dis = new DataInputStream(fis);
<caret>throw new IllegalAccessException();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
@@ -1,17 +0,0 @@
// "Generalize catch for 'C.E1' to 'C.E'" "true"
class C {
static class E extends Exception { }
static class E1 extends E { }
static class MyResource implements AutoCloseable {
public MyResource() throws E1 { }
public void close() throws E { }
}
void f() {
try (<caret>MyResource r = new MyResource()) {
} catch (E1 e) {
e.printStackTrace();
}
}
}
@@ -1,16 +0,0 @@
// "Generalize catch for 'java.lang.Exception' to 'java.lang.Exception'" "false"
import java.util.function.Supplier;
class C {
static Object get() throws Exception {
return null;
}
void method() {
try {
Supplier<Object> lambda1 = () -> C.ge<caret>t();
} catch( Exception e) {
throw new RuntimeException(e);
}
}
}
@@ -1,16 +0,0 @@
// "Generalize catch for 'java.lang.Exception' to 'java.lang.Exception'" "false"
import java.util.function.Supplier;
class C {
static Object get() throws Exception {
return null;
}
void method() {
try {
Supplier<Object> lambda1 = C::g<caret>et;
} catch( Exception e) {
throw new RuntimeException(e);
}
}
}
@@ -1,25 +0,0 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.java.codeInsight.daemon.quickFix;
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
public class GeneralizeCatchTest extends LightQuickFixParameterizedTestCase {
@Override
protected String getBasePath() {
return "/codeInsight/daemonCodeAnalyzer/quickFix/generalizeCatch";
}
}