private void buildOutputItemsList( final String outputDir, final Module module, VirtualFile from, final FileTypeManager typeManager, final VirtualFile sourceRoot, final String packagePrefix, final List<File> filesToRefresh, final Map<String, Collection<TranslatingCompiler.OutputItem>> results) throws CacheCorruptedException { final Ref<CacheCorruptedException> exRef = new Ref<CacheCorruptedException>(null); final ModuleFileIndex fileIndex = ModuleRootManager.getInstance(module).getFileIndex(); final GlobalSearchScope srcRootScope = GlobalSearchScope.moduleScope(module) .intersectWith(GlobalSearchScopes.directoryScope(myProject, sourceRoot, true)); final Collection<FileType> registeredInputTypes = CompilerManager.getInstance(myProject).getRegisteredInputTypes(myTranslatingCompiler); final ContentIterator contentIterator = new ContentIterator() { public boolean processFile(final VirtualFile child) { try { if (child.isValid()) { if (!child.isDirectory() && registeredInputTypes.contains(child.getFileType())) { updateOutputItemsList( outputDir, child, sourceRoot, packagePrefix, filesToRefresh, results, srcRootScope); } } return true; } catch (CacheCorruptedException e) { exRef.set(e); return false; } } }; if (fileIndex.isInContent(from)) { // use file index for iteration to handle 'inner modules' and excludes properly fileIndex.iterateContentUnderDirectory(from, contentIterator); } else { // seems to be a root for generated sources VfsUtilCore.visitChildrenRecursively( from, new VirtualFileVisitor() { @Override public boolean visitFile(@NotNull VirtualFile file) { if (!file.isDirectory()) { contentIterator.processFile(file); } return true; } }); } final CacheCorruptedException exc = exRef.get(); if (exc != null) { throw exc; } }
// currently only one level here.. public boolean contains(@NotNull String name, @NotNull final VirtualFile vFile) { final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); final Set<Boolean> find = new HashSet<Boolean>(); final ContentIterator contentIterator = new ContentIterator() { public boolean processFile(VirtualFile fileOrDir) { if (fileOrDir != null && fileOrDir.getPath().equals(vFile.getPath())) { find.add(Boolean.TRUE); } return true; } }; Collection<TreeItem<Pair<AbstractUrl, String>>> urls = getFavoritesListRootUrls(name); for (TreeItem<Pair<AbstractUrl, String>> pair : urls) { AbstractUrl abstractUrl = pair.getData().getFirst(); if (abstractUrl == null) { continue; } final Object[] path = abstractUrl.createPath(myProject); if (path == null || path.length < 1 || path[0] == null) { continue; } Object element = path[path.length - 1]; if (element instanceof SmartPsiElementPointer) { final VirtualFile virtualFile = PsiUtilBase.getVirtualFile(((SmartPsiElementPointer) element).getElement()); if (virtualFile == null) continue; if (vFile.getPath().equals(virtualFile.getPath())) { return true; } if (!virtualFile.isDirectory()) { continue; } projectFileIndex.iterateContentUnderDirectory(virtualFile, contentIterator); } if (element instanceof PsiElement) { final VirtualFile virtualFile = PsiUtilBase.getVirtualFile((PsiElement) element); if (virtualFile == null) continue; if (vFile.getPath().equals(virtualFile.getPath())) { return true; } if (!virtualFile.isDirectory()) { continue; } projectFileIndex.iterateContentUnderDirectory(virtualFile, contentIterator); } if (element instanceof Module) { ModuleRootManager.getInstance((Module) element) .getFileIndex() .iterateContent(contentIterator); } if (element instanceof LibraryGroupElement) { final boolean inLibrary = ModuleRootManager.getInstance(((LibraryGroupElement) element).getModule()) .getFileIndex() .isInContent(vFile) && projectFileIndex.isInLibraryClasses(vFile); if (inLibrary) { return true; } } if (element instanceof NamedLibraryElement) { NamedLibraryElement namedLibraryElement = (NamedLibraryElement) element; final VirtualFile[] files = namedLibraryElement.getOrderEntry().getRootFiles(OrderRootType.CLASSES); if (files != null && ArrayUtil.find(files, vFile) > -1) { return true; } } if (element instanceof ModuleGroup) { ModuleGroup group = (ModuleGroup) element; final Collection<Module> modules = group.modulesInGroup(myProject, true); for (Module module : modules) { ModuleRootManager.getInstance(module).getFileIndex().iterateContent(contentIterator); } } for (FavoriteNodeProvider provider : Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, myProject)) { if (provider.elementContainsFile(element, vFile)) { return true; } } if (!find.isEmpty()) { return true; } } return false; }