mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
local redundant throws should respect exception subclasses when checking inherited method exceptions
This commit is contained in:
+3
-7
@@ -82,22 +82,18 @@ public class RedundantThrowsDeclarationLocalInspection extends AbstractBaseJavaL
|
||||
|
||||
if (candidates.isEmpty()) return null;
|
||||
if (needCheckOverridingMethods) {
|
||||
|
||||
Set<String> thrownExceptionShortNames = candidates.stream().map(refAndType -> refAndType.type.getClassName()).collect(Collectors.toSet());
|
||||
Predicate<PsiMethod> methodContainsThrownExceptions = m -> Arrays.stream(m.getThrowsList().getReferencedTypes())
|
||||
.map(PsiClassType::getClassName)
|
||||
.anyMatch(thrownExceptionShortNames::contains);
|
||||
Predicate<PsiMethod> methodContainsThrownExceptions = m -> m.getThrowsList().getReferencedTypes().length != 0;
|
||||
Stream<PsiMethod> overridingMethods = JavaOverridingMethodUtil.getOverridingMethodsIfCheapEnough(method, null, methodContainsThrownExceptions);
|
||||
if (overridingMethods == null) return null;
|
||||
|
||||
Iterator<PsiMethod> overridingMethodIt = overridingMethods.iterator();
|
||||
while (overridingMethodIt.hasNext()) {
|
||||
PsiMethod m = overridingMethodIt.next();
|
||||
PsiClassType[] overridingMethodThrownException = m.getThrowsList().getReferencedTypes();
|
||||
PsiClassType[] overridingMethodThrownExceptions = m.getThrowsList().getReferencedTypes();
|
||||
|
||||
candidates.removeIf(refAndType -> {
|
||||
PsiClassType type = refAndType.type;
|
||||
return ArrayUtil.contains(type, overridingMethodThrownException);
|
||||
return Arrays.stream(overridingMethodThrownExceptions).anyMatch(type::isAssignableFrom);
|
||||
});
|
||||
|
||||
if (candidates.isEmpty()) return null;
|
||||
|
||||
Reference in New Issue
Block a user