mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IG: recognize when catch blocks containing a return statement are identical (IDEA-159182)
This commit is contained in:
+7
-1
@@ -24,6 +24,8 @@ import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.refactoring.extractMethod.InputVariables;
|
||||
import com.intellij.refactoring.util.duplicates.DuplicatesFinder;
|
||||
import com.intellij.refactoring.util.duplicates.Match;
|
||||
import com.intellij.refactoring.util.duplicates.ReturnStatementReturnValue;
|
||||
import com.intellij.refactoring.util.duplicates.ReturnValue;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
@@ -110,7 +112,11 @@ public class TryWithIdenticalCatchesInspection extends BaseInspection {
|
||||
continue;
|
||||
}
|
||||
final Match match = finder.isDuplicate(otherCatchBlock, true);
|
||||
if (match == null || match.getReturnValue() != null) {
|
||||
if (match == null) {
|
||||
continue;
|
||||
}
|
||||
final ReturnValue returnValue = match.getReturnValue();
|
||||
if (returnValue != null && !(returnValue instanceof ReturnStatementReturnValue)) {
|
||||
continue;
|
||||
}
|
||||
final List<PsiElement> parameterValues = match.getParameterValues(parameter);
|
||||
|
||||
+13
@@ -160,4 +160,17 @@ class TryIdenticalCatches {
|
||||
|
||||
void foo() throws IOException {}
|
||||
private static final IOException INSTANCE = new IOException();
|
||||
|
||||
public boolean returning() {
|
||||
try {
|
||||
// work
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
return true;
|
||||
}
|
||||
catch(RuntimeException e) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+13
@@ -163,4 +163,17 @@ class TryIdenticalCatches {
|
||||
|
||||
void foo() throws IOException {}
|
||||
private static final IOException INSTANCE = new IOException();
|
||||
|
||||
public boolean returning() {
|
||||
try {
|
||||
// work
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
return true;
|
||||
}
|
||||
<warning descr="'catch' branch identical to 'NumberFormatException' branch">catch(RuntimeException e)</warning> {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user