SSR: fix lambda body matching (IDEA-214637)

GitOrigin-RevId: bb33b4c14daf50ae13361b196d2befe70ec2f2fb
This commit is contained in:
Bas Leijdekkers
2019-05-25 14:39:12 +02:00
committed by intellij-monorepo-bot
parent 3173d2abee
commit 208ea67385
2 changed files with 39 additions and 1 deletions

View File

@@ -370,7 +370,16 @@ public class JavaMatchingVisitor extends JavaElementVisitor {
if (!myMatchingVisitor.setResult(
parameterList1.isEmpty() || myMatchingVisitor.matchSons(parameterList1, other.getParameterList()))) return;
final PsiElement body1 = getElementToMatch(expression.getBody());
myMatchingVisitor.setResult(body1 == null || myMatchingVisitor.matchSequentially(body1, getElementToMatch(other.getBody())));
if (body1 == null) {
return;
}
final PsiElement body2 = getElementToMatch(other.getBody());
if (body1 instanceof PsiExpression && body2 instanceof PsiStatement) {
myMatchingVisitor.setResult(myMatchingVisitor.matchSequentially(body1.getParent(), body2));
}
else {
myMatchingVisitor.setResult(myMatchingVisitor.matchSequentially(body1, body2));
}
}
private static PsiElement getElementToMatch(PsiElement element) {

View File

@@ -2390,6 +2390,35 @@ public class StructuralSearchTest extends StructuralSearchTestCase {
"}";
String pattern8 = "String '_x;";
assertEquals("avoid IncorrectOperationException", 0, findMatchesCount(source3, pattern8));
String source4 = "class Main2 {\n" +
" public static void main(String[] args) {\n" +
" //need to match this\n" +
" JSTestUtils.testES6(\"myProject\", () -> {\n" +
" doTest1();\n" +
" doTest2();\n" +
" });\n" +
" }\n" +
"\n" +
" private static void doTest1() {\n" +
" }\n" +
"\n" +
" private static void doTest2() {\n" +
" }\n" +
"\n" +
" static class JSTestUtils {\n" +
" private JSTestUtils() {\n" +
" }\n" +
"\n" +
" static void testES6(Object project, Runnable runnable) {\n" +
" runnable.run();\n" +
" }\n" +
" }\n" +
"}";
String pattern9 = "JSTestUtils.testES6('_expression, () -> {\n" +
" '_statements*;\n" +
"})";
assertEquals("match lambda body correctly", 1, findMatchesCount(source4, pattern9));
}
public void testFindDefaultMethods() {