java method search: create a single request per method when occurrences for overloads are requested (IDEA-165761)

This commit is contained in:
Dmitry Batkovich
2016-12-21 20:55:05 +03:00
parent f3e6c2591c
commit 69fad35300
5 changed files with 32 additions and 2 deletions

View File

@@ -98,8 +98,10 @@ public class MethodUsagesSearcher extends QueryExecutorBase<PsiReference, Method
SearchScope restrictedByAccessScope = searchScope.intersectWith(accessScope);
short searchContext = UsageSearchContext.IN_CODE | UsageSearchContext.IN_COMMENTS | UsageSearchContext.IN_FOREIGN_LANGUAGES;
collector.searchWord(methodName[0], restrictedByAccessScope, searchContext, true, method,
getTextOccurrenceProcessor(methods, aClass, strictSignatureSearch));
for (PsiMethod m : methods) {
collector.searchWord(methodName[0], restrictedByAccessScope, searchContext, true, m,
getTextOccurrenceProcessor(new PsiMethod[] {m}, aClass, strictSignatureSearch));
}
SimpleAccessorReferenceSearcher.addPropertyAccessUsages(method, restrictedByAccessScope, collector);
return null;

View File

@@ -0,0 +1,5 @@
public class A {
void m(Foo foo) {
foo.bar();
}
}

View File

@@ -0,0 +1,5 @@
public class B {
void m(Foo foo) {
foo.bar(100);
}
}

View File

@@ -0,0 +1,10 @@
public class Foo {
public void bar() {
}
public void bar(int param) {
}
}

View File

@@ -158,6 +158,14 @@ public class CompilerReferencesFindUsagesTest extends DaemonAnalyzerTestCase {
}, 2, "Foo.java", "Bar.java");
}
public void testOverloadedMethods() throws Exception {
configureByFiles(getName(), getName() + "/Foo.java", getName() + "/A.java", getName() + "/B.java");
PsiMethod methodToSearch = findClass("Foo").findMethodsByName("bar", false)[0];
assertSize(2, MethodReferencesSearch.search(methodToSearch, false).findAll());
myCompilerTester.rebuild();
assertSize(2, MethodReferencesSearch.search(methodToSearch, false).findAll());
}
private void doTestRunnableFindUsagesWithExcludesConfiguration(@NotNull Consumer<ExcludesConfiguration> excludesConfigurationPatcher,
int expectedUsagesCount,
String... testFiles) {