Search in sources :

Example 16 with ContentIterator

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

the class ScanSourceCommentsAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project p = e.getProject();
    final String file = Messages.showInputDialog(p, "Enter path to the file comments will be extracted to", "Comments File Path", Messages.getQuestionIcon());
    try {
        final PrintStream stream = new PrintStream(file);
        stream.println("Comments in " + p.getName());
        ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
            final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
            ProjectRootManager.getInstance(p).getFileIndex().iterateContent(new ContentIterator() {

                @Override
                public boolean processFile(VirtualFile fileOrDir) {
                    if (fileOrDir.isDirectory()) {
                        indicator.setText("Extracting comments");
                        indicator.setText2(fileOrDir.getPresentableUrl());
                    }
                    scanCommentsInFile(p, fileOrDir);
                    return true;
                }
            });
            indicator.setText2("");
            int count = 1;
            for (CommentDescriptor descriptor : myComments.values()) {
                stream.println("#" + count + " ---------------------------------------------------------------");
                descriptor.print(stream);
                stream.println();
                count++;
            }
        }, "Generating Comments", true, p);
        stream.close();
    } catch (Throwable e1) {
        LOG.error(e1);
        Messages.showErrorDialog(p, "Error writing? " + e1.getMessage(), "Problem writing");
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PrintStream(java.io.PrintStream) ContentIterator(com.intellij.openapi.roots.ContentIterator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 17 with ContentIterator

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

the class AbstractFileProcessor method findFiles.

protected static void findFiles(final Module module, final List<PsiFile> files) {
    final ModuleFileIndex idx = ModuleRootManager.getInstance(module).getFileIndex();
    final VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
    for (final VirtualFile root : roots) {
        ApplicationManager.getApplication().runReadAction(() -> {
            idx.iterateContentUnderDirectory(root, new ContentIterator() {

                @Override
                public boolean processFile(final VirtualFile dir) {
                    if (dir.isDirectory()) {
                        final PsiDirectory psiDir = PsiManager.getInstance(module.getProject()).findDirectory(dir);
                        if (psiDir != null) {
                            findFiles(files, psiDir, false);
                        }
                    }
                    return true;
                }
            });
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentIterator(com.intellij.openapi.roots.ContentIterator) PsiDirectory(com.intellij.psi.PsiDirectory) ModuleFileIndex(com.intellij.openapi.roots.ModuleFileIndex)

Example 18 with ContentIterator

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

the class PySignatureCacheManagerImpl method clearCache.

@Override
public void clearCache() {
    final Ref<Boolean> deleted = Ref.create(false);
    ProgressManager.getInstance().runProcessWithProgressSynchronously((Runnable) () -> ProjectFileIndex.SERVICE.getInstance(myProject).iterateContent(new ContentIterator() {

        @Override
        public boolean processFile(VirtualFile fileOrDir) {
            if (readAttribute(fileOrDir) != null) {
                writeAttribute(fileOrDir, "");
                deleted.set(true);
            }
            if (ProgressManager.getInstance().getProgressIndicator().isCanceled()) {
                return false;
            }
            return true;
        }
    }), "Cleaning the Cache of Dynamically Collected Types", true, myProject);
    String message;
    if (deleted.get()) {
        message = "Collected signatures were deleted";
    } else {
        message = "Nothing to delete";
    }
    Messages.showInfoMessage(myProject, message, "Delete Cache");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentIterator(com.intellij.openapi.roots.ContentIterator)

Example 19 with ContentIterator

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

the class PyIntegratedToolsConfigurable method apply.

@Override
public void apply() throws ConfigurationException {
    if (myDocstringFormatComboBox.getSelectedItem() != myDocumentationSettings.getFormat()) {
        DaemonCodeAnalyzer.getInstance(myProject).restart();
    }
    if (analyzeDoctest.isSelected() != myDocumentationSettings.isAnalyzeDoctest()) {
        final List<VirtualFile> files = Lists.newArrayList();
        ProjectRootManager.getInstance(myProject).getFileIndex().iterateContent(new ContentIterator() {

            @Override
            public boolean processFile(VirtualFile fileOrDir) {
                if (!fileOrDir.isDirectory() && PythonFileType.INSTANCE.getDefaultExtension().equals(fileOrDir.getExtension())) {
                    files.add(fileOrDir);
                }
                return true;
            }
        });
        FileContentUtil.reparseFiles(myProject, Lists.newArrayList(files), false);
    }
    myModel.apply();
    myDocumentationSettings.setFormat((DocStringFormat) myDocstringFormatComboBox.getSelectedItem());
    final ReSTService reSTService = ReSTService.getInstance(myModule);
    reSTService.setWorkdir(myWorkDir.getText());
    if (txtIsRst.isSelected() != reSTService.txtIsRst()) {
        reSTService.setTxtIsRst(txtIsRst.isSelected());
        reparseFiles(Collections.singletonList(PlainTextFileType.INSTANCE.getDefaultExtension()));
    }
    myDocumentationSettings.setAnalyzeDoctest(analyzeDoctest.isSelected());
    PyPackageRequirementsSettings.getInstance(myModule).setRequirementsPath(myRequirementsPathField.getText());
    DaemonCodeAnalyzer.getInstance(myProject).restart();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentIterator(com.intellij.openapi.roots.ContentIterator) ReSTService(com.jetbrains.python.ReSTService)

Example 20 with ContentIterator

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

the class DesignerTests method configureByFiles.

public static VirtualFile[] configureByFiles(@Nullable VirtualFile rawProjectRoot, VirtualFile[] files, @Nullable VirtualFile[] auxiliaryFiles, Module module, @Nullable TripleFunction<ModifiableRootModel, VirtualFile, List<String>, Void> moduleInitializer) throws Exception {
    return WriteAction.compute(() -> {
        VirtualFile dummyRoot = VirtualFileManager.getInstance().findFileByUrl("temp:///");
        //noinspection ConstantConditions
        dummyRoot.refresh(false, false);
        final VirtualFile sourceDir = dummyRoot.createChildDirectory(DesignerTests.class, "s");
        assert sourceDir != null;
        final IndexableFileSet indexableFileSet = new IndexableFileSet() {

            @Override
            public boolean isInSet(@NotNull final VirtualFile file) {
                return file.getFileSystem() == sourceDir.getFileSystem();
            }

            @Override
            public void iterateIndexableFilesIn(@NotNull final VirtualFile file, @NotNull final ContentIterator iterator) {
                if (file.isDirectory()) {
                    for (VirtualFile child : file.getChildren()) {
                        iterateIndexableFilesIn(child, iterator);
                    }
                } else {
                    iterator.processFile(file);
                }
            }
        };
        FileBasedIndex.getInstance().registerIndexableSet(indexableFileSet, module.getProject());
        Disposer.register(module, new Disposable() {

            @Override
            public void dispose() {
                FileBasedIndex.getInstance().removeIndexableSet(indexableFileSet);
                ApplicationManager.getApplication().runWriteAction(() -> {
                    try {
                        sourceDir.delete(null);
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                });
            }
        });
        final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
        VirtualFile[] toFiles = copyFiles(files, sourceDir, rawProjectRoot);
        if (auxiliaryFiles != null) {
            copyFiles(auxiliaryFiles, sourceDir, rawProjectRoot);
        }
        rootModel.addContentEntry(sourceDir).addSourceFolder(sourceDir, false);
        final List<String> libs = new ArrayList<>();
        if (moduleInitializer != null) {
            moduleInitializer.fun(rootModel, sourceDir, libs);
        }
        rootModel.commit();
        for (String path : libs) {
            VirtualFile virtualFile = path.charAt(0) != '/' ? getFile("lib", path) : getFile(path);
            FlexTestUtils.addLibrary(module, path, virtualFile.getParent().getPath(), virtualFile.getName(), null, null);
        }
        return toFiles;
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Disposable(com.intellij.openapi.Disposable) ContentIterator(com.intellij.openapi.roots.ContentIterator) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IndexableFileSet(com.intellij.util.indexing.IndexableFileSet) NotNull(org.jetbrains.annotations.NotNull) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel)

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