mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 19:02:13 +07:00
(no message)
This commit is contained in:
@@ -5,6 +5,7 @@ import com.intellij.psi.controlFlow.*;
|
||||
import com.intellij.psi.jsp.JspFile;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import gnu.trove.THashSet;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -172,7 +173,7 @@ public class ExceptionUtil {
|
||||
final PsiClass aClass = constructor.getContainingClass();
|
||||
final PsiClass superClass = aClass == null ? null : aClass.getSuperClass();
|
||||
final PsiMethod[] superConstructors = superClass == null ? PsiMethod.EMPTY_ARRAY : superClass.getConstructors();
|
||||
Collection<PsiClassType> unhandled = new HashSet<PsiClassType>();
|
||||
Set<PsiClassType> unhandled = new HashSet<PsiClassType>();
|
||||
for (int i = 0; i < superConstructors.length; i++) {
|
||||
PsiMethod superConstructor = superConstructors[i];
|
||||
if (!superConstructor.hasModifierProperty(PsiModifier.PRIVATE) &&
|
||||
@@ -180,8 +181,7 @@ public class ExceptionUtil {
|
||||
final PsiClassType[] exceptionTypes = superConstructor.getThrowsList().getReferencedTypes();
|
||||
for (int j = 0; j < exceptionTypes.length; j++) {
|
||||
PsiClassType exceptionType = exceptionTypes[j];
|
||||
if (!isUncheckedException(exceptionType) &&
|
||||
!isHandled(element, exceptionType, topElement)) {
|
||||
if (!isUncheckedException(exceptionType) && !isHandled(element, exceptionType, topElement)) {
|
||||
unhandled.add(exceptionType);
|
||||
}
|
||||
}
|
||||
@@ -189,6 +189,23 @@ public class ExceptionUtil {
|
||||
}
|
||||
}
|
||||
|
||||
// plus all exceptions thrown in instance class initializers
|
||||
if (aClass != null) {
|
||||
final PsiClassInitializer[] initializers = aClass.getInitializers();
|
||||
final Set<PsiClassType> thrownByInitializer = new THashSet<PsiClassType>();
|
||||
for (int i = 0; i < initializers.length; i++) {
|
||||
PsiClassInitializer initializer = initializers[i];
|
||||
if (initializer.hasModifierProperty(PsiModifier.STATIC)) continue;
|
||||
thrownByInitializer.clear();
|
||||
collectUnhandledExceptions(initializer.getBody(), initializer, thrownByInitializer);
|
||||
for (Iterator<PsiClassType> iterator = thrownByInitializer.iterator(); iterator.hasNext();) {
|
||||
PsiClassType thrown = iterator.next();
|
||||
if (!isHandled(constructor.getBody(), thrown, topElement)) {
|
||||
unhandled.add(thrown);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
unhandledExceptions = unhandled.toArray(new PsiClassType[unhandled.size()]);
|
||||
}
|
||||
|
||||
@@ -333,7 +350,9 @@ public class ExceptionUtil {
|
||||
if (aClass == null) return false;
|
||||
PsiClass runtimeExceptionClass = aClass.getManager().findClass("java.lang.RuntimeException", searchScope);
|
||||
if (runtimeExceptionClass != null &&
|
||||
InheritanceUtil.isInheritorOrSelf(aClass, runtimeExceptionClass, true)) return true;
|
||||
InheritanceUtil.isInheritorOrSelf(aClass, runtimeExceptionClass, true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
PsiClass errorClass = aClass.getManager().findClass("java.lang.Error", searchScope);
|
||||
if (errorClass != null && InheritanceUtil.isInheritorOrSelf(aClass, errorClass, true)) return true;
|
||||
|
||||
@@ -290,6 +290,9 @@ public class HighlightMethodUtil {
|
||||
|
||||
//@top
|
||||
static HighlightInfo checkExceptionsNeverThrown(PsiJavaCodeReferenceElement referenceElement) {
|
||||
if (!DaemonCodeAnalyzerSettings.getInstance().getInspectionProfile().isToolEnabled(HighlightDisplayKey.UNUSED_THROWS_DECL)) {
|
||||
return null;
|
||||
}
|
||||
if (!(referenceElement.getParent() instanceof PsiReferenceList)) return null;
|
||||
final PsiReferenceList referenceList = (PsiReferenceList)referenceElement.getParent();
|
||||
if (!(referenceList.getParent() instanceof PsiMethod)) return null;
|
||||
@@ -301,9 +304,6 @@ public class HighlightMethodUtil {
|
||||
PsiManager manager = referenceElement.getManager();
|
||||
final PsiClassType exceptionType = manager.getElementFactory().createType(referenceElement);
|
||||
if (ExceptionUtil.isUncheckedExceptionOrSuperclass(exceptionType)) return null;
|
||||
if (!DaemonCodeAnalyzerSettings.getInstance().getInspectionProfile().isToolEnabled(HighlightDisplayKey.UNUSED_THROWS_DECL)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final PsiCodeBlock body = method.getBody();
|
||||
if (body == null) return null;
|
||||
|
||||
Reference in New Issue
Block a user