mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-01 02:38:59 +07:00
redundant throws: find throws clauses inside functional expressions (IDEA-135181)
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
package com.intellij.codeInspection.reference;
|
||||
|
||||
import com.intellij.codeInsight.ExceptionUtil;
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
@@ -30,6 +31,9 @@ import com.intellij.util.VisibilityUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class RefJavaUtilImpl extends RefJavaUtil{
|
||||
|
||||
@Override
|
||||
@@ -114,6 +118,29 @@ public class RefJavaUtilImpl extends RefJavaUtil{
|
||||
final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(aClass);
|
||||
if (interfaceMethod != null) {
|
||||
refFrom.addReference(refFrom.getRefManager().getReference(interfaceMethod), interfaceMethod, psiFrom, false, true, null);
|
||||
|
||||
PsiElement body = null;
|
||||
PsiElement topElement = null;
|
||||
if (expression instanceof PsiLambdaExpression) {
|
||||
body = ((PsiLambdaExpression)expression).getBody();
|
||||
topElement = expression;
|
||||
}
|
||||
else {
|
||||
final PsiElement resolve = ((PsiMethodReferenceExpression)expression).resolve();
|
||||
if (resolve instanceof PsiMethod) {
|
||||
body = ((PsiMethod)resolve).getBody();
|
||||
topElement = resolve;
|
||||
}
|
||||
}
|
||||
|
||||
final Collection<PsiClassType> exceptionTypes = body != null ? ExceptionUtil.collectUnhandledExceptions(body, topElement, false)
|
||||
: Collections.<PsiClassType>emptyList();
|
||||
RefElement refResolved = refFrom.getRefManager().getReference(interfaceMethod);
|
||||
if (refResolved instanceof RefMethodImpl) {
|
||||
for (final PsiClassType exceptionType : exceptionTypes) {
|
||||
((RefMethodImpl)refResolved).updateThrowsList(exceptionType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user