redundant throws: find throws clauses inside functional expressions (IDEA-135181)

This commit is contained in:
Anna Kozlova
2015-01-14 13:20:34 +01:00
parent 73239255ec
commit a1b44a53ac
4 changed files with 74 additions and 0 deletions

View File

@@ -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);
}
}
}
}
}