From e47615be334bc2d938f9db0c2c8fab21be7a7b97 Mon Sep 17 00:00:00 2001 From: Valentin Fondaratov Date: Mon, 12 Dec 2016 13:05:06 +0300 Subject: [PATCH] RUBY-18889: test for goto class --- .../fixtures/CodeInsightTestFixture.java | 10 ++++++ .../impl/CodeInsightTestFixtureImpl.java | 31 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java index 09fd7ab95be9..96c5e9961a61 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java @@ -577,5 +577,15 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { @NotNull List completeBasicAllCarets(@Nullable Character charToTypeAfterCompletion); + /** + * Get elements found by the Goto Class action called with the given pattern + * @param pattern a pattern to search for elements + * @param searchEverywhere indicates whether "include non-project classes" checkbox is selected + * @param contextForSorting a PsiElement used for "proximity sorting" of the results. The sorting will be disabled if null given. + * @return a list of the results (likely PsiElements) found for the given pattern + */ + @NotNull + List getGotoClassResults(@NotNull String pattern, boolean searchEverywhere, @Nullable PsiElement contextForSorting); + void saveText(@NotNull VirtualFile file, @NotNull String text); } \ No newline at end of file diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index e2ae5bd83548..5f687e698ddb 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -50,11 +50,15 @@ import com.intellij.ide.startup.StartupManagerEx; import com.intellij.ide.startup.impl.StartupManagerImpl; import com.intellij.ide.structureView.StructureViewBuilder; import com.intellij.ide.structureView.newStructureView.StructureViewComponent; +import com.intellij.ide.util.gotoByName.ChooseByNameBase; +import com.intellij.ide.util.gotoByName.ChooseByNamePopup; +import com.intellij.ide.util.gotoByName.GotoClassModel2; import com.intellij.injected.editor.DocumentWindow; import com.intellij.injected.editor.EditorWindow; import com.intellij.internal.DumpLookupElementWeights; import com.intellij.lang.LanguageStructureViewBuilder; import com.intellij.lang.annotation.HighlightSeverity; +import com.intellij.mock.MockProgressIndicator; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.actionSystem.ex.ActionManagerEx; @@ -150,6 +154,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig private String myTestDataPath; private boolean myEmptyLookup; private VirtualFileFilter myVirtualFileFilter = new FileTreeAccessFilter(); + private ChooseByNameBase myChooseByNamePopup; private boolean myAllowDirt; private boolean myCaresAboutInjection = true; @@ -1180,6 +1185,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig myEditor = null; myFile = null; myPsiManager = null; + myChooseByNamePopup = null; try { myProjectFixture.tearDown(); @@ -1728,6 +1734,31 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig return (LookupImpl)LookupManager.getActiveLookup(myEditor); } + @NotNull + @Override + public List getGotoClassResults(@NotNull String pattern, boolean searchEverywhere, @Nullable PsiElement contextForSorting) { + final ChooseByNameBase chooseByNamePopup = getMockChooseByNamePopup(contextForSorting); + final ArrayList results = new ArrayList<>(); + chooseByNamePopup.getProvider().filterElements(chooseByNamePopup, + chooseByNamePopup.transformPattern(pattern), + searchEverywhere, + new MockProgressIndicator(), + new CommonProcessors.CollectProcessor<>(results)); + return results; + } + + @NotNull + private ChooseByNameBase getMockChooseByNamePopup(@Nullable PsiElement contextForSorting) { + final Project project = getProject(); + if (contextForSorting != null) { + return ChooseByNamePopup.createPopup(project, new GotoClassModel2(project), contextForSorting); + } + if (myChooseByNamePopup == null) { + myChooseByNamePopup = ChooseByNamePopup.createPopup(project, new GotoClassModel2(project), (PsiElement)null); + } + return myChooseByNamePopup; + } + protected void bringRealEditorBack() { PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); if (myEditor instanceof EditorWindow) {