@NotNull protected Collection<HighlightInfo> checkHighlighting( @NotNull final ExpectedHighlightingData data) { data.init(); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); // to load text ApplicationManager.getApplication() .runWriteAction( new Runnable() { @Override public void run() { TreeUtil.clearCaches((TreeElement) myFile.getNode()); } }); // to initialize caches if (!DumbService.isDumb(getProject())) { CacheManager.SERVICE .getInstance(myProject) .getFilesWithWord( "XXX", UsageSearchContext.IN_COMMENTS, GlobalSearchScope.allScope(myProject), true); } final JavaPsiFacadeEx facade = getJavaFacade(); if (facade != null) { facade.setAssertOnFileLoadingFilter( myFileTreeAccessFilter, myTestRootDisposable); // check repository work } try { Collection<HighlightInfo> infos = doHighlighting(); String text = myEditor.getDocument().getText(); data.checkLineMarkers( DaemonCodeAnalyzerImpl.getLineMarkers(getDocument(getFile()), getProject()), text); data.checkResult(infos, text); return infos; } finally { if (facade != null) { facade.setAssertOnFileLoadingFilter(VirtualFileFilter.NONE, myTestRootDisposable); } } }
public void testExternalFileModificationWhileProjectClosed() throws Exception { VirtualFile root = ProjectRootManager.getInstance(myProject).getContentRoots()[0]; PsiClass objectClass = myJavaFacade.findClass( CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(getProject())); assertNotNull(objectClass); checkUsages(objectClass, new String[] {}); FileBasedIndex.getInstance() .getContainingFiles( TodoIndex.NAME, new TodoIndexEntry("todo", true), GlobalSearchScope.allScope(getProject())); final String projectLocation = myProject.getPresentableUrl(); assert projectLocation != null : myProject; PlatformTestUtil.saveProject(myProject); final VirtualFile content = ModuleRootManager.getInstance(getModule()).getContentRoots()[0]; Project project = myProject; ProjectUtil.closeAndDispose(project); InjectedLanguageManagerImpl.checkInjectorsAreDisposed(project); assertTrue("Project was not disposed", myProject.isDisposed()); myModule = null; final File file = new File(root.getPath(), "1.java"); assertTrue(file.exists()); FileUtil.writeToFile(file, "class A{ Object o;}".getBytes(CharsetToolkit.UTF8_CHARSET)); root.refresh(false, true); LocalFileSystem.getInstance().refresh(false); myProject = ProjectManager.getInstance().loadAndOpenProject(projectLocation); InjectedLanguageManagerImpl.pushInjectors(getProject()); setUpModule(); setUpJdk(); ProjectManagerEx.getInstanceEx().openTestProject(myProject); UIUtil.dispatchAllInvocationEvents(); // startup activities runStartupActivities(); PsiTestUtil.addSourceContentToRoots(getModule(), content); assertNotNull(myProject); myPsiManager = (PsiManagerImpl) PsiManager.getInstance(myProject); myJavaFacade = JavaPsiFacadeEx.getInstanceEx(myProject); objectClass = myJavaFacade.findClass( CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(getProject())); assertNotNull(objectClass); checkUsages(objectClass, new String[] {"1.java"}); }