Implemented iterateContentUnderDirectory method with additional custom VirtualFile...
authorAlexandr Evstigneev <Alexandr.Evstigneev@jetbrains.com>
Thu, 29 Dec 2016 09:27:15 +0000 (12:27 +0300)
committerAlexandr Evstigneev <Alexandr.Evstigneev@jetbrains.com>
Thu, 29 Dec 2016 09:27:15 +0000 (12:27 +0300)
platform/projectModel-api/src/com/intellij/openapi/roots/FileIndex.java
platform/projectModel-impl/src/com/intellij/openapi/roots/impl/FileIndexBase.java

index 0d8def9d6273df72381a6ca9dd09f08489ef27e9..5a177b8ccc72fa8bb8da4aeb2889415fd60aec7a 100644 (file)
@@ -17,6 +17,7 @@ package com.intellij.openapi.roots;
 
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.openapi.vfs.VirtualFileFilter;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.jps.model.module.JpsModuleSourceRootType;
 
@@ -48,6 +49,18 @@ public interface FileIndex {
   boolean iterateContentUnderDirectory(@NotNull VirtualFile dir, @NotNull ContentIterator iterator);
 
   /**
+   * Same as {@link #iterateContentUnderDirectory(VirtualFile, ContentIterator)} but allows to pass additional custom filter to the processor
+   *
+   * @param dir          the directory the contents of which is iterated.
+   * @param iterator     the iterator receiving the files.
+   * @param customFilter custom filter for files and directories
+   * @return false if files processing was stopped ({@link ContentIterator#processFile(VirtualFile)} returned false)
+   */
+  boolean iterateContentUnderDirectory(@NotNull VirtualFile dir,
+                                       @NotNull ContentIterator iterator,
+                                       @NotNull VirtualFileFilter customFilter);
+
+  /**
    * Returns {@code true} if {@code fileOrDir} is a file or directory under a content root of this project or module and not excluded or
    * ignored.
    */
index b81c6eb71c8b3f82be38a159ab7333fb74cef205..f1975b45a239680e000583fb2e969f3bf79b2b89 100644 (file)
@@ -38,8 +38,21 @@ public abstract class FileIndexBase implements FileIndex {
   protected abstract boolean isScopeDisposed();
 
   @Override
+  public boolean iterateContentUnderDirectory(@NotNull VirtualFile dir,
+                                              @NotNull ContentIterator iterator,
+                                              @NotNull VirtualFileFilter customFilter) {
+    return iterateContentUnderDirectoryWithFilter(dir, iterator, file -> myContentFilter.accept(file) && customFilter.accept(file));
+  }
+
+  @Override
   public boolean iterateContentUnderDirectory(@NotNull VirtualFile dir, @NotNull ContentIterator iterator) {
-    return VfsUtilCore.iterateChildrenRecursively(dir, myContentFilter, iterator);
+    return iterateContentUnderDirectoryWithFilter(dir, iterator, myContentFilter);
+  }
+
+  private static boolean iterateContentUnderDirectoryWithFilter(@NotNull VirtualFile dir,
+                                                                @NotNull ContentIterator iterator,
+                                                                @NotNull VirtualFileFilter filter) {
+    return VfsUtilCore.iterateChildrenRecursively(dir, filter, iterator);
   }
 
   @NotNull