本文整理汇总了Java中com.intellij.openapi.vfs.VirtualFileVisitor类的典型用法代码示例。如果您正苦于以下问题:Java VirtualFileVisitor类的具体用法?Java VirtualFileVisitor怎么用?Java VirtualFileVisitor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VirtualFileVisitor类属于com.intellij.openapi.vfs包,在下文中一共展示了VirtualFileVisitor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findApplicationFileRecursively
import com.intellij.openapi.vfs.VirtualFileVisitor; //导入依赖的package包/类
@Nullable
private File findApplicationFileRecursively(@NotNull final VirtualFile appDirectory,
@NotNull final String applicationName) {
final VirtualFileVisitor<VirtualFile> fileVisitor = new VirtualFileVisitor<VirtualFile>(VirtualFileVisitor
.limit(APP_DEPTH_SEARCH), VirtualFileVisitor.SKIP_ROOT, VirtualFileVisitor.NO_FOLLOW_SYMLINKS) {
@Override
public boolean visitFile(@NotNull VirtualFile file) {
if (ApplicationDictionary.SUPPORTED_APPLICATION_EXTENSIONS.contains(file.getExtension())) {
if (applicationName.equals(file.getNameWithoutExtension())) {
throw new MyStopVisitingException(file);
}
return false; //do not search inside application bundles
}
return true;
}
};
try {
VfsUtilCore.visitChildrenRecursively(appDirectory, fileVisitor, MyStopVisitingException.class);
} catch (MyStopVisitingException e) {
LOG.debug("Application file found for application " + applicationName + " : " + e.getResult());
return new File(e.getResult().getPath());
}
return null;
}
示例2: getAllSubFiles
import com.intellij.openapi.vfs.VirtualFileVisitor; //导入依赖的package包/类
public static Collection<VirtualFile> getAllSubFiles(VirtualFile virtualFile)
{
Collection<VirtualFile> list = new ArrayList<>();
VfsUtilCore.visitChildrenRecursively(virtualFile, new VirtualFileVisitor() {
@Override
public boolean visitFile(@NotNull VirtualFile file) {
if (!file.isDirectory()) {
list.add(file);
}
return super.visitFile(file);
}
});
return list;
}
示例3: loadAllModulesUnder
import com.intellij.openapi.vfs.VirtualFileVisitor; //导入依赖的package包/类
@Nullable
protected Module loadAllModulesUnder(@NotNull VirtualFile rootDir, @Nullable final Consumer<Module> moduleConsumer) {
final Ref<Module> result = Ref.create();
VfsUtilCore.visitChildrenRecursively(rootDir, new VirtualFileVisitor() {
@Override
public boolean visitFile(@NotNull VirtualFile file) {
if (!file.isDirectory() && file.getName().endsWith(ModuleFileType.DOT_DEFAULT_EXTENSION)) {
ModuleImpl module = (ModuleImpl)loadModule(file.getPath());
if (moduleConsumer != null) {
moduleConsumer.consume(module);
}
result.setIfNull(module);
}
return true;
}
});
return result.get();
}
示例4: processFolder
import com.intellij.openapi.vfs.VirtualFileVisitor; //导入依赖的package包/类
protected void processFolder(final HashSet<String> seenNames, final PsiManager manager, final VirtualFile folder) {
VfsUtilCore.visitChildrenRecursively(folder, new VirtualFileVisitor() {
@Override
public boolean visitFile(@NotNull VirtualFile file) {
if (myExcludedFolders.contains(file)) {
return false;
}
if (!file.isDirectory()) {
final PsiFile psiFile = manager.findFile(file);
if (psiFile != null) {
processFile(psiFile, seenNames);
}
}
return true;
}
});
}
示例5: getFilesWithBom
import com.intellij.openapi.vfs.VirtualFileVisitor; //导入依赖的package包/类
private static void getFilesWithBom(@NotNull VirtualFile root, @NotNull final List<VirtualFile> result, final boolean all) {
VfsUtilCore.visitChildrenRecursively(root, new VirtualFileVisitor() {
@Override
public boolean visitFile(@NotNull VirtualFile file) {
if (file.isDirectory()) {
if (!all && !result.isEmpty()) {
return false;
}
}
else if (file.getBOM() != null) {
result.add(file);
}
return true;
}
});
}
示例6: iterateRecursively
import com.intellij.openapi.vfs.VirtualFileVisitor; //导入依赖的package包/类
public static void iterateRecursively(@Nullable final VirtualFile root,
@NotNull final ContentIterator processor,
@Nullable final ProgressIndicator indicator,
@Nullable final Set<VirtualFile> visitedRoots,
@Nullable final ProjectFileIndex projectFileIndex) {
if (root == null) {
return;
}
VfsUtilCore.visitChildrenRecursively(root, new VirtualFileVisitor() {
@Override
public boolean visitFile(@NotNull VirtualFile file) {
if (visitedRoots != null && !root.equals(file) && file.isDirectory() && !visitedRoots.add(file)) {
return false; // avoid visiting files more than once, e.g. additional indexed roots intersect sometimes
}
if (projectFileIndex != null && projectFileIndex.isExcluded(file)) {
return false;
}
if (indicator != null) indicator.checkCanceled();
processor.processFile(file);
return true;
}
});
}
示例7: removeFilesAndDirsRecursively
import com.intellij.openapi.vfs.VirtualFileVisitor; //导入依赖的package包/类
void removeFilesAndDirsRecursively(@NotNull VirtualFile vFile) {
DebugUtil.startPsiModification("removeFilesAndDirsRecursively");
try {
VfsUtilCore.visitChildrenRecursively(vFile, new VirtualFileVisitor() {
@Override
public boolean visitFile(@NotNull VirtualFile file) {
if (file.isDirectory()) {
myVFileToPsiDirMap.remove(file);
}
else {
FileViewProvider viewProvider = myVFileToViewProviderMap.remove(file);
if (viewProvider instanceof SingleRootFileViewProvider) {
((SingleRootFileViewProvider)viewProvider).markInvalidated();
}
}
return true;
}
});
}
finally {
DebugUtil.finishPsiModification();
}
}
示例8: NewViewNameCompletionProvider
import com.intellij.openapi.vfs.VirtualFileVisitor; //导入依赖的package包/类
public NewViewNameCompletionProvider(VirtualFile targetDirectory) {
completions = new ArrayList<>();
VfsUtil.visitChildrenRecursively(targetDirectory, new VirtualFileVisitor() {
@Override
public boolean visitFile(@NotNull VirtualFile file) {
if(!file.isDirectory()) {
return true;
}
String path = StringUtils.stripStart(file.getPath().replace(targetDirectory.getPath(), ""), "\\/");
completions.add(LookupElementBuilder.create(path.replace("\\", ".").replace("/", ".") + "."));
return true;
}
});
}
示例9: loadAllModulesUnder
import com.intellij.openapi.vfs.VirtualFileVisitor; //导入依赖的package包/类
@Nullable
protected Module loadAllModulesUnder(@NotNull VirtualFile rootDir) throws Exception {
final Ref<Module> result = Ref.create();
VfsUtilCore.visitChildrenRecursively(rootDir, new VirtualFileVisitor() {
@Override
public boolean visitFile(@NotNull VirtualFile file) {
if (!file.isDirectory() && file.getName().endsWith(ModuleFileType.DOT_DEFAULT_EXTENSION)) {
ModuleImpl module = (ModuleImpl)loadModule(new File(file.getPath()));
readJdomExternalizables(module);
result.setIfNull(module);
}
return true;
}
});
return result.get();
}
示例10: getFilesWithBom
import com.intellij.openapi.vfs.VirtualFileVisitor; //导入依赖的package包/类
private static void getFilesWithBom(@Nonnull VirtualFile root, @Nonnull final List<VirtualFile> result, final boolean all) {
VfsUtilCore.visitChildrenRecursively(root, new VirtualFileVisitor() {
@Override
public boolean visitFile(@Nonnull VirtualFile file) {
if (file.isDirectory()) {
if (!all && !result.isEmpty()) {
return false;
}
}
else if (file.getBOM() != null) {
result.add(file);
}
return true;
}
});
}
示例11: removeFilesAndDirsRecursively
import com.intellij.openapi.vfs.VirtualFileVisitor; //导入依赖的package包/类
void removeFilesAndDirsRecursively(@Nonnull VirtualFile vFile) {
DebugUtil.performPsiModification("removeFilesAndDirsRecursively", () -> {
VfsUtilCore.visitChildrenRecursively(vFile, new VirtualFileVisitor() {
@Override
public boolean visitFile(@Nonnull VirtualFile file) {
if (file.isDirectory()) {
getVFileToPsiDirMap().remove(file);
}
else {
FileViewProvider viewProvider = getVFileToViewProviderMap().remove(file);
if (viewProvider != null) {
markInvalidated(viewProvider);
}
}
return true;
}
});
});
}
示例12: modifyRoots
import com.intellij.openapi.vfs.VirtualFileVisitor; //导入依赖的package包/类
@Override
protected void modifyRoots(@NotNull VirtualFile vFile, @NotNull ContentEntry entry) {
VfsUtilCore.visitChildrenRecursively(vFile, new VirtualFileVisitor() {
@Override
public boolean visitFile(@NotNull VirtualFile file) {
if (file.isDirectory() && file.is(VFileProperty.SYMLINK)) {
entry.addExcludeFolder(file);
return false;
} else {
return true;
}
}
});
}
示例13: discoverApplicationsInDirectory
import com.intellij.openapi.vfs.VirtualFileVisitor; //导入依赖的package包/类
private void discoverApplicationsInDirectory(@NotNull VirtualFile appsDirVFile) {
VfsUtilCore.visitChildrenRecursively(appsDirVFile, new VirtualFileVisitor(VirtualFileVisitor.limit(APP_DEPTH_SEARCH)) {
@Override
public boolean visitFile(@NotNull VirtualFile file) {
if (ApplicationDictionaryImpl.extensionSupported(file.getExtension())) {
if (!"xml".equals(file.getExtension())) {
discoveredApplicationNames.add(file.getNameWithoutExtension());
}
return false;
}
return file.isDirectory();
}
});
}
示例14: setUpExternalUpAnnotations
import com.intellij.openapi.vfs.VirtualFileVisitor; //导入依赖的package包/类
private void setUpExternalUpAnnotations() {
String annotationsPath = PathManagerEx.getTestDataPath() + "/codeInspection/bytecodeAnalysis/annotations";
final VirtualFile annotationsDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(annotationsPath);
assertNotNull(annotationsDir);
ModuleRootModificationUtil.updateModel(myModule, new AsynchConsumer<ModifiableRootModel>() {
@Override
public void finished() {
}
@Override
public void consume(ModifiableRootModel modifiableRootModel) {
final LibraryTable libraryTable = modifiableRootModel.getModuleLibraryTable();
Library[] libs = libraryTable.getLibraries();
for (Library library : libs) {
final Library.ModifiableModel libraryModel = library.getModifiableModel();
libraryModel.addRoot(annotationsDir, AnnotationOrderRootType.getInstance());
libraryModel.commit();
}
Sdk sdk = modifiableRootModel.getSdk();
if (sdk != null) {
SdkModificator sdkModificator = sdk.getSdkModificator();
sdkModificator.addRoot(annotationsDir, AnnotationOrderRootType.getInstance());
sdkModificator.commitChanges();
}
}
});
VfsUtilCore.visitChildrenRecursively(annotationsDir, new VirtualFileVisitor() { });
annotationsDir.refresh(false, true);
}
示例15: suggestRoots
import com.intellij.openapi.vfs.VirtualFileVisitor; //导入依赖的package包/类
/**
* Scan directory and detect java source roots within it. The source root is detected as the following:
* <ol>
* <li>It contains at least one Java file.</li>
* <li>Java file is located in the sub-folder that matches package statement in the file.</li>
* </ol>
*
* @param dir a directory to scan
* @param progressIndicator
* @return a list of found source roots within directory. If no source roots are found, a empty list is returned.
*/
@NotNull
public static List<VirtualFile> suggestRoots(@NotNull VirtualFile dir, @NotNull final ProgressIndicator progressIndicator) {
if (!dir.isDirectory()) {
return ContainerUtil.emptyList();
}
final FileTypeManager typeManager = FileTypeManager.getInstance();
final ArrayList<VirtualFile> foundDirectories = new ArrayList<VirtualFile>();
try {
VfsUtilCore.visitChildrenRecursively(dir, new VirtualFileVisitor() {
@NotNull
@Override
public Result visitFileEx(@NotNull VirtualFile file) {
progressIndicator.checkCanceled();
if (file.isDirectory()) {
if (typeManager.isFileIgnored(file) || StringUtil.startsWithIgnoreCase(file.getName(), "testData")) {
return SKIP_CHILDREN;
}
}
else {
FileType type = typeManager.getFileTypeByFileName(file.getName());
if (StdFileTypes.JAVA == type) {
VirtualFile root = suggestRootForJavaFile(file);
if (root != null) {
foundDirectories.add(root);
return skipTo(root);
}
}
}
return CONTINUE;
}
});
}
catch (ProcessCanceledException ignore) { }
return foundDirectories;
}