Search in sources :

Example 11 with ContentIterator

use of com.intellij.openapi.roots.ContentIterator in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoIdFilter method createIdFilter.

private static IdFilter createIdFilter(@NotNull Project project, @NotNull Key<CachedValue<IdFilter>> cacheKey, @NotNull Condition<VirtualFile> filterCondition) {
    return CachedValuesManager.getManager(project).getCachedValue(project, cacheKey, () -> {
        BitSet bitSet = new BitSet();
        ContentIterator iterator = fileOrDir -> {
            if (filterCondition.value(fileOrDir)) {
                addToBitSet(bitSet, fileOrDir);
            }
            ProgressManager.checkCanceled();
            return true;
        };
        FileBasedIndex.getInstance().iterateIndexableFiles(iterator, project, null);
        return CachedValueProvider.Result.create(new GoIdFilter(bitSet), ProjectRootManager.getInstance(project), VirtualFileManager.VFS_STRUCTURE_MODIFICATIONS);
    }, false);
}
Also used : ProgressManager(com.intellij.openapi.progress.ProgressManager) GoTestFinder(com.goide.runconfig.testing.GoTestFinder) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentIterator(com.intellij.openapi.roots.ContentIterator) Key(com.intellij.openapi.util.Key) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) IdFilter(com.intellij.util.indexing.IdFilter) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) CachedValuesManager(com.intellij.psi.util.CachedValuesManager) CachedValueProvider(com.intellij.psi.util.CachedValueProvider) Nullable(org.jetbrains.annotations.Nullable) CachedValue(com.intellij.psi.util.CachedValue) Project(com.intellij.openapi.project.Project) BitSet(java.util.BitSet) Logger(com.intellij.openapi.diagnostic.Logger) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) NotNull(org.jetbrains.annotations.NotNull) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) Condition(com.intellij.openapi.util.Condition) ContentIterator(com.intellij.openapi.roots.ContentIterator) BitSet(java.util.BitSet)

Example 12 with ContentIterator

use of com.intellij.openapi.roots.ContentIterator in project intellij-community by JetBrains.

the class IdFilter method buildProjectIdFilter.

@NotNull
private static IdFilter buildProjectIdFilter(Project project, boolean includeNonProjectItems) {
    long started = System.currentTimeMillis();
    final BitSet idSet = new BitSet();
    ContentIterator iterator = new ContentIterator() {

        @Override
        public boolean processFile(VirtualFile fileOrDir) {
            int id = ((VirtualFileWithId) fileOrDir).getId();
            // workaround for encountering invalid files, see EA-49915, EA-50599
            if (id < 0)
                id = -id;
            idSet.set(id);
            ProgressManager.checkCanceled();
            return true;
        }
    };
    if (!includeNonProjectItems) {
        ProjectRootManager.getInstance(project).getFileIndex().iterateContent(iterator);
    } else {
        FileBasedIndex.getInstance().iterateIndexableFiles(iterator, project, null);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Done filter " + (System.currentTimeMillis() - started) + ":" + idSet.size());
    }
    return new IdFilter() {

        @Override
        public boolean containsFileId(int id) {
            return id >= 0 && idSet.get(id);
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentIterator(com.intellij.openapi.roots.ContentIterator) BitSet(java.util.BitSet) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with ContentIterator

use of com.intellij.openapi.roots.ContentIterator in project intellij-community by JetBrains.

the class PackageChooserDialog method createTreeModel.

private void createTreeModel() {
    final PsiManager psiManager = PsiManager.getInstance(myProject);
    final FileIndex fileIndex = myModule != null ? ModuleRootManager.getInstance(myModule).getFileIndex() : ProjectRootManager.getInstance(myProject).getFileIndex();
    fileIndex.iterateContent(new ContentIterator() {

        public boolean processFile(VirtualFile fileOrDir) {
            if (fileOrDir.isDirectory() && fileIndex.isUnderSourceRootOfType(fileOrDir, JavaModuleSourceRootTypes.SOURCES)) {
                final PsiDirectory psiDirectory = psiManager.findDirectory(fileOrDir);
                LOG.assertTrue(psiDirectory != null);
                PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory);
                if (aPackage != null) {
                    addPackage(aPackage);
                }
            }
            return true;
        }
    });
    TreeUtil.sort(myModel, (o1, o2) -> {
        DefaultMutableTreeNode n1 = (DefaultMutableTreeNode) o1;
        DefaultMutableTreeNode n2 = (DefaultMutableTreeNode) o2;
        PsiNamedElement element1 = (PsiNamedElement) n1.getUserObject();
        PsiNamedElement element2 = (PsiNamedElement) n2.getUserObject();
        return element1.getName().compareToIgnoreCase(element2.getName());
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileIndex(com.intellij.openapi.roots.FileIndex) ContentIterator(com.intellij.openapi.roots.ContentIterator) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 14 with ContentIterator

use of com.intellij.openapi.roots.ContentIterator in project intellij-community by JetBrains.

the class DumpDirectoryInfoAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final DirectoryIndex index = DirectoryIndex.getInstance(project);
    if (project != null) {
        final VirtualFile root = e.getData(CommonDataKeys.VIRTUAL_FILE);
        ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
            final ContentIterator contentIterator = new ContentIterator() {

                @Override
                public boolean processFile(VirtualFile fileOrDir) {
                    LOG.info(fileOrDir.getPath());
                    LOG.info(index.getInfoForFile(fileOrDir).toString());
                    return true;
                }
            };
            if (root != null) {
                ProjectRootManager.getInstance(project).getFileIndex().iterateContentUnderDirectory(root, contentIterator);
            } else {
                ProjectRootManager.getInstance(project).getFileIndex().iterateContent(contentIterator);
            }
        }, "Dumping directory index", true, project);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ContentIterator(com.intellij.openapi.roots.ContentIterator) DirectoryIndex(com.intellij.openapi.roots.impl.DirectoryIndex)

Example 15 with ContentIterator

use of com.intellij.openapi.roots.ContentIterator in project intellij-community by JetBrains.

the class LoadAllContentsAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    String m = "Started loading content";
    LOG.info(m);
    System.out.println(m);
    long start = System.currentTimeMillis();
    count.set(0);
    totalSize.set(0);
    ApplicationManagerEx.getApplicationEx().runProcessWithProgressSynchronously(() -> ProjectRootManager.getInstance(project).getFileIndex().iterateContent(new ContentIterator() {

        @Override
        public boolean processFile(VirtualFile fileOrDir) {
            if (fileOrDir.isDirectory() || fileOrDir.is(VFileProperty.SPECIAL)) {
                return true;
            }
            try {
                count.incrementAndGet();
                byte[] bytes = FileUtil.loadFileBytes(new File(fileOrDir.getPath()));
                totalSize.addAndGet(bytes.length);
                ProgressManager.getInstance().getProgressIndicator().setText(fileOrDir.getPresentableUrl());
            } catch (IOException e1) {
                LOG.error(e1);
            }
            return true;
        }
    }), "Loading", false, project);
    long end = System.currentTimeMillis();
    String message = "Finished loading content of " + count + " files. " + "Total size=" + StringUtil.formatFileSize(totalSize.get()) + ". " + "Elapsed=" + ((end - start) / 1000) + "sec.";
    LOG.info(message);
    System.out.println(message);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ContentIterator(com.intellij.openapi.roots.ContentIterator) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

ContentIterator (com.intellij.openapi.roots.ContentIterator)20 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 NotNull (org.jetbrains.annotations.NotNull)8 Project (com.intellij.openapi.project.Project)6 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)4 IOException (java.io.IOException)4 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)3 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)3 File (java.io.File)3 Nullable (org.jetbrains.annotations.Nullable)3 Module (com.intellij.openapi.module.Module)2 ModuleFileIndex (com.intellij.openapi.roots.ModuleFileIndex)2 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)2 Condition (com.intellij.openapi.util.Condition)2 FileUtil (com.intellij.openapi.util.io.FileUtil)2 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)2 VirtualFileManager (com.intellij.openapi.vfs.VirtualFileManager)2 VirtualFileVisitor (com.intellij.openapi.vfs.VirtualFileVisitor)2 VirtualFileWithId (com.intellij.openapi.vfs.VirtualFileWithId)2 PsiDirectory (com.intellij.psi.PsiDirectory)2