Java 类com.intellij.psi.impl.cache.impl.id.IdIndex 实例源码

项目:intellij-ce-playground    文件:PsiSearchHelperImpl.java   
private static boolean processFilesContainingAllKeys(@NotNull Project project,
                                                     @NotNull final GlobalSearchScope scope,
                                                     @Nullable final Condition<Integer> checker,
                                                     @NotNull final Collection<IdIndexEntry> keys,
                                                     @NotNull final Processor<VirtualFile> processor) {
  final FileIndexFacade index = FileIndexFacade.getInstance(project);
  return DumbService.getInstance(project).runReadActionInSmartMode(new Computable<Boolean>() {
    @Override
    public Boolean compute() {
      return FileBasedIndex.getInstance().processFilesContainingAllKeys(IdIndex.NAME, keys, scope, checker, new Processor<VirtualFile>() {
        @Override
        public boolean process(VirtualFile file) {
          return !index.shouldBeFound(scope, file) || processor.process(file);
        }
      });
    }
  });
}
项目:tools-idea    文件:IdCacheTest.java   
@Override
protected void setUp() throws Exception {
  super.setUp();

  FileBasedIndex.getInstance().requestRebuild(IdIndex.NAME);
  FileBasedIndex.getInstance().requestRebuild(TodoIndex.NAME);

  String root = JavaTestUtil.getJavaTestDataPath()+ "/psi/impl/cache/";

  PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
  myRootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);

  myCacheFile = FileUtil.createTempFile("cache", "");
  myCacheFile.delete();
  myFilesToDelete.add(myCacheFile);
}
项目:consulo-java    文件:IdCacheTest.java   
@Override
protected void setUp() throws Exception {
  super.setUp();

  FileBasedIndex.getInstance().requestRebuild(IdIndex.NAME);
  FileBasedIndex.getInstance().requestRebuild(TodoIndex.NAME);

  String root = JavaTestUtil.getJavaTestDataPath()+ "/psi/impl/cache/";

  PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
  myRootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);

  myCacheFile = FileUtil.createTempFile("cache", "");
  myCacheFile.delete();
  myFilesToDelete.add(myCacheFile);
}
项目:intellij-ce-playground    文件:IndexCacheManagerImpl.java   
private boolean collectVirtualFilesWithWord(@NotNull final Processor<VirtualFile> fileProcessor,
                                           @NotNull final String word, final short occurrenceMask,
                                           @NotNull final GlobalSearchScope scope, final boolean caseSensitively) {
  if (myProject.isDefault()) {
    return true;
  }

  try {
    return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
      @Override
      public Boolean compute() {
        return FileBasedIndex.getInstance().processValues(IdIndex.NAME, new IdIndexEntry(word, caseSensitively), null, new FileBasedIndex.ValueProcessor<Integer>() {
          final FileIndexFacade index = FileIndexFacade.getInstance(myProject);
          @Override
          public boolean process(final VirtualFile file, final Integer value) {
            ProgressIndicatorProvider.checkCanceled();
            final int mask = value.intValue();
            if ((mask & occurrenceMask) != 0 && index.shouldBeFound(scope, file)) {
              if (!fileProcessor.process(file)) return false;
            }
            return true;
          }
        }, scope);
      }
    });
  }
  catch (IndexNotReadyException e) {
    throw new ProcessCanceledException();
  }
}
项目:intellij-ce-playground    文件:FileBasedIndexImpl.java   
@NotNull
private <K, V> UpdatableIndex<K, V, FileContent> createIndex(@NotNull final ID<K, V> indexId,
                                                             @NotNull final FileBasedIndexExtension<K, V> extension,
                                                             @NotNull final MemoryIndexStorage<K, V> storage)
  throws StorageException, IOException {
  final MapReduceIndex<K, V, FileContent> index;
  if (extension instanceof CustomImplementationFileBasedIndexExtension) {
    final UpdatableIndex<K, V, FileContent> custom =
      ((CustomImplementationFileBasedIndexExtension<K, V, FileContent>)extension).createIndexImplementation(indexId, this, storage);
    if (!(custom instanceof MapReduceIndex)) {
      return custom;
    }
    index = (MapReduceIndex<K, V, FileContent>)custom;
  }
  else {
    DataExternalizer<Collection<K>> externalizer =
      extension.hasSnapshotMapping() && IdIndex.ourSnapshotMappingsEnabled
      ? createInputsIndexExternalizer(extension, indexId, extension.getKeyDescriptor())
      : null;
    index = new MapReduceIndex<K, V, FileContent>(
      indexId, extension.getIndexer(), storage, externalizer, extension.getValueExternalizer(), extension instanceof PsiDependentIndex);
  }
  index.setInputIdToDataKeysIndex(new Factory<PersistentHashMap<Integer, Collection<K>>>() {
    @Override
    public PersistentHashMap<Integer, Collection<K>> create() {
      try {
        return createIdToDataKeysIndex(extension, storage);
      }
      catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
  });

  return index;
}
项目:tools-idea    文件:UpdateCacheTest.java   
@Override
protected void setUp() throws Exception {
  super.setUp();

  FileBasedIndex.getInstance().requestRebuild(IdIndex.NAME);
  FileBasedIndex.getInstance().requestRebuild(TodoIndex.NAME);
}
项目:tools-idea    文件:PsiSearchHelperImpl.java   
@NotNull
private static MultiMap<VirtualFile, RequestWithProcessor> findFilesWithIndexEntry(@NotNull final IdIndexEntry entry,
                                                                                   @NotNull final FileIndexFacade index,
                                                                                   @NotNull final Collection<RequestWithProcessor> data,
                                                                                   @NotNull final GlobalSearchScope commonScope,
                                                                                   final ProgressIndicator progress) {
  final MultiMap<VirtualFile, RequestWithProcessor> local = createMultiMap();
  ApplicationManager.getApplication().runReadAction(new Runnable() {
    @Override
    public void run() {
      if (progress != null) progress.checkCanceled();
      FileBasedIndex.getInstance().processValues(IdIndex.NAME, entry, null, new FileBasedIndex.ValueProcessor<Integer>() {
          @Override
          public boolean process(VirtualFile file, Integer value) {
            if (progress != null) progress.checkCanceled();

            if (index.shouldBeFound(commonScope, file)) {
              int mask = value.intValue();
              for (RequestWithProcessor single : data) {
                final PsiSearchRequest request = single.request;
                if ((mask & request.searchContext) != 0 && ((GlobalSearchScope)request.searchScope).contains(file)) {
                  local.putValue(file, single);
                }
              }
            }
            return true;
          }
        }, commonScope);
    }
  });

  return local;
}
项目:tools-idea    文件:PsiSearchHelperImpl.java   
private static boolean processFilesContainingAllKeys(@NotNull final GlobalSearchScope scope,
                                                     @Nullable final Condition<Integer> checker,
                                                     @NotNull final Processor<VirtualFile> processor,
                                                     @NotNull final Collection<IdIndexEntry> keys) {
  return ApplicationManager.getApplication().runReadAction(new NullableComputable<Boolean>() {
    @Override
    public Boolean compute() {
      return FileBasedIndex.getInstance().processFilesContainingAllKeys(IdIndex.NAME, keys, scope, checker, processor);
    }
  });
}
项目:tools-idea    文件:IndexCacheManagerImpl.java   
private boolean collectVirtualFilesWithWord(@NotNull final Processor<VirtualFile> fileProcessor,
                                           @NotNull final String word, final short occurrenceMask,
                                           @NotNull final GlobalSearchScope scope, final boolean caseSensitively) {
  if (myProject.isDefault()) {
    return true;
  }

  try {
    return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
      @Override
      public Boolean compute() {
        return FileBasedIndex.getInstance().processValues(IdIndex.NAME, new IdIndexEntry(word, caseSensitively), null, new FileBasedIndex.ValueProcessor<Integer>() {
          final FileIndexFacade index = FileIndexFacade.getInstance(myProject);
          @Override
          public boolean process(final VirtualFile file, final Integer value) {
            ProgressIndicatorProvider.checkCanceled();
            final int mask = value.intValue();
            if ((mask & occurrenceMask) != 0 && index.shouldBeFound(scope, file)) {
              if (!fileProcessor.process(file)) return false;
            }
            return true;
          }
        }, scope);
      }
    });
  }
  catch (IndexNotReadyException e) {
    throw new ProcessCanceledException();
  }
}
项目:consulo    文件:PsiSearchHelperImpl.java   
private void collectFiles(@Nonnull MultiMap<Set<IdIndexEntry>, RequestWithProcessor> singles,
                          @Nonnull ProgressIndicator progress,
                          @Nonnull final MultiMap<VirtualFile, RequestWithProcessor> intersectionResult,
                          @Nonnull final MultiMap<VirtualFile, RequestWithProcessor> restResult) {
  for (Map.Entry<Set<IdIndexEntry>, Collection<RequestWithProcessor>> entry : singles.entrySet()) {
    final Set<IdIndexEntry> keys = entry.getKey();
    if (keys.isEmpty()) {
      continue;
    }

    final Collection<RequestWithProcessor> processors = entry.getValue();
    final GlobalSearchScope commonScope = uniteScopes(processors);
    final Set<VirtualFile> intersectionWithContainerNameFiles = intersectionWithContainerNameFiles(commonScope, processors, keys);

    List<VirtualFile> result = new ArrayList<>();
    Processor<VirtualFile> processor = Processors.cancelableCollectProcessor(result);
    processFilesContainingAllKeys(myManager.getProject(), commonScope, null, keys, processor);
    for (final VirtualFile file : result) {
      progress.checkCanceled();
      for (final IdIndexEntry indexEntry : keys) {
        myDumbService.runReadActionInSmartMode(
                () -> FileBasedIndex.getInstance().processValues(IdIndex.NAME, indexEntry, file, (file1, value) -> {
                  int mask = value.intValue();
                  for (RequestWithProcessor single : processors) {
                    final PsiSearchRequest request = single.request;
                    if ((mask & request.searchContext) != 0 && request.searchScope.contains(file1)) {
                      MultiMap<VirtualFile, RequestWithProcessor> result1 =
                              intersectionWithContainerNameFiles == null || !intersectionWithContainerNameFiles.contains(file1) ? restResult : intersectionResult;
                      result1.putValue(file1, single);
                    }
                  }
                  return true;
                }, commonScope));
      }
    }
  }
}
项目:consulo    文件:PsiSearchHelperImpl.java   
private static boolean processFilesContainingAllKeys(@Nonnull Project project,
                                                     @Nonnull final GlobalSearchScope scope,
                                                     @javax.annotation.Nullable final Condition<Integer> checker,
                                                     @Nonnull final Collection<IdIndexEntry> keys,
                                                     @Nonnull final Processor<VirtualFile> processor) {
  final FileIndexFacade index = FileIndexFacade.getInstance(project);
  return DumbService.getInstance(project).runReadActionInSmartMode(
          () -> FileBasedIndex.getInstance().processFilesContainingAllKeys(IdIndex.NAME, keys, scope, checker,
                                                                           file -> !index.shouldBeFound(scope, file) || processor.process(file)));
}
项目:consulo    文件:IndexCacheManagerImpl.java   
private boolean collectVirtualFilesWithWord(@Nonnull final Processor<VirtualFile> fileProcessor,
                                            @Nonnull final String word, final short occurrenceMask,
                                            @Nonnull final GlobalSearchScope scope, final boolean caseSensitively) {
  if (myProject.isDefault()) {
    return true;
  }

  try {
    return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
      @Override
      public Boolean compute() {
        return FileBasedIndex.getInstance().processValues(IdIndex.NAME, new IdIndexEntry(word, caseSensitively), null, new FileBasedIndex.ValueProcessor<Integer>() {
          final FileIndexFacade index = FileIndexFacade.getInstance(myProject);
          @Override
          public boolean process(final VirtualFile file, final Integer value) {
            ProgressIndicatorProvider.checkCanceled();
            final int mask = value.intValue();
            if ((mask & occurrenceMask) != 0 && index.shouldBeFound(scope, file)) {
              if (!fileProcessor.process(file)) return false;
            }
            return true;
          }
        }, scope);
      }
    });
  }
  catch (IndexNotReadyException e) {
    throw new ProcessCanceledException();
  }
}
项目:consulo    文件:VfsAwareMapReduceIndex.java   
@Nullable
private static <Key, Value> ForwardIndex<Key, Value> getForwardIndex(@Nonnull IndexExtension<Key, Value, ?> indexExtension)
        throws IOException {
  final boolean hasSnapshotMapping = indexExtension instanceof FileBasedIndexExtension &&
                                     ((FileBasedIndexExtension<Key, Value>)indexExtension).hasSnapshotMapping() &&
                                     IdIndex.ourSnapshotMappingsEnabled;
  if (hasSnapshotMapping) return null;

  MapBasedForwardIndex<Key, Value> backgroundIndex =
          !SharedIndicesData.ourFileSharedIndicesEnabled || SharedIndicesData.DO_CHECKS ? new MyForwardIndex<>(indexExtension) : null;
  return new SharedMapBasedForwardIndex<>(indexExtension, backgroundIndex);
}
项目:consulo-java    文件:UpdateCacheTest.java   
@Override
protected void setUp() throws Exception {
  super.setUp();

  FileBasedIndex.getInstance().requestRebuild(IdIndex.NAME);
  FileBasedIndex.getInstance().requestRebuild(TodoIndex.NAME);
}
项目:intellij-ce-playground    文件:TrigramIndex.java   
@Override
public int getVersion() {
  return ENABLED ? 3 + (IdIndex.ourSnapshotMappingsEnabled ? 0xFF:0) : 1;
}
项目:consulo    文件:TrigramIndex.java   
@Override
public int getVersion() {
  return ENABLED ? 3 + (IdIndex.ourSnapshotMappingsEnabled ? 0xFF:0) : 1;
}