public static void doTearDown() throws Exception { UsefulTestCase.doPostponedFormatting(ourProject); LookupManager.getInstance(ourProject).hideActiveLookup(); InspectionProfileManager.getInstance().deleteProfile(PROFILE); assertNotNull("Application components damaged", ProjectManager.getInstance()); ApplicationManager.getApplication() .runWriteAction( new Runnable() { public void run() { try { final VirtualFile[] children = ourSourceRoot.getChildren(); for (VirtualFile child : children) { child.delete(this); } } catch (IOException e) { //noinspection CallToPrintStackTrace e.printStackTrace(); } FileDocumentManager manager = FileDocumentManager.getInstance(); if (manager instanceof FileDocumentManagerImpl) { ((FileDocumentManagerImpl) manager).dropAllUnsavedDocuments(); } } }); // final Project[] openProjects = ProjectManagerEx.getInstanceEx().getOpenProjects(); // assertTrue(Arrays.asList(openProjects).contains(ourProject)); assertFalse(PsiManager.getInstance(getProject()).isDisposed()); if (!ourAssertionsInTestDetected) { if (IdeaLogger.ourErrorsOccurred != null) { throw IdeaLogger.ourErrorsOccurred; } // assertTrue("Logger errors occurred. ", IdeaLogger.ourErrorsOccurred == null); } ((PsiDocumentManagerImpl) PsiDocumentManager.getInstance(getProject())) .clearUncommitedDocuments(); ((UndoManagerImpl) UndoManager.getGlobalInstance()).dropHistoryInTests(); ProjectManagerEx.getInstanceEx().setCurrentTestProject(null); ourApplication.setDataProvider(null); ourTestCase = null; ((PsiManagerImpl) ourPsiManager).cleanupForNextTest(); final Editor[] allEditors = EditorFactory.getInstance().getAllEditors(); if (allEditors.length > 0) { for (Editor allEditor : allEditors) { EditorFactory.getInstance().releaseEditor(allEditor); } fail("Unreleased editors: " + allEditors.length); } }
public PsiVFSListener(Project project) { myProject = project; myFileTypeManager = FileTypeManager.getInstance(); myProjectRootManager = ProjectRootManager.getInstance(project); myManager = (PsiManagerImpl) PsiManager.getInstance(project); myFileManager = (FileManagerImpl) myManager.getFileManager(); myConnection = project.getMessageBus().connect(project); StartupManager.getInstance(project) .registerPreStartupActivity( new Runnable() { @Override public void run() { final BulkVirtualFileListenerAdapter adapter = new BulkVirtualFileListenerAdapter(PsiVFSListener.this); myConnection.subscribe( VirtualFileManager.VFS_CHANGES, new BulkFileListener() { @Override public void before(@NotNull List<? extends VFileEvent> events) { adapter.before(events); } @Override public void after(@NotNull List<? extends VFileEvent> events) { myReportedUnloadedPsiChange = false; adapter.after(events); myReportedUnloadedPsiChange = false; } }); myConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyModuleRootListener()); myConnection.subscribe( FileTypeManager.TOPIC, new FileTypeListener.Adapter() { @Override public void fileTypesChanged(@NotNull FileTypeEvent e) { myFileManager.processFileTypesChanged(); } }); myConnection.subscribe( AppTopics.FILE_DOCUMENT_SYNC, new MyFileDocumentManagerAdapter()); myFileManager.markInitialized(); } }); }
FindInProjectTask( @NotNull final FindModel findModel, @NotNull final Project project, @Nullable final PsiDirectory psiDirectory) { myFindModel = findModel; myProject = project; myPsiDirectory = psiDirectory; myPsiManager = PsiManager.getInstance(project); final String moduleName = findModel.getModuleName(); myModule = moduleName == null ? null : ApplicationManager.getApplication() .runReadAction( new Computable<Module>() { @Override public Module compute() { return ModuleManager.getInstance(project).findModuleByName(moduleName); } }); myFileIndex = myModule == null ? ProjectRootManager.getInstance(project).getFileIndex() : ModuleRootManager.getInstance(myModule).getFileIndex(); final String filter = findModel.getFileFilter(); final Pattern pattern = FindInProjectUtil.createFileMaskRegExp(filter); //noinspection unchecked myFileMask = pattern == null ? Condition.TRUE : new Condition<VirtualFile>() { @Override public boolean value(VirtualFile file) { return file != null && pattern.matcher(file.getName()).matches(); } }; final ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator(); myProgress = progress != null ? progress : new EmptyProgressIndicator(); }
@Nullable public String getInstalledPluginNameByPath(Project project, @NotNull VirtualFile pluginPath) { VirtualFile pluginXml = pluginPath.findChild("plugin.xml"); if (pluginXml == null) return null; PsiFile pluginXmlPsi = PsiManager.getInstance(project).findFile(pluginXml); if (!(pluginXmlPsi instanceof XmlFile)) return null; XmlTag rootTag = ((XmlFile) pluginXmlPsi).getRootTag(); if (rootTag == null || !"plugin".equals(rootTag.getName())) return null; XmlAttribute attrName = rootTag.getAttribute("name"); if (attrName == null) return null; String res = attrName.getValue(); if (res == null) return null; res = res.trim(); if (res.length() == 0) return null; return res; }
/** Shortcut to PsiManager.getInstance(getProject()) */ public static PsiManager getPsiManager() { if (ourPsiManager == null) { ourPsiManager = PsiManager.getInstance(ourProject); } return ourPsiManager; }