com.intellij.openapi.vfs.VirtualFileFilter Java Examples
The following examples show how to use
com.intellij.openapi.vfs.VirtualFileFilter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileLookupData.java From intellij with Apache License 2.0 | 6 votes |
@Nullable public static FileLookupData nonLocalFileLookup( String originalLabel, @Nullable BuildFile containingFile, QuoteType quoteType, PathFormat pathFormat) { if (originalLabel.indexOf(':') != -1) { // it's a package-local reference return null; } // handle the single '/' case by calling twice. String relativePath = StringUtil.trimStart(StringUtil.trimStart(originalLabel, "/"), "/"); if (relativePath.startsWith("/")) { return null; } boolean onlyDirectories = pathFormat != PathFormat.NonLocalWithoutInitialBackslashes; VirtualFileFilter filter = vf -> !onlyDirectories || vf.isDirectory(); return new FileLookupData( originalLabel, containingFile, null, relativePath, pathFormat, quoteType, filter); }
Example #2
Source File: FileLookupData.java From intellij with Apache License 2.0 | 6 votes |
@Nullable public static FileLookupData packageLocalFileLookup( String originalLabel, StringLiteral element, @Nullable BuildFile basePackage, @Nullable VirtualFileFilter fileFilter) { if (basePackage == null) { return null; } Label packageLabel = basePackage.getPackageLabel(); if (packageLabel == null) { return null; } String basePackagePath = packageLabel.blazePackage().relativePath(); String filePath = basePackagePath + "/" + LabelUtils.getRuleComponent(originalLabel); return new FileLookupData( originalLabel, basePackage, basePackagePath, filePath, PathFormat.PackageLocal, element.getQuoteType(), fileFilter); }
Example #3
Source File: FileLookupData.java From intellij with Apache License 2.0 | 6 votes |
private FileLookupData( String originalLabel, @Nullable BuildFile containingFile, @Nullable String containingPackage, String filePathFragment, PathFormat pathFormat, QuoteType quoteType, @Nullable VirtualFileFilter fileFilter) { this.originalLabel = originalLabel; this.containingFile = containingFile; this.containingPackage = containingPackage; this.fileFilter = fileFilter; this.filePathFragment = filePathFragment; this.pathFormat = pathFormat; this.quoteType = quoteType; assert (pathFormat != PathFormat.PackageLocal || (containingPackage != null && containingFile != null)); }
Example #4
Source File: PolygeneFacetType.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override public final void registerDetectors( FacetDetectorRegistry<PolygeneFacetConfiguration> registry ) { registry.registerOnTheFlyDetector( StdFileTypes.JAVA, VirtualFileFilter.ALL, new HasPolygeneImportPackageCondition(), new FacetDetector<PsiFile, PolygeneFacetConfiguration>( "PolygeneFacetDetector" ) { @Override public PolygeneFacetConfiguration detectFacet( PsiFile source, Collection<PolygeneFacetConfiguration> existingConfigurations ) { if( !existingConfigurations.isEmpty() ) { return existingConfigurations.iterator().next(); } return createDefaultConfiguration(); } } ); }
Example #5
Source File: AnalysisScope.java From consulo with Apache License 2.0 | 6 votes |
protected boolean accept(@Nonnull final PsiDirectory dir, @Nonnull final Processor<VirtualFile> processor) { final Project project = dir.getProject(); final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex(); //we should analyze generated source files only if the action is explicitly invoked for a directory located under generated roots final boolean processGeneratedFiles = isInGeneratedSources(dir.getVirtualFile(), project); return VfsUtilCore.iterateChildrenRecursively(dir.getVirtualFile(), VirtualFileFilter.ALL, new ContentIterator() { @Override @SuppressWarnings({"SimplifiableIfStatement"}) public boolean processFile(@Nonnull final VirtualFile fileOrDir) { if (!myIncludeTestSource && index.isInTestSourceContent(fileOrDir)) return true; if (!processGeneratedFiles && isInGeneratedSources(fileOrDir, project)) return true; if (!fileOrDir.isDirectory()) { return processor.process(fileOrDir); } return true; } }); }
Example #6
Source File: PsiManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override @TestOnly public void setAssertOnFileLoadingFilter(@Nonnull VirtualFileFilter filter, @Nonnull Disposable parentDisposable) { // Find something to ensure there's no changed files waiting to be processed in repository indices. myAssertOnFileLoadingFilter = filter; Disposer.register(parentDisposable, () -> myAssertOnFileLoadingFilter = VirtualFileFilter.NONE); }
Example #7
Source File: AbstractLayoutCodeProcessor.java From consulo with Apache License 2.0 | 5 votes |
private boolean acceptedByFilters(@Nonnull PsiFile file) { VirtualFile vFile = file.getVirtualFile(); if (vFile == null) { return false; } for (VirtualFileFilter filter : myFilters) { if (!filter.accept(file.getVirtualFile())) { return false; } } return true; }
Example #8
Source File: PlatformTestUtil.java From consulo with Apache License 2.0 | 5 votes |
@SuppressWarnings("UnsafeVfsRecursion") public static void assertDirectoriesEqual(VirtualFile dirAfter, VirtualFile dirBefore, @Nullable VirtualFileFilter fileFilter) throws IOException { FileDocumentManager.getInstance().saveAllDocuments(); VirtualFile[] childrenAfter = dirAfter.getChildren(); if (dirAfter.isInLocalFileSystem()) { File[] ioAfter = new File(dirAfter.getPath()).listFiles(); shallowCompare(childrenAfter, ioAfter); } VirtualFile[] childrenBefore = dirBefore.getChildren(); if (dirBefore.isInLocalFileSystem()) { File[] ioBefore = new File(dirBefore.getPath()).listFiles(); shallowCompare(childrenBefore, ioBefore); } HashMap<String, VirtualFile> mapAfter = buildNameToFileMap(childrenAfter, fileFilter); HashMap<String, VirtualFile> mapBefore = buildNameToFileMap(childrenBefore, fileFilter); Set<String> keySetAfter = mapAfter.keySet(); Set<String> keySetBefore = mapBefore.keySet(); assertEquals(dirAfter.getPath(), keySetAfter, keySetBefore); for (String name : keySetAfter) { VirtualFile fileAfter = mapAfter.get(name); VirtualFile fileBefore = mapBefore.get(name); if (fileAfter.isDirectory()) { assertDirectoriesEqual(fileAfter, fileBefore, fileFilter); } else { assertFilesEqual(fileAfter, fileBefore); } } }
Example #9
Source File: PlatformTestUtil.java From consulo with Apache License 2.0 | 5 votes |
private static HashMap<String, VirtualFile> buildNameToFileMap(VirtualFile[] files, @javax.annotation.Nullable VirtualFileFilter filter) { HashMap<String, VirtualFile> map = new HashMap<String, VirtualFile>(); for (VirtualFile file : files) { if (filter != null && !filter.accept(file)) continue; map.put(file.getName(), file); } return map; }
Example #10
Source File: ModuleFileIndexImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean iterateContent(@Nonnull ContentIterator processor, @Nullable VirtualFileFilter filter) { final Set<VirtualFile> contentRoots = AccessRule.read(() -> { if (myModule.isDisposed()) return Collections.emptySet(); Set<VirtualFile> result = new LinkedHashSet<>(); VirtualFile[][] allRoots = getModuleContentAndSourceRoots(myModule); for (VirtualFile[] roots : allRoots) { for (VirtualFile root : roots) { DirectoryInfo info = getInfoForFileOrDirectory(root); if (!info.isInProject(root)) continue; VirtualFile parent = root.getParent(); if (parent != null) { DirectoryInfo parentInfo = myDirectoryIndex.getInfoForFile(parent); if (parentInfo.isInProject(parent) && myModule.equals(parentInfo.getModule())) continue; // inner content - skip it } result.add(root); } } return result; }); for (VirtualFile contentRoot : contentRoots) { if (!iterateContentUnderDirectory(contentRoot, processor, filter)) { return false; } } return true; }
Example #11
Source File: ProjectFileIndexImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean iterateContent(@Nonnull ContentIterator processor, @Nullable VirtualFileFilter filter) { Module[] modules = AccessRule.read(() -> ModuleManager.getInstance(myProject).getModules()); for (final Module module : modules) { for (VirtualFile contentRoot : getRootsToIterate(module)) { if (!iterateContentUnderDirectory(contentRoot, processor, filter)) { return false; } } } return true; }
Example #12
Source File: LabelReference.java From intellij with Apache License 2.0 | 5 votes |
private BuildLookupElement[] getSkylarkExtensionLookups(String labelString) { if (!skylarkExtensionReference(myElement)) { return BuildLookupElement.EMPTY_ARRAY; } String packagePrefix = LabelUtils.getPackagePathComponent(labelString); BuildFile parentFile = myElement.getContainingFile(); if (parentFile == null) { return BuildLookupElement.EMPTY_ARRAY; } BlazePackage containingPackage = BlazePackage.getContainingPackage(parentFile); if (containingPackage == null) { return BuildLookupElement.EMPTY_ARRAY; } BuildFile referencedBuildFile = LabelUtils.getReferencedBuildFile(containingPackage.buildFile, packagePrefix); // Directories before the colon are already covered. // We're only concerned with package-local directories. boolean hasColon = labelString.indexOf(':') != -1; VirtualFileFilter filter = file -> ("bzl".equals(file.getExtension()) && !file.getPath().equals(parentFile.getFilePath())) || (hasColon && file.isDirectory()); FileLookupData lookupData = FileLookupData.packageLocalFileLookup(labelString, myElement, referencedBuildFile, filter); return lookupData != null ? getReferenceManager().resolvePackageLookupElements(lookupData) : BuildLookupElement.EMPTY_ARRAY; }
Example #13
Source File: AbstractFileTreeTable.java From consulo with Apache License 2.0 | 4 votes |
public ProjectRootNode(@Nonnull Project project) { this(project, VirtualFileFilter.ALL); }
Example #14
Source File: AbstractFileTreeTable.java From consulo with Apache License 2.0 | 4 votes |
public ProjectRootNode(@Nonnull Project project, @Nonnull VirtualFileFilter filter) { super(project); myFilter = filter; }
Example #15
Source File: AbstractFileTreeTable.java From consulo with Apache License 2.0 | 4 votes |
public FileNode(@Nonnull VirtualFile file, @Nonnull final Project project) { this(file, project, VirtualFileFilter.ALL); }
Example #16
Source File: AbstractFileTreeTable.java From consulo with Apache License 2.0 | 4 votes |
private MyModel(@Nonnull Project project, @Nonnull Class<T> valueClass, @Nonnull String valueTitle, @Nonnull VirtualFileFilter filter) { super(new ProjectRootNode(project, filter)); myValueClass = valueClass; myValueTitle = valueTitle; }
Example #17
Source File: AbstractFileTreeTable.java From consulo with Apache License 2.0 | 4 votes |
public AbstractFileTreeTable(@Nonnull Project project, @Nonnull Class<T> valueClass, @Nonnull String valueTitle, @Nonnull VirtualFileFilter filter, boolean showProjectNode) { super(new MyModel<T>(project, valueClass, valueTitle, filter)); myProject = project; myModel = (MyModel)getTableModel(); myModel.setTreeTable(this); new TreeTableSpeedSearch(this, new Convertor<TreePath, String>() { @Override public String convert(final TreePath o) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode)o.getLastPathComponent(); final Object userObject = node.getUserObject(); if (userObject == null) { return getProjectNodeText(); } if (userObject instanceof VirtualFile) { return ((VirtualFile)userObject).getName(); } return node.toString(); } }); final DefaultTreeExpander treeExpander = new DefaultTreeExpander(getTree()); CommonActionsManager.getInstance().createExpandAllAction(treeExpander, this); CommonActionsManager.getInstance().createCollapseAllAction(treeExpander, this); getTree().setShowsRootHandles(true); getTree().setLineStyleAngled(); getTree().setRootVisible(showProjectNode); getTree().setCellRenderer(new DefaultTreeCellRenderer() { @Override public Component getTreeCellRendererComponent(final JTree tree, final Object value, final boolean sel, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); if (value instanceof ProjectRootNode) { setText(getProjectNodeText()); setIcon(AllIcons.Nodes.ProjectTab); return this; } FileNode fileNode = (FileNode)value; VirtualFile file = fileNode.getObject(); if (fileNode.getParent() instanceof FileNode) { setText(file.getName()); } else { setText(file.getPresentableUrl()); } consulo.ui.image.Image icon = file.isDirectory() ? AllIcons.Nodes.TreeClosed : VfsIconUtil.getIcon(file, 0, null); setIcon(TargetAWT.to(icon)); return this; } }); getTableHeader().setReorderingAllowed(false); setSelectionMode(ListSelectionModel.SINGLE_SELECTION); setPreferredScrollableViewportSize(new Dimension(300, getRowHeight() * 10)); getColumnModel().getColumn(0).setPreferredWidth(280); getColumnModel().getColumn(1).setPreferredWidth(60); }
Example #18
Source File: AbstractLayoutCodeProcessor.java From consulo with Apache License 2.0 | 4 votes |
public void addFileFilter(@Nonnull VirtualFileFilter filter) { myFilters.add(filter); }
Example #19
Source File: AbstractFileTreeTable.java From consulo with Apache License 2.0 | 4 votes |
public FileNode(@Nonnull VirtualFile file, @Nonnull final Project project, @Nonnull VirtualFileFilter filter) { super(file); myProject = project; myFilter = filter; }
Example #20
Source File: PsiManagerEx.java From consulo with Apache License 2.0 | 4 votes |
@TestOnly public abstract void setAssertOnFileLoadingFilter(@Nonnull VirtualFileFilter filter, @Nonnull Disposable parentDisposable);
Example #21
Source File: FileIndexBase.java From consulo with Apache License 2.0 | 4 votes |
private static boolean iterateContentUnderDirectoryWithFilter(@Nonnull VirtualFile dir, @Nonnull ContentIterator iterator, @Nonnull VirtualFileFilter filter) { return VfsUtilCore.iterateChildrenRecursively(dir, filter, iterator); }
Example #22
Source File: FileIndexBase.java From consulo with Apache License 2.0 | 4 votes |
@Override public boolean iterateContentUnderDirectory(@Nonnull VirtualFile dir, @Nonnull ContentIterator processor, @Nullable VirtualFileFilter customFilter) { VirtualFileFilter filter = customFilter != null ? file -> myContentFilter.accept(file) && customFilter.accept(file) : myContentFilter; return iterateContentUnderDirectoryWithFilter(dir, processor, filter); }
Example #23
Source File: LocalFilesystemModificationHandler.java From saros with GNU General Public License v2.0 | 4 votes |
/** * Generates and dispatches a folder deletion activity for the deleted folder. * * <p>Also explicitly creates deletion activities for all contained (non-excluded) resources. * Contained files are processed first (in ascending depth order), followed by the contained * folders in descending depth order. This ensures that deletion activities for folders are only * send once the activities for all contained resources were sent, allowing the receiver to also * explicitly handle all resource deletions. * * @param deletedFolder the folder that was deleted */ private void generateFolderDeletionActivity(@NotNull VirtualFile deletedFolder) { Set<IReferencePoint> sharedReferencePoints = session.getReferencePoints(); IContainer container = (IContainer) VirtualFileConverter.convertToResource(sharedReferencePoints, deletedFolder); if (container == null || !session.isShared(container)) { if (log.isTraceEnabled()) { log.trace("Ignoring non-shared folder deletion: " + deletedFolder); } return; } else if (container.getType() == REFERENCE_POINT) { log.error( "Local representation of reference point " + container + " was deleted. Leaving the session."); NotificationPanel.showError( MessageFormat.format( Messages.LocalFilesystemModificationHandler_deleted_reference_point_message, deletedFolder.getPath()), Messages.LocalFilesystemModificationHandler_deleted_reference_point_title); CollaborationUtils.leaveSessionUnconditionally(); return; } IReferencePoint baseReferencePoint = container.getReferencePoint(); User user = session.getLocalUser(); Deque<IActivity> queuedDeletionActivities = new ConcurrentLinkedDeque<>(); VirtualFileFilter virtualFileFilter = getVirtualFileFilter(); /* * Defines the actions executed on the base directory and every valid * child resource (defined through the virtualFileFilter). * * Returns whether the content iteration should be continued. */ ContentIterator contentIterator = fileOrDir -> { if (!fileOrDir.isDirectory()) { generateFileDeletionActivity(fileOrDir); return true; } IFolder childFolder = (IFolder) VirtualFileConverter.convertToResource(fileOrDir, baseReferencePoint); if (childFolder == null || !session.isShared(childFolder)) { log.debug( "Ignoring non-shared child folder deletion: " + fileOrDir + ", parent folder: " + container); return true; } IActivity newFolderDeletedActivity = new FolderDeletedActivity(user, childFolder); queuedDeletionActivities.addFirst(newFolderDeletedActivity); return true; }; /* * Calls the above defined contentIterator on the base directory and every contained resource. * Directories are only stepped into if they match the above defined virtualFileFilter. This * also applies to the base directory. */ VfsUtilCore.iterateChildrenRecursively(deletedFolder, virtualFileFilter, contentIterator); while (!queuedDeletionActivities.isEmpty()) { dispatchActivity(queuedDeletionActivities.pop()); } }
Example #24
Source File: FileIndex.java From consulo with Apache License 2.0 | 2 votes |
/** * Same as {@link #iterateContentUnderDirectory(VirtualFile, ContentIterator)} but allows to pass additional {@code customFilter} to * the iterator, in case you need to skip some file system branches using your own logic. If {@code customFilter} returns false on * a directory, it won't be processed, but iteration will go on. * <p> * {@code null} filter means that all directories should be processed. */ boolean iterateContentUnderDirectory(@Nonnull VirtualFile dir, @Nonnull ContentIterator processor, @Nullable VirtualFileFilter customFilter);
Example #25
Source File: MockPsiManager.java From consulo with Apache License 2.0 | 2 votes |
@Override public void setAssertOnFileLoadingFilter(@Nonnull VirtualFileFilter filter, @Nonnull Disposable parentDisposable) { }
Example #26
Source File: FileIndex.java From consulo with Apache License 2.0 | 2 votes |
/** * Same as {@link #iterateContent(ContentIterator)} but allows to pass {@code filter} to * provide filtering in condition for directories. * <p> * If {@code filter} returns false on a directory, the directory won't be processed, but iteration will go on. * <p> * {@code null} filter means that all directories should be processed. * * @return false if files processing was stopped ({@link ContentIterator#processFile(VirtualFile)} returned false) */ boolean iterateContent(@Nonnull ContentIterator processor, @Nullable VirtualFileFilter filter);
Example #27
Source File: LocalFilesystemModificationHandler.java From saros with GNU General Public License v2.0 | 2 votes |
/** * Returns a filter determining which child resources to iterate over. * * <p>The filter only iterates over non-excluded resources. * * @return a filter determining which child resources to iterate over * @see ProjectAPI#isExcluded(Project, VirtualFile) */ private VirtualFileFilter getVirtualFileFilter() { return (fileOrDir) -> ProjectAPI.isExcluded(project, fileOrDir); }
Example #28
Source File: TempDirTestFixture.java From consulo with Apache License 2.0 | votes |
VirtualFile copyAll(String dataDir, String targetDir, @Nonnull VirtualFileFilter filter);