diff --git a/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/JavaMatchingVisitor.java b/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/JavaMatchingVisitor.java index db36986bfe86..1981803174d0 100644 --- a/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/JavaMatchingVisitor.java +++ b/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/JavaMatchingVisitor.java @@ -978,7 +978,8 @@ public class JavaMatchingVisitor extends JavaElementVisitor { final PsiType type1 = new1.getType(); final PsiType type2 = new2.getType(); myMatchingVisitor.setResult(type1 != null && type2 != null && type1.getArrayDimensions() == type2.getArrayDimensions() && - myMatchingVisitor.matchSons(new1.getArgumentList(), new2.getArgumentList())); + myMatchingVisitor.matchSons(new1.getArgumentList(), new2.getArgumentList()) && + myMatchingVisitor.setResult(matchTypeParameters(new1, new2))); } } @@ -1027,27 +1028,22 @@ public class JavaMatchingVisitor extends JavaElementVisitor { } if (!myMatchingVisitor.setResult(myMatchingVisitor.matchSons(mcall.getArgumentList(), mcall2.getArgumentList()))) return; - if (!myMatchingVisitor.setResult(matchTypeParameters(mcallRef1, mcallRef2))) return; + if (!myMatchingVisitor.setResult(matchTypeParameters(mcall, mcall2))) return; if (isTypedVar) { myMatchingVisitor.setResult(myMatchingVisitor.handleTypedElement(patternMethodName, mcallRef2.getReferenceNameElement())); } } - private boolean matchTypeParameters(PsiJavaCodeReferenceElement mcallRef1, PsiJavaCodeReferenceElement mcallRef2) { - final PsiReferenceParameterList patternParameterList = mcallRef1.getParameterList(); - if (patternParameterList == null) { - return true; - } + private boolean matchTypeParameters(PsiCallExpression call1, PsiCallExpression call2) { + final PsiReferenceParameterList patternParameterList = call1.getTypeArgumentList(); final PsiTypeElement[] patternTypeElements = patternParameterList.getTypeParameterElements(); if (patternTypeElements.length == 0) { return true; } - PsiReferenceParameterList matchedParameterList = mcallRef2.getParameterList(); - if (matchedParameterList == null) { - return false; - } - if (matchedParameterList.getFirstChild() == null) { // check inferred type parameters - final JavaResolveResult resolveResult = mcallRef2.advancedResolve(false); + PsiReferenceParameterList matchedParameterList = call2.getTypeArgumentList(); + if (matchedParameterList.getFirstChild() == null && myMatchingVisitor.getMatchContext().getOptions().isLooseMatching()) { + // check inferred type parameters + final JavaResolveResult resolveResult = call2.resolveMethodGenerics(); final PsiMethod targetMethod = (PsiMethod)resolveResult.getElement(); if (targetMethod == null) { return false; @@ -1064,7 +1060,7 @@ public class JavaMatchingVisitor extends JavaElementVisitor { if (type == null) { return false; } - final PsiTypeElement matchedTypeElement = JavaPsiFacade.getElementFactory(mcallRef1.getProject()).createTypeElement(type); + final PsiTypeElement matchedTypeElement = JavaPsiFacade.getElementFactory(call1.getProject()).createTypeElement(type); matchedParameterList.add(matchedTypeElement); } } diff --git a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java index 705fa20a3390..648e9564370b 100644 --- a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java +++ b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java @@ -2700,20 +2700,32 @@ public class StructuralSearchTest extends StructuralSearchTestCase { public void testFindParameterizedMethodCalls() { String source = "interface Foo {" + " T bar();" + - " void bar2(S, T);" + + " void bar2(S s, T t);" + "}" + "class X {" + + " X(T t) {}" + + " X() {}" + " void x(Foo foo) {" + " foo.bar();" + " foo.bar();" + " String s = foo.bar();" + " foo.bar2(1, 2);" + " }" + + " void y(String s) {" + + " new X();" + + " new X();" + + " new X();" + + " new X(s);" + + " }" + "}"; assertEquals("find parameterized method calls 1", 1, findMatchesCount(source, "foo.bar()")); assertEquals("find parameterized method calls 2", 2, findMatchesCount(source, "foo.bar()")); assertEquals("find parameterized method calls 3", 3, findMatchesCount(source, "'_a.<'_b>'_c('_d*)")); assertEquals("find parameterized method calls 4", 4, findMatchesCount(source, "'_a.<'_b+>'_c('_d*)")); + + assertEquals("find parameterized constructor calls 1", 2, findMatchesCount(source, "new X()")); + assertEquals("find parameterized constructor calls 2", 1, findMatchesCount(source, "new X(s)")); + assertEquals("find constructor calls 3", 3, findMatchesCount(source, "new X()")); } public void testFindDiamondTypes() {