mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SSR: match lambda's and method references on functional interface type (IDEA-203929)
This commit is contained in:
+6
-2
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.structuralsearch.impl.matcher.predicates;
|
||||
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
@@ -53,7 +53,11 @@ public class ExprTypePredicate extends MatchPredicate {
|
||||
}
|
||||
|
||||
protected PsiType evalType(PsiExpression match, MatchContext context) {
|
||||
if (match instanceof PsiReferenceExpression) {
|
||||
if (match instanceof PsiFunctionalExpression) {
|
||||
final PsiFunctionalExpression functionalExpression = (PsiFunctionalExpression)match;
|
||||
return functionalExpression.getFunctionalInterfaceType();
|
||||
}
|
||||
else if (match instanceof PsiReferenceExpression) {
|
||||
final PsiElement parent = match.getParent();
|
||||
if (parent instanceof PsiMethodCallExpression) {
|
||||
return ((PsiMethodCallExpression)parent).getType();
|
||||
|
||||
+7
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.structuralsearch;
|
||||
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
@@ -2329,6 +2329,9 @@ public class StructuralSearchTest extends StructuralSearchTestCase {
|
||||
String pattern6 = "('_Parameter+) -> System.out.println()";
|
||||
assertEquals("should find lambdas with at least one parameter and matching body", 0, findMatchesCount(source, pattern6));
|
||||
|
||||
String typePattern = "'_X:[exprtype( Runnable )]";
|
||||
assertEquals("should find Runnable lambda's", 2, findMatchesCount(source, typePattern));
|
||||
|
||||
String source2 = "import java.util.function.Function;\n" +
|
||||
"public class Test {\n" +
|
||||
" public static void main(String[] args) {\n" +
|
||||
@@ -2398,6 +2401,9 @@ public class StructuralSearchTest extends StructuralSearchTestCase {
|
||||
|
||||
String pattern4 = "@AA A::new";
|
||||
assertEquals("should find annotated method references", 1, findMatchesCount(source, pattern4));
|
||||
|
||||
String pattern5 = "'_X:[exprtype( Runnable )]";
|
||||
assertEquals("should find Runnable method references", 4, findMatchesCount(source, pattern5));
|
||||
}
|
||||
|
||||
public void testNoUnexpectedException() {
|
||||
|
||||
Reference in New Issue
Block a user