@Override public <S> List<S> filterUniqueRoots( final List<S> in, final Convertor<S, VirtualFile> convertor) { Collections.sort( in, new ComparatorDelegate<S, VirtualFile>(convertor, FilePathComparator.getInstance())); for (int i = 1; i < in.size(); i++) { final S sChild = in.get(i); final VirtualFile child = convertor.convert(sChild); final VirtualFile childRoot = HgUtil.getHgRootOrNull(myProject, child); if (childRoot == null) { continue; } for (int j = i - 1; j >= 0; --j) { final S sParent = in.get(j); final VirtualFile parent = convertor.convert(sParent); // if the parent is an ancestor of the child and that they share common root, the child is // removed if (VfsUtil.isAncestor(parent, child, false) && VfsUtil.isAncestor(childRoot, parent, false)) { in.remove(i); //noinspection AssignmentToForLoopParameter --i; break; } } } return in; }
private void removeDescendants(VirtualFile file, VirtualFilePointerContainer container) { for (VirtualFile virtualFile : container.getFiles()) { if (VfsUtil.isAncestor(file, virtualFile, false)) { container.remove(myPointerManager.create(virtualFile, this, null)); } } }
@Nullable private MPSTreeNode getNode(MPSTreeNode rootTreeNode, VirtualFile file) { if (rootTreeNode instanceof AbstractFileTreeNode) { VirtualFile nodeFile = ((AbstractFileTreeNode) rootTreeNode).getFile(); if (nodeFile != null) { if (nodeFile.getUrl().equals(file.getUrl())) { return rootTreeNode; } if (!VfsUtil.isAncestor(nodeFile, file, false)) { return null; } } else { return null; } } for (MPSTreeNode node : rootTreeNode) { node.init(); MPSTreeNode result = getNode(node, file); if (result != null) { return result; } } return null; }
private static boolean isUnder(VirtualFile file, final VirtualFilePointerContainer container) { for (VirtualFile excludedFile : container.getFiles()) { if (VfsUtil.isAncestor(excludedFile, file, false)) { return true; } } return false; }
public boolean isInSet(VirtualFile file) { if (CacheUtil.isIgnored(file, myRootManager)) return false; for (VirtualFile vf : getRootFiles()) { if (VfsUtil.isAncestor(vf, file, true)) return true; } return false; }
@Override public boolean isInSet(VirtualFile file) { for (final VirtualFile root : getDirectories()) { if (VfsUtil.isAncestor(root, file, false)) { return true; } } return cachedFiles.contains(file); }
@Nullable private static String getRelativePathInSources( @NotNull VirtualFile file, final @NotNull ModuleOutputPackagingElement moduleElement, @NotNull PackagingElementResolvingContext context) { for (VirtualFile sourceRoot : moduleElement.getSourceRoots(context)) { if (VfsUtil.isAncestor(sourceRoot, file, true)) { return VfsUtilCore.getRelativePath(file, sourceRoot, '/'); } } return null; }
@Nullable public String getBranchForFile(final VirtualFile file) { final VirtualFile floor = myMap.floorKey(file); if (floor == null) return null; final SortedMap<VirtualFile, Pair<Boolean, String>> floorMap = myMap.headMap(floor); for (VirtualFile parent : floorMap.keySet()) { if (VfsUtil.isAncestor(parent, file, false)) { return floorMap.get(parent).getSecond(); } } return null; }
@Override public synchronized boolean containsFile(final VirtualFile file) { final VirtualFile floor = myMap.floorKey(file); if (floor == null) return false; final SortedMap<VirtualFile, Pair<Boolean, String>> floorMap = myMap.headMap(floor, true); for (VirtualFile parent : floorMap.keySet()) { if (VfsUtil.isAncestor(parent, file, false)) { final Pair<Boolean, String> value = floorMap.get(parent); return parent.equals(file) || value.getFirst(); } } return false; }
private String getContentRootName(final VirtualFile baseDir, final String dirName) { if (baseDir != null) { if (!Comparing.equal(myVDirectory, baseDir)) { if (VfsUtil.isAncestor(baseDir, myVDirectory, false)) { return VfsUtilCore.getRelativePath(myVDirectory, baseDir, '/'); } else { return myVDirectory.getPresentableUrl(); } } } else { return myVDirectory.getPresentableUrl(); } return dirName; }
@Nullable private static VirtualFile suggestBaseDir( @NotNull Project project, final @Nullable VirtualFile file) { final VirtualFile[] contentRoots = ProjectRootManager.getInstance(project).getContentRoots(); if (file == null && contentRoots.length > 0) { return contentRoots[0]; } if (file != null) { for (VirtualFile contentRoot : contentRoots) { if (VfsUtil.isAncestor(contentRoot, file, false)) { return contentRoot; } } } return project.getBaseDir(); }
@Override public Module getModuleByFile(VirtualFile file) { final Module module = myProjectFileIndex.getModuleForFile(file); if (module != null) { LOG.assertTrue(!module.isDisposed()); return module; } for (final VirtualFile root : myRootToModuleMap.keySet()) { if (VfsUtil.isAncestor(root, file, false)) { final Module mod = myRootToModuleMap.get(root); if (mod != null) { LOG.assertTrue(!mod.isDisposed()); } return mod; } } return null; }
private PathsList removeFrameworkStuff(Module module, List<VirtualFile> rootFiles) { final List<File> toExclude = getImplicitClasspathRoots(module); if (LOG.isDebugEnabled()) { LOG.debug("Before removing framework stuff: " + rootFiles); LOG.debug("Implicit roots:" + toExclude); } PathsList scriptClassPath = new PathsList(); eachRoot: for (VirtualFile file : rootFiles) { for (final File excluded : toExclude) { if (VfsUtil.isAncestor(excluded, VfsUtil.virtualToIoFile(file), false)) { continue eachRoot; } } scriptClassPath.add(file); } return scriptClassPath; }
@Test public void testGeneration() throws Exception { for (int i = 0; i < 100; i++) { final File f = new File(myClientRoot, "f" + i + ".txt"); f.createNewFile(); } myWorkingCopyDir.refresh(false, true); myChangeListManager.ensureUpToDate(false); final List<VirtualFile> unversionedFiles = ((ChangeListManagerImpl) myChangeListManager).getUnversionedFiles(); final Pattern pattern = Pattern.compile("f([0-9])+\\.txt"); int cnt = 0; for (VirtualFile unversionedFile : unversionedFiles) { if (VfsUtil.isAncestor(myWorkingCopyDir, unversionedFile, true)) { ++cnt; Assert.assertTrue(pattern.matcher(unversionedFile.getName()).matches()); } } Assert.assertEquals(100, cnt); }
@Override public boolean isValidAncestor( @NotNull final VirtualFile baseDir, @NotNull final VirtualFile childDir) { return VfsUtil.isAncestor(baseDir, childDir, false); }
@Override public boolean isInContent(@NotNull final VirtualFile file) { return VfsUtil.isAncestor(getBaseDir(), file, false); }