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");
}
}
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;
}
});
});
}
}
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");
}
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();
}
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;
});
}
Aggregations