do not add exceptions to containing methods when element is selected inside lambda

This commit is contained in:
Anna Kozlova
2014-11-18 18:36:39 +01:00
parent f52ceb369b
commit 498e067158
3 changed files with 13 additions and 3 deletions
@@ -72,10 +72,10 @@ public class AddRuntimeExceptionToThrowsAction implements IntentionAction {
PsiClassType exception = getRuntimeExceptionAtCaret(editor, file);
if (exception == null) return false;
PsiMethod method = PsiTreeUtil.getParentOfType(elementAtCaret(editor, file), PsiMethod.class);
if (method == null || !method.getThrowsList().isPhysical()) return false;
PsiElement element = PsiTreeUtil.getParentOfType(elementAtCaret(editor, file), PsiMethod.class, PsiLambdaExpression.class);
if (element == null || element instanceof PsiLambdaExpression || !((PsiMethod)element).getThrowsList().isPhysical()) return false;
return !isMethodThrows(method, exception);
return !isMethodThrows((PsiMethod)element, exception);
}
private static PsiClassType getRuntimeExceptionAtCaret(Editor editor, PsiFile file) {
@@ -0,0 +1,9 @@
// "Add Runtime Exception(s) to Method Signature" "false"
class a {
int f() {
Runnable r = () -> {
throw new RuntimeException()<caret>;
}
}
}
@@ -1,5 +1,6 @@
package com.intellij.codeInsight.daemon.quickFix;
import com.intellij.codeInsight.daemon.LightIntentionActionTestCase;
import com.intellij.pom.java.LanguageLevel;
/**
* @author ven