mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
[cdr] Improved catch analysis relaxed for general exceptions
This commit is contained in:
@@ -466,11 +466,14 @@ public class ExceptionUtil {
|
||||
return errorClass != null && InheritanceUtil.isInheritorOrSelf(aClass, errorClass, true);
|
||||
}
|
||||
|
||||
public static boolean isUncheckedExceptionOrSuperclass(@NotNull PsiClassType type) {
|
||||
String canonicalText = type.getCanonicalText();
|
||||
return "java.lang.Throwable".equals(canonicalText) ||
|
||||
"java.lang.Exception".equals(canonicalText) ||
|
||||
isUncheckedException(type);
|
||||
public static boolean isUncheckedExceptionOrSuperclass(@NotNull final PsiClassType type) {
|
||||
return isGeneralExceptionType(type) || isUncheckedException(type);
|
||||
}
|
||||
|
||||
public static boolean isGeneralExceptionType(@NotNull final PsiType type) {
|
||||
final String canonicalText = type.getCanonicalText();
|
||||
return CommonClassNames.JAVA_LANG_THROWABLE.equals(canonicalText) ||
|
||||
CommonClassNames.JAVA_LANG_EXCEPTION.equals(canonicalText);
|
||||
}
|
||||
|
||||
public static boolean isHandled(PsiClassType exceptionType, PsiElement throwPlace) {
|
||||
|
||||
@@ -981,7 +981,8 @@ public class HighlightUtil {
|
||||
|
||||
|
||||
@Nullable
|
||||
static Collection<HighlightInfo> checkWithImprovedCatchAnalysis(final PsiParameter parameter, Collection<PsiClassType> thrownTypes) {
|
||||
static Collection<HighlightInfo> checkWithImprovedCatchAnalysis(final PsiParameter parameter,
|
||||
final Collection<PsiClassType> thrownInTryStatement) {
|
||||
final PsiElement scope = parameter.getDeclarationScope();
|
||||
if (!(scope instanceof PsiCatchSection)) return null;
|
||||
|
||||
@@ -990,7 +991,7 @@ public class HighlightUtil {
|
||||
final int idx = ArrayUtil.find(allCatchSections, catchSection);
|
||||
if (idx <= 0) return null;
|
||||
|
||||
thrownTypes = Sets.newHashSet(thrownTypes);
|
||||
final Collection<PsiClassType> thrownTypes = Sets.newHashSet(thrownInTryStatement);
|
||||
thrownTypes.add(PsiType.getJavaLangError(parameter.getManager(), parameter.getResolveScope()));
|
||||
thrownTypes.add(PsiType.getJavaLangRuntimeException(parameter.getManager(), parameter.getResolveScope()));
|
||||
final Collection<HighlightInfo> result = Lists.newArrayList();
|
||||
@@ -998,8 +999,10 @@ public class HighlightUtil {
|
||||
final List<PsiTypeElement> parameterTypeElements = PsiUtil.getParameterTypeElements(parameter);
|
||||
final boolean isMultiCatch = parameterTypeElements.size() > 1;
|
||||
for (PsiTypeElement catchTypeElement : parameterTypeElements) {
|
||||
// collect exceptions which are caught by this type
|
||||
final PsiType catchType = catchTypeElement.getType();
|
||||
if (ExceptionUtil.isGeneralExceptionType(catchType)) continue;
|
||||
|
||||
// collect exceptions which are caught by this type
|
||||
Collection<PsiClassType> caught = ContainerUtil.findAll(thrownTypes, new Condition<PsiClassType>() {
|
||||
@Override public boolean value(PsiClassType type) { return catchType.isAssignableFrom(type); }
|
||||
});
|
||||
|
||||
@@ -104,7 +104,7 @@ class C {
|
||||
void m15() {
|
||||
try { f(); }
|
||||
catch (RuntimeException e) { }
|
||||
<warning descr="Unreachable section: exception 'java.lang.RuntimeException' has already been caught">catch (Exception e) { }</warning>
|
||||
catch (Exception e) { }
|
||||
}
|
||||
|
||||
void m16() {
|
||||
@@ -116,34 +116,34 @@ class C {
|
||||
void m17() {
|
||||
try { h(); }
|
||||
catch (RuntimeException e) { }
|
||||
<warning descr="Unreachable section: exception 'java.lang.RuntimeException' has already been caught">catch (Exception e) { }</warning>
|
||||
catch (Exception e) { }
|
||||
}
|
||||
|
||||
void m18() {
|
||||
try { f(); }
|
||||
catch (RuntimeException e) { }
|
||||
catch (<error descr="Exception 'C.E' is never thrown in the corresponding try block">E e</error>) { }
|
||||
<warning descr="Unreachable section: exception 'java.lang.RuntimeException' has already been caught">catch (Exception e) { }</warning>
|
||||
catch (Exception e) { }
|
||||
}
|
||||
|
||||
void m19() {
|
||||
try { g(); }
|
||||
catch (RuntimeException e) { }
|
||||
catch (E e) { }
|
||||
<warning descr="Unreachable section: exceptions 'C.E, java.lang.RuntimeException' have already been caught">catch (Exception e) { }</warning>
|
||||
catch (Exception e) { }
|
||||
}
|
||||
|
||||
void m20() {
|
||||
try { h(); }
|
||||
catch (RuntimeException e) { }
|
||||
catch (<error descr="Exception 'C.E' is never thrown in the corresponding try block">E e</error>) { }
|
||||
<warning descr="Unreachable section: exception 'java.lang.RuntimeException' has already been caught">catch (Exception e) { }</warning>
|
||||
catch (Exception e) { }
|
||||
}
|
||||
|
||||
void m21() {
|
||||
try { f(); }
|
||||
catch (RuntimeException e) { }
|
||||
<warning descr="Unreachable section: exception 'java.lang.RuntimeException' has already been caught">catch (Exception e) { }</warning>
|
||||
catch (Exception e) { }
|
||||
}
|
||||
|
||||
void m22() {
|
||||
@@ -155,14 +155,14 @@ class C {
|
||||
void m23() {
|
||||
try { h(); }
|
||||
catch (RuntimeException e) { }
|
||||
<warning descr="Unreachable section: exception 'java.lang.RuntimeException' has already been caught">catch (Exception e) { }</warning>
|
||||
catch (Exception e) { }
|
||||
}
|
||||
|
||||
void m24() {
|
||||
try { f(); }
|
||||
catch (RuntimeException e) { }
|
||||
catch (Error e) { }
|
||||
<warning descr="Unreachable section: exceptions 'java.lang.RuntimeException, java.lang.Error' have already been caught">catch (Throwable t) { }</warning>
|
||||
catch (Throwable t) { }
|
||||
}
|
||||
|
||||
void m25() {
|
||||
@@ -176,7 +176,7 @@ class C {
|
||||
try { h(); }
|
||||
catch (RuntimeException e) { }
|
||||
catch (Error e) { }
|
||||
<warning descr="Unreachable section: exceptions 'java.lang.RuntimeException, java.lang.Error' have already been caught">catch (Throwable t) { }</warning>
|
||||
catch (Throwable t) { }
|
||||
}
|
||||
|
||||
void m27() {
|
||||
@@ -184,7 +184,7 @@ class C {
|
||||
catch (RuntimeException e) { }
|
||||
catch (Error e) { }
|
||||
catch (<error descr="Exception 'C.E' is never thrown in the corresponding try block">E e</error>) { }
|
||||
<warning descr="Unreachable section: exceptions 'java.lang.RuntimeException, java.lang.Error' have already been caught">catch (Throwable t) { }</warning>
|
||||
catch (Throwable t) { }
|
||||
}
|
||||
|
||||
void m28() {
|
||||
@@ -192,7 +192,7 @@ class C {
|
||||
catch (RuntimeException e) { }
|
||||
catch (Error e) { }
|
||||
catch (E e) { }
|
||||
<warning descr="Unreachable section: exceptions 'C.E, java.lang.RuntimeException, java.lang.Error' have already been caught">catch (Throwable t) { }</warning>
|
||||
catch (Throwable t) { }
|
||||
}
|
||||
|
||||
void m29() {
|
||||
@@ -200,14 +200,14 @@ class C {
|
||||
catch (RuntimeException e) { }
|
||||
catch (Error e) { }
|
||||
catch (<error descr="Exception 'C.E' is never thrown in the corresponding try block">E e</error>) { }
|
||||
<warning descr="Unreachable section: exceptions 'java.lang.RuntimeException, java.lang.Error' have already been caught">catch (Throwable t) { }</warning>
|
||||
catch (Throwable t) { }
|
||||
}
|
||||
|
||||
void m30() {
|
||||
try { f(); }
|
||||
catch (RuntimeException e) { }
|
||||
catch (Error e) { }
|
||||
<warning descr="Unreachable section: exceptions 'java.lang.RuntimeException, java.lang.Error' have already been caught">catch (Throwable t) { }</warning>
|
||||
catch (Throwable t) { }
|
||||
}
|
||||
|
||||
void m31() {
|
||||
@@ -221,7 +221,7 @@ class C {
|
||||
try { h(); }
|
||||
catch (RuntimeException e) { }
|
||||
catch (Error e) { }
|
||||
<warning descr="Unreachable section: exceptions 'java.lang.RuntimeException, java.lang.Error' have already been caught">catch (Throwable t) { }</warning>
|
||||
catch (Throwable t) { }
|
||||
}
|
||||
|
||||
void m33() {
|
||||
|
||||
Reference in New Issue
Block a user