public void testRemoveSourceRoot() { final VirtualFile root = ModuleRootManager.getInstance(myModule).getContentRoots()[0]; PsiTodoSearchHelper.SERVICE .getInstance(myProject) .findFilesWithTodoItems(); // to initialize caches new WriteCommandAction.Simple(getProject()) { @Override protected void run() throws Throwable { VirtualFile newFile = createChildData(root, "New.java"); setFileText(newFile, "class A{ Exception e;} //todo"); } }.execute().throwException(); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); PsiTodoSearchHelper.SERVICE.getInstance(myProject).findFilesWithTodoItems(); // to update caches VirtualFile[] sourceRoots = ModuleRootManager.getInstance(myModule).getSourceRoots(); LOG.assertTrue(sourceRoots.length == 1); PsiTestUtil.removeSourceRoot(myModule, sourceRoots[0]); PsiClass exceptionClass = myJavaFacade.findClass("java.lang.Exception", GlobalSearchScope.allScope(getProject())); assertNotNull(exceptionClass); // currently it actually finds usages by FQN due to Java PSI enabled for out-of-source java // files // so the following check is disabled // checkUsages(exceptionClass, new String[]{}); checkTodos(new String[] {"2.java", "New.java"}); }
public void testSCR6066() throws Exception { ProjectRootManagerEx rootManager = (ProjectRootManagerEx) ProjectRootManager.getInstance(myProject); final VirtualFile root = rootManager.getContentRoots()[0]; PsiTodoSearchHelper.SERVICE .getInstance(myProject) .findFilesWithTodoItems(); // to initialize caches new WriteCommandAction.Simple(getProject()) { @Override protected void run() throws Throwable { VirtualFile newFile = createChildData(root, "New.java"); setFileText(newFile, "class A{ Exception e;} //todo"); } }.execute().throwException(); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); PsiTodoSearchHelper.SERVICE.getInstance(myProject).findFilesWithTodoItems(); // to update caches PsiTestUtil.addExcludedRoot(myModule, root); PsiClass exceptionClass = myJavaFacade.findClass("java.lang.Exception", GlobalSearchScope.allScope(getProject())); assertNotNull(exceptionClass); checkUsages(exceptionClass, new String[] {}); checkTodos(new String[] {}); }
public void testAddSourceRoot() throws Exception { File dir = createTempDirectory(); final VirtualFile root = LocalFileSystem.getInstance() .refreshAndFindFileByPath(dir.getCanonicalPath().replace(File.separatorChar, '/')); new WriteCommandAction.Simple(getProject()) { @Override protected void run() throws Throwable { PsiTestUtil.addContentRoot(myModule, root); VirtualFile newFile = createChildData(root, "New.java"); setFileText(newFile, "class A{ Exception e;} //todo"); } }.execute().throwException(); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); PsiTodoSearchHelper.SERVICE .getInstance(myProject) .findFilesWithTodoItems(); // to initialize caches PsiTestUtil.addSourceRoot(myModule, root); PsiClass exceptionClass = myJavaFacade.findClass("java.lang.Exception", GlobalSearchScope.allScope(getProject())); assertNotNull(exceptionClass); checkUsages(exceptionClass, new String[] {"1.java", "2.java", "New.java"}); checkTodos(new String[] {"2.java", "New.java"}); }
private void checkTodos(@NonNls String[] expectedFiles) { PsiTodoSearchHelper helper = PsiTodoSearchHelper.SERVICE.getInstance(myProject); PsiFile[] files = helper.findFilesWithTodoItems(); assertEquals(expectedFiles.length, files.length); Arrays.sort(files, (file1, file2) -> file1.getName().compareTo(file2.getName())); Arrays.sort(expectedFiles); for (int i = 0; i < expectedFiles.length; i++) { String name = expectedFiles[i]; PsiFile file = files[i]; assertEquals(name, file.getName()); } }