really search for private class inheritors outside the current file (IDEA-167877)

This commit is contained in:
peter
2017-02-14 18:19:33 +01:00
parent 2b674bf37e
commit 4f45117015
5 changed files with 29 additions and 6 deletions
@@ -282,6 +282,18 @@ public class GotoImplementationHandlerTest extends JavaCodeInsightFixtureTestCas
assertEquals(1, impls.length);
}
public void testPrivateClassInheritors() {
PsiFile file = myFixture.addFileToProject("Foo.java",
"class C {\n" +
" private static class Pr<caret>ivate {}\n" +
" public static class Public extends Private {}" +
"}");
myFixture.addClass("class Inheritor extends C.Public {}");
myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
assertSize(2, getTargets(file));
}
private PsiElement[] getTargets(PsiFile file) {
GotoTargetHandler.GotoData gotoData = CodeInsightTestUtil.gotoImplementation(myFixture.getEditor(), file);
assertNotNull(gotoData);
@@ -17,9 +17,11 @@
package com.intellij.psi.search.searches;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.util.Computable;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.search.PsiSearchHelper;
import com.intellij.psi.search.SearchScope;
import com.intellij.util.Processor;
@@ -98,11 +100,10 @@ public class DefinitionsScopedSearch extends ExtensibleQueryFactory<PsiElement,
@NotNull
public SearchScope getScope() {
return ApplicationManager.getApplication().runReadAction(new Computable<SearchScope>() {
@Override
public SearchScope compute() {
return myScope.intersectWith(PsiSearchHelper.SERVICE.getInstance(myElement.getProject()).getUseScope(myElement));
}
return ReadAction.compute(() -> {
PsiFile file = myElement.getContainingFile();
return myScope.intersectWith(
PsiSearchHelper.SERVICE.getInstance(myElement.getProject()).getUseScope(file != null ? file : myElement));
});
}
}
@@ -88,6 +88,10 @@ public abstract class TargetElementEvaluatorEx2 implements TargetElementEvaluato
return true;
}
/**
* @return a scope where element's implementations (Goto/Show Implementations) should be searched.
* If null is returned, default (module-with-dependents) scope will be used.
*/
@Nullable
public SearchScope getSearchScope(Editor editor, @NotNull PsiElement element) {
return null;
@@ -457,7 +457,10 @@ public class TargetElementUtil extends TargetElementUtilBase {
public SearchScope getSearchScope(Editor editor, @NotNull PsiElement element) {
TargetElementEvaluatorEx2 evaluator = getElementEvaluatorsEx2(element.getLanguage());
SearchScope result = evaluator != null ? evaluator.getSearchScope(editor, element) : null;
return result != null ? result : PsiSearchHelper.SERVICE.getInstance(element.getProject()).getUseScope(element);
if (result != null) return result;
PsiFile file = element.getContainingFile();
return PsiSearchHelper.SERVICE.getInstance(element.getProject()).getUseScope(file != null ? file : element);
}
protected final LanguageExtension<TargetElementEvaluator> targetElementEvaluator =
@@ -96,6 +96,9 @@ public abstract class TargetElementUtilBase {
public abstract boolean acceptImplementationForReference(@Nullable PsiReference reference, @Nullable PsiElement element);
/**
* @return a scope where element's implementations (Goto/Show Implementations) should be searched
*/
@NotNull
public abstract SearchScope getSearchScope(Editor editor, @NotNull PsiElement element);
}