Java Code Examples for com.intellij.util.ui.UIUtil#dispatchAllInvocationEvents()
The following examples show how to use
com.intellij.util.ui.UIUtil#dispatchAllInvocationEvents() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CamelProjectComponentTestIT.java From camel-idea-plugin with Apache License 2.0 | 6 votes |
public void testRemoveLibrary() throws IOException { CamelService service = ServiceManager.getService(myProject, CamelService.class); assertEquals(0, service.getLibraries().size()); VirtualFile camelCoreVirtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(createTestArchive("camel-core-2.22.0.jar")); VirtualFile camelSpringVirtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(createTestArchive("camel-spring-2.22.0.jar")); final LibraryTable projectLibraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(myProject); Library springLibrary = addLibraryToModule(camelSpringVirtualFile, projectLibraryTable, "Maven: org.apache.camel:camel-spring:2.22.0-snapshot"); Library coreLibrary = addLibraryToModule(camelCoreVirtualFile, projectLibraryTable, "Maven: org.apache.camel:camel-core:2.22.0-snapshot"); UIUtil.dispatchAllInvocationEvents(); assertEquals(2, service.getLibraries().size()); assertEquals(true, service.isCamelPresent()); ApplicationManager.getApplication().runWriteAction(() -> projectLibraryTable.removeLibrary(springLibrary)); UIUtil.dispatchAllInvocationEvents(); assertEquals(1, service.getLibraries().size()); }
Example 2
Source File: CamelProjectComponentTestIT.java From camel-idea-plugin with Apache License 2.0 | 6 votes |
public void testAddModule() throws IOException { CamelService service = ServiceManager.getService(myProject, CamelService.class); assertEquals(0, service.getLibraries().size()); File camelJar = createTestArchive("camel-core-2.22.0.jar"); VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(camelJar); final LibraryTable projectLibraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(myProject); ApplicationManager.getApplication().runWriteAction(() -> { final Module moduleA = createModule("myNewModel.iml"); Library library = projectLibraryTable.createLibrary("Maven: org.apache.camel:camel-core:2.22.0-snapshot"); final Library.ModifiableModel libraryModifiableModel = library.getModifiableModel(); libraryModifiableModel.addRoot(virtualFile, OrderRootType.CLASSES); libraryModifiableModel.commit(); ModuleRootModificationUtil.addDependency(moduleA, library); }); UIUtil.dispatchAllInvocationEvents(); assertEquals(1, service.getLibraries().size()); }
Example 3
Source File: CamelProjectComponentTestIT.java From camel-idea-plugin with Apache License 2.0 | 6 votes |
public void testAddLegacyPackaging() throws IOException { CamelService service = ServiceManager.getService(myProject, CamelService.class); assertEquals(0, service.getLibraries().size()); VirtualFile camelCoreVirtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(createTestArchive("camel-core-2.22.0.jar")); VirtualFile legacyJarPackagingFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(createTestArchive("legacy-custom-file-0.12.snapshot.jar")); final LibraryTable projectLibraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(myProject); addLibraryToModule(camelCoreVirtualFile, projectLibraryTable, "Maven: org.apache.camel:camel-core:2.22.0-snapshot"); addLibraryToModule(legacyJarPackagingFile, projectLibraryTable, "c:\\test\\libs\\legacy-custom-file-0.12.snapshot.jar"); UIUtil.dispatchAllInvocationEvents(); assertEquals(1, service.getLibraries().size()); assertEquals(true, service.getLibraries().contains("camel-core")); }
Example 4
Source File: UsageViewTest.java From consulo with Apache License 2.0 | 6 votes |
public void testUsageViewDoesNotHoldPsiFilesOrDocuments() throws Exception { PsiFile psiFile = createFile("X.java", "public class X{} //iuggjhfg"); Usage[] usages = new Usage[100]; for (int i = 0; i < usages.length; i++) { usages[i] = createUsage(psiFile,i); } UsageView usageView = UsageViewManager.getInstance(getProject()).createUsageView(UsageTarget.EMPTY_ARRAY, usages, new UsageViewPresentation(), null); Disposer.register(getTestRootDisposable(), usageView); ((EncodingManagerImpl)EncodingManager.getInstance()).clearDocumentQueue(); FileDocumentManager.getInstance().saveAllDocuments(); UIUtil.dispatchAllInvocationEvents(); LeakHunter.checkLeak(usageView, PsiFileImpl.class); LeakHunter.checkLeak(usageView, Document.class); }
Example 5
Source File: CamelProjectComponentTestIT.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
public void testAddLibrary() throws IOException { CamelService service = ServiceManager.getService(myProject, CamelService.class); assertEquals(0, service.getLibraries().size()); File camelJar = createTestArchive("camel-core-2.22.0.jar"); VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(camelJar); final LibraryTable projectLibraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(myProject); addLibraryToModule(virtualFile, projectLibraryTable, "Maven: org.apache.camel:camel-core:2.22.0-snapshot"); UIUtil.dispatchAllInvocationEvents(); assertEquals(1, service.getLibraries().size()); assertEquals(true, service.isCamelPresent()); }
Example 6
Source File: PlatformTestCase.java From consulo with Apache License 2.0 | 5 votes |
@Override protected void setUp() throws Exception { super.setUp(); if (ourTestCase != null) { String message = "Previous test " + ourTestCase + " hasn't called tearDown(). Probably overridden without super call."; ourTestCase = null; fail(message); } LOGGER.info(getClass().getName() + ".setUp()"); initApplication(); myEditorListenerTracker = new EditorListenerTracker(); myThreadTracker = new ThreadTracker(); setUpProject(); storeSettings(); ourTestCase = this; if (myProject != null) { ProjectManagerEx.getInstanceEx().openTestProject(myProject); CodeStyleSettingsManager.getInstance(myProject).setTemporarySettings(new CodeStyleSettings()); InjectedLanguageManagerImpl.pushInjectors(getProject()); } DocumentCommitThread.getInstance().clearQueue(); UIUtil.dispatchAllInvocationEvents(); }
Example 7
Source File: UsageNodeTreeBuilderTest.java From consulo with Apache License 2.0 | 5 votes |
private GroupNode buildUsageTree(int[] indices, UsageGroupingRule[] rules) { Usage[] usages = new Usage[indices.length]; for (int i = 0; i < usages.length; i++) { usages[i] = createUsage(indices[i]); } UsageViewPresentation presentation = new UsageViewPresentation(); presentation.setUsagesString("searching for mock usages"); ExtensionPoint<UsageGroupingRuleProvider> point = Application.get().getExtensionPoint(UsageGroupingRuleProvider.EP_NAME); UsageGroupingRuleProvider provider = new UsageGroupingRuleProvider() { @Nonnull @Override public UsageGroupingRule[] getActiveRules(Project project) { return rules; } @Nonnull @Override public AnAction[] createGroupingActions(UsageView view) { return AnAction.EMPTY_ARRAY; } }; // point.registerExtension(provider); try { UsageViewImpl usageView = new UsageViewImpl(getProject(), presentation, UsageTarget.EMPTY_ARRAY, null); Disposer.register(getTestRootDisposable(), usageView); for (Usage usage : usages) { usageView.appendUsage(usage); } UIUtil.dispatchAllInvocationEvents(); return usageView.getRoot(); } finally { // point.unregisterExtension(provider); } }
Example 8
Source File: VirtualFilePointerTest.java From consulo with Apache License 2.0 | 5 votes |
private static void refreshVFS() { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { VirtualFileManager.getInstance().syncRefresh(); } }); UIUtil.dispatchAllInvocationEvents(); }
Example 9
Source File: EditorBasedStatusBarPopup.java From consulo with Apache License 2.0 | 5 votes |
@TestOnly public void updateInTests(boolean immediately) { update(); update.drainRequestsInTest(); UIUtil.dispatchAllInvocationEvents(); if (immediately) { // for widgets with background activities, the first flush() adds handlers to be called update.drainRequestsInTest(); UIUtil.dispatchAllInvocationEvents(); } }
Example 10
Source File: LaterInvocator.java From consulo with Apache License 2.0 | 5 votes |
@TestOnly public static void dispatchPendingFlushes() { if (!isDispatchThread()) throw new IllegalStateException("Must call from EDT"); Semaphore semaphore = new Semaphore(); semaphore.down(); invokeLaterWithCallback(semaphore::up, ModalityState.any(), Conditions.FALSE, null); while (!semaphore.isUp()) { UIUtil.dispatchAllInvocationEvents(); } }
Example 11
Source File: FileBasedIndexImpl.java From consulo with Apache License 2.0 | 5 votes |
@TestOnly public void waitForVfsEventsExecuted(long timeout, @Nonnull TimeUnit unit) throws Exception { ApplicationManager.getApplication().assertIsDispatchThread(); BoundedTaskExecutor executor = (BoundedTaskExecutor)getChangedFilesCollector().myVfsEventsExecutor; long deadline = System.nanoTime() + unit.toNanos(timeout); while (System.nanoTime() < deadline) { try { executor.waitAllTasksExecuted(100, TimeUnit.MILLISECONDS); return; } catch (TimeoutException e) { UIUtil.dispatchAllInvocationEvents(); } } }
Example 12
Source File: OSSPantsIdeaPluginGoalIntegrationTest.java From intellij-pants-plugin with Apache License 2.0 | 4 votes |
public void testPantsIdeaPluginGoal() throws Throwable { assertEmpty(ModuleManager.getInstance(myProject).getModules()); /** * Check whether Pants supports `idea-plugin` goal. */ final GeneralCommandLine commandLinePantsGoals = PantsUtil.defaultCommandLine(getProjectFolder().getPath()); commandLinePantsGoals.addParameter("goals"); final ProcessOutput cmdOutputGoals = PantsUtil.getCmdOutput(commandLinePantsGoals.withWorkDirectory(getProjectFolder()), null); assertEquals(commandLinePantsGoals.toString() + " failed", 0, cmdOutputGoals.getExitCode()); if (!cmdOutputGoals.getStdout().contains("idea-plugin")) { return; } /** * Generate idea project via `idea-plugin` goal. */ final GeneralCommandLine commandLine = PantsUtil.defaultCommandLine(getProjectFolder().getPath()); final File outputFile = FileUtil.createTempFile("project_dir_location", ".out"); String targetToImport = "testprojects/tests/java/org/pantsbuild/testproject/matcher:matcher"; commandLine.addParameters( "idea-plugin", "--no-open", "--output-file=" + outputFile.getPath(), targetToImport ); final ProcessOutput cmdOutput = PantsUtil.getCmdOutput(commandLine.withWorkDirectory(getProjectFolder()), null); assertEquals(commandLine.toString() + " failed", 0, cmdOutput.getExitCode()); // `outputFile` contains the path to the project directory. String projectDir = FileUtil.loadFile(outputFile); // Search the directory for ipr file. File[] files = new File(projectDir).listFiles(); assertNotNull(files); Optional<String> iprFile = Arrays.stream(files) .map(File::getPath) .filter(s -> s.endsWith(ProjectFileType.DOT_DEFAULT_EXTENSION)) .findFirst(); assertTrue(iprFile.isPresent()); myProject = ProjectUtil.openProject(iprFile.get(), myProject, false); // Invoke post startup activities. UIUtil.dispatchAllInvocationEvents(); /** * Under unit test mode, {@link com.intellij.ide.impl.ProjectUtil#openProject} will force open a project in a new window, * so Project SDK has to be reset. In practice, this is not needed. */ ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { final JavaSdk javaSdk = JavaSdk.getInstance(); ProjectRootManager.getInstance(myProject).setProjectSdk(ProjectJdkTable.getInstance().getSdksOfType(javaSdk).iterator().next()); } }); assertSuccessfulTest(PantsUtil.getCanonicalModuleName(targetToImport), "org.pantsbuild.testproject.matcher.MatcherTest"); assertTrue(ProjectUtil.closeAndDispose(myProject)); }
Example 13
Source File: LeakHunter.java From consulo with Apache License 2.0 | 4 votes |
@TestOnly public static <T> void checkLeak(@Nonnull Object root, @Nonnull Class<T> suspectClass, @javax.annotation.Nullable final Processor<T> isReallyLeak) throws AssertionError { if (SwingUtilities.isEventDispatchThread()) { UIUtil.dispatchAllInvocationEvents(); } else { UIUtil.pump(); } PersistentEnumerator.clearCacheForTests(); toVisit.clear(); visited.clear(); toVisit.push(new BackLink(root.getClass(), root, null,null)); try { walkObjects(suspectClass, new Processor<BackLink>() { @Override public boolean process(BackLink backLink) { UserDataHolder leaked = (UserDataHolder)backLink.value; if (((UserDataHolderBase)leaked).replace(REPORTED_LEAKED,null,Boolean.TRUE) && (isReallyLeak == null || isReallyLeak.process((T)leaked))) { String place = leaked instanceof Project ? PlatformTestCase.getCreationPlace((Project)leaked) : ""; System.out.println("Leaked object found:" + leaked + "; hash: "+System.identityHashCode(leaked) + "; place: "+ place); while (backLink != null) { String valueStr; try { valueStr = String.valueOf(backLink.value); } catch (Throwable e) { valueStr = "("+e.getMessage()+" while computing .toString())"; } System.out.println("-->"+backLink.field+"; Value: "+ valueStr +"; "+backLink.aClass); backLink = backLink.backLink; } System.out.println(";-----"); throw new AssertionError(); } return true; } }); } finally { visited.clear(); ((THashSet)visited).compact(); toVisit.clear(); toVisit.trimToSize(); } }
Example 14
Source File: StructureViewComponent.java From consulo with Apache License 2.0 | 4 votes |
@SuppressWarnings("TestOnlyProblems") private void waitForRebuildAndExpand() { wait(rebuildAndUpdate()); UIUtil.dispatchAllInvocationEvents(); wait(TreeUtil.promiseExpand(getTree(), getMinimumExpandDepth(myTreeModel))); }
Example 15
Source File: CamelProjectComponentTestIT.java From camel-idea-plugin with Apache License 2.0 | 3 votes |
public void testAddLibWithoutMavenPackaging() throws IOException { CamelService service = ServiceManager.getService(myProject, CamelService.class); assertEquals(0, service.getLibraries().size()); VirtualFile camelCoreVirtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(createTestArchive("camel-core-2.22.0.jar")); final LibraryTable projectLibraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(myProject); addLibraryToModule(camelCoreVirtualFile, projectLibraryTable, "org.apache.camel:camel-core:2.22.0-snapshot"); UIUtil.dispatchAllInvocationEvents(); assertEquals(1, service.getLibraries().size()); assertEquals(true, service.getLibraries().contains("camel-core")); }