extract method: stop at lambda body during exceptions collecting (IDEA-144938)

This commit is contained in:
Anna Kozlova
2015-09-09 17:18:45 +03:00
parent 43890f1144
commit db53e6d20b
4 changed files with 51 additions and 0 deletions

View File

@@ -92,6 +92,9 @@ public class ExceptionUtil {
// filter class declaration in code
return Collections.emptyList();
}
else if (element instanceof PsiLambdaExpression) {
return Collections.emptyList();
}
else if (element instanceof PsiMethodCallExpression) {
PsiReferenceExpression methodRef = ((PsiMethodCallExpression)element).getMethodExpression();
JavaResolveResult result = methodRef.advancedResolve(false);

View File

@@ -0,0 +1,20 @@
import java.io.IOException;
class Issue {
public static void main(String[] args) {
<selection>swallow(() -> {
throw new IOException();
});</selection>
}
private static void swallow(ThrowsUnchecked r) {
try {
r.doAction();
} catch (IOException ignored) {
}
}
}
interface ThrowsUnchecked {
void doAction() throws IOException;
}

View File

@@ -0,0 +1,24 @@
import java.io.IOException;
class Issue {
public static void main(String[] args) {
newMethod();
}
private static void newMethod() {
swallow(() -> {
throw new IOException();
});
}
private static void swallow(ThrowsUnchecked r) {
try {
r.doAction();
} catch (IOException ignored) {
}
}
}
interface ThrowsUnchecked {
void doAction() throws IOException;
}

View File

@@ -711,6 +711,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
doTest();
}
public void testSkipThrowsDeclaredInLambda() throws Exception {
doTest();
}
public void testChangedReturnType() throws Exception {
doTestReturnTypeChanged(PsiType.getJavaLangObject(getPsiManager(), GlobalSearchScope.allScope(getProject())));
}