FilenameIndex supports case-insensitive search (post review: more reliable keys-value...
authorAnton Makeev <Anton.Makeev@jetbrains.com>
Sat, 11 Jul 2015 15:15:36 +0000 (17:15 +0200)
committerAnton Makeev <Anton.Makeev@jetbrains.com>
Sun, 19 Jul 2015 15:11:17 +0000 (17:11 +0200)
java/java-tests/testSrc/com/intellij/index/FilenameIndexTest.java
platform/indexing-impl/src/com/intellij/psi/search/FilenameIndex.java

index d4962dfbefcb68d2671bb3b54eeef3ab9e4bb529..dd0de6d318d435ce439953c0fdb6f5b9daf3201b 100644 (file)
@@ -23,13 +23,13 @@ import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
 public class FilenameIndexTest extends JavaCodeInsightFixtureTestCase {
   public void testCaseInsensitiveFilesByName() throws Exception {
     final VirtualFile vFile1 = myFixture.addFileToProject("dir1/foo.test", "Foo").getVirtualFile();
-    final VirtualFile vFile2 = myFixture.addFileToProject("dir2/FOO.test", "Foo").getVirtualFile();
+    final VirtualFile vFile2 = myFixture.addFileToProject("dir2/FOO.TEST", "Foo").getVirtualFile();
 
     GlobalSearchScope scope = GlobalSearchScope.projectScope(getProject());
     assertSameElements(FilenameIndex.getVirtualFilesByName(getProject(), "foo.test", true, scope), vFile1);
-    assertSameElements(FilenameIndex.getVirtualFilesByName(getProject(), "FOO.test", true, scope), vFile2);
+    assertSameElements(FilenameIndex.getVirtualFilesByName(getProject(), "FOO.TEST", true, scope), vFile2);
 
     assertSameElements(FilenameIndex.getVirtualFilesByName(getProject(), "foo.test", false, scope), vFile1, vFile2);
-    assertSameElements(FilenameIndex.getVirtualFilesByName(getProject(), "FOO.test", false, scope), vFile1, vFile2);
+    assertSameElements(FilenameIndex.getVirtualFilesByName(getProject(), "FOO.TEST", false, scope), vFile1, vFile2);
   }
 }
index b826a8b79d459a7a633cb386f72fc7a206fd29ec..88b11c19d0ef2ecd53f5e39d4934a6f8378b1d24 100644 (file)
@@ -163,18 +163,24 @@ public class FilenameIndex extends ScalarIndexExtension<String> {
   @NotNull
   private static Set<VirtualFile> getVirtualFilesByNameIgnoringCase(@NotNull final String name,
                                                                     @NotNull final GlobalSearchScope scope,
-                                                                    @Nullable IdFilter idFilter) {
-    final Set<VirtualFile> files = new THashSet<VirtualFile>();
+                                                                    @Nullable final IdFilter idFilter) {
+    final Set<String> keys = new THashSet<String>();
     final FileBasedIndex index = FileBasedIndex.getInstance();
     index.processAllKeys(NAME, new Processor<String>() {
       @Override
       public boolean process(String value) {
         if (name.equalsIgnoreCase(value)) {
-          files.addAll(index.getContainingFiles(NAME, value, scope));
+          keys.add(value);
         }
         return true;
       }
     }, scope, idFilter);
+
+    // values accessed outside of provessAllKeys 
+    final Set<VirtualFile> files = new THashSet<VirtualFile>();
+    for (String each : keys) {
+      files.addAll(index.getContainingFiles(NAME, each, scope));
+    }
     return files;
   }