Java 类com.intellij.psi.search.IndexPatternProvider 实例源码

项目:intellij-ce-playground    文件:IndexPatternSearcher.java   
@Override
public boolean execute(@NotNull final IndexPatternSearch.SearchParameters queryParameters,
                       @NotNull final Processor<IndexPatternOccurrence> consumer) {
  final PsiFile file = queryParameters.getFile();
  VirtualFile virtualFile = file.getVirtualFile();
  if (file instanceof PsiBinaryFile || file instanceof PsiCompiledElement || virtualFile == null) {
    return true;
  }

  final TodoCacheManager cacheManager = TodoCacheManager.SERVICE.getInstance(file.getProject());
  final IndexPatternProvider patternProvider = queryParameters.getPatternProvider();
  int count = patternProvider != null
              ? cacheManager.getTodoCount(virtualFile, patternProvider)
              : cacheManager.getTodoCount(virtualFile, queryParameters.getPattern());
  return count == 0 || executeImpl(queryParameters, consumer);
}
项目:tools-idea    文件:IndexPatternSearcher.java   
@Override
public boolean execute(@NotNull final IndexPatternSearch.SearchParameters queryParameters,
                       @NotNull final Processor<IndexPatternOccurrence> consumer) {
  final PsiFile file = queryParameters.getFile();
  VirtualFile virtualFile = file.getVirtualFile();
  if (file instanceof PsiBinaryFile || file instanceof PsiCompiledElement || virtualFile == null) {
    return true;
  }

  final TodoCacheManager cacheManager = TodoCacheManager.SERVICE.getInstance(file.getProject());
  final IndexPatternProvider patternProvider = queryParameters.getPatternProvider();
  int count = patternProvider != null
              ? cacheManager.getTodoCount(virtualFile, patternProvider)
              : cacheManager.getTodoCount(virtualFile, queryParameters.getPattern());
  return count == 0 || executeImpl(queryParameters, consumer);
}
项目:tools-idea    文件:TodoConfiguration.java   
private void doSetTodoPatterns(@NotNull TodoPattern[] todoPatterns, final boolean shouldNotifyIndices) {
  TodoPattern[] oldTodoPatterns = myTodoPatterns;
  IndexPattern[] oldIndexPatterns = myIndexPatterns;

  myTodoPatterns = todoPatterns;
  buildIndexPatterns();

  // only trigger index refresh actual index patterns have changed
  if (shouldNotifyIndices && !Arrays.deepEquals(myIndexPatterns, oldIndexPatterns)) {
    final PropertyChangeEvent event =
      new PropertyChangeEvent(this, IndexPatternProvider.PROP_INDEX_PATTERNS, oldTodoPatterns, todoPatterns);
    myMessageBus.syncPublisher(IndexPatternProvider.INDEX_PATTERNS_CHANGED).propertyChange(event);
  }

  // only trigger gui and code daemon refresh when either the index patterns or presentation attributes have changed
  if (!Arrays.deepEquals(myTodoPatterns, oldTodoPatterns)) {
    final PropertyChangeListener multicaster = myPropertyChangeMulticaster.getMulticaster();
    multicaster.propertyChange(new PropertyChangeEvent(this, PROP_TODO_PATTERNS, oldTodoPatterns, todoPatterns));
  }
}
项目:consulo    文件:IndexPatternSearcher.java   
@Override
public boolean execute(@Nonnull final IndexPatternSearch.SearchParameters queryParameters,
                       @Nonnull final Processor<IndexPatternOccurrence> consumer) {
  final PsiFile file = queryParameters.getFile();
  VirtualFile virtualFile = file.getVirtualFile();
  if (file instanceof PsiBinaryFile || file instanceof PsiCompiledElement || virtualFile == null) {
    return true;
  }

  final TodoCacheManager cacheManager = TodoCacheManager.getInstance(file.getProject());
  final IndexPatternProvider patternProvider = queryParameters.getPatternProvider();
  int count = patternProvider != null
              ? cacheManager.getTodoCount(virtualFile, patternProvider)
              : cacheManager.getTodoCount(virtualFile, queryParameters.getPattern());
  return count == 0 || executeImpl(queryParameters, consumer);
}
项目:intellij-ce-playground    文件:IndexPatternSearcher.java   
protected static boolean executeImpl(IndexPatternSearch.SearchParameters queryParameters,
                                     Processor<IndexPatternOccurrence> consumer) {
  final IndexPatternProvider patternProvider = queryParameters.getPatternProvider();
  final PsiFile file = queryParameters.getFile();
  TIntArrayList commentStarts = new TIntArrayList();
  TIntArrayList commentEnds = new TIntArrayList();

  final CharSequence chars = file.getViewProvider().getContents();
  findCommentTokenRanges(file, chars, queryParameters.getRange(), commentStarts, commentEnds);
  TIntArrayList occurrences = new TIntArrayList(1);
  IndexPattern[] patterns = patternProvider != null ? patternProvider.getIndexPatterns() : null;

  for (int i = 0; i < commentStarts.size(); i++) {
    int commentStart = commentStarts.get(i);
    int commentEnd = commentEnds.get(i);
    occurrences.resetQuick();

    if (patternProvider != null) {
      for (int j = patterns.length - 1; j >=0; --j) {
        if (!collectPatternMatches(patterns[j], chars, commentStart, commentEnd, file, queryParameters.getRange(), consumer, occurrences)) {
          return false;
        }
      }
    }
    else {
      if (!collectPatternMatches(queryParameters.getPattern(), chars, commentStart, commentEnd, file, queryParameters.getRange(),
                                 consumer, occurrences)) {
        return false;
      }
    }
  }

  return true;
}
项目:intellij-ce-playground    文件:TodoIndex.java   
public TodoIndex(MessageBus messageBus, FileTypeRegistry manager) {
  myFileTypeManager = manager;
  messageBus.connect().subscribe(IndexPatternProvider.INDEX_PATTERNS_CHANGED, new PropertyChangeListener() {
    @Override
    public void propertyChange(PropertyChangeEvent evt) {
      FileBasedIndex.getInstance().requestRebuild(NAME);
    }
  });
}
项目:intellij-ce-playground    文件:IndexTodoCacheManagerImpl.java   
@Override
public int getTodoCount(@NotNull final VirtualFile file, @NotNull final IndexPatternProvider patternProvider) {
  if (myProject.isDefault()) {
    return 0;
  }
  if (file instanceof VirtualFileWindow) return -1;
  final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
  int count = 0;
  for (IndexPattern indexPattern : patternProvider.getIndexPatterns()) {
    count += fetchCount(fileBasedIndex, file, indexPattern);
  }
  return count;
}
项目:intellij-ce-playground    文件:IndexPatternUtil.java   
public static int getIndexPatternCount() {
  int patternsCount = 0;
  for(IndexPatternProvider provider: getIndexPatternProviders()) {
    patternsCount += provider.getIndexPatterns().length;
  }
  return patternsCount;
}
项目:intellij-ce-playground    文件:IndexPatternUtil.java   
public static IndexPattern[] getIndexPatterns() {
  IndexPattern[] result = new IndexPattern[getIndexPatternCount()];
  int destIndex = 0;
  for(IndexPatternProvider provider: getIndexPatternProviders()) {
    for(IndexPattern pattern: provider.getIndexPatterns()) {
      result [destIndex++] = pattern;
    }
  }
  return result;
}
项目:tools-idea    文件:IndexPatternUtil.java   
public static int getIndexPatternCount() {
  int patternsCount = 0;
  for(IndexPatternProvider provider: getIndexPatternProviders()) {
    patternsCount += provider.getIndexPatterns().length;
  }
  return patternsCount;
}
项目:tools-idea    文件:IndexPatternUtil.java   
public static IndexPattern[] getIndexPatterns() {
  IndexPattern[] result = new IndexPattern[getIndexPatternCount()];
  int destIndex = 0;
  for(IndexPatternProvider provider: getIndexPatternProviders()) {
    for(IndexPattern pattern: provider.getIndexPatterns()) {
      result [destIndex++] = pattern;
    }
  }
  return result;
}
项目:tools-idea    文件:IndexPatternSearcher.java   
protected static boolean executeImpl(IndexPatternSearch.SearchParameters queryParameters,
                                     Processor<IndexPatternOccurrence> consumer) {
  final IndexPatternProvider patternProvider = queryParameters.getPatternProvider();
  final PsiFile file = queryParameters.getFile();
  TIntArrayList commentStarts = new TIntArrayList();
  TIntArrayList commentEnds = new TIntArrayList();

  final CharSequence chars = file.getViewProvider().getContents();
  findCommentTokenRanges(file, chars, queryParameters.getRange(), commentStarts, commentEnds);

  for (int i = 0; i < commentStarts.size(); i++) {
    int commentStart = commentStarts.get(i);
    int commentEnd = commentEnds.get(i);

    if (patternProvider != null) {
      for (final IndexPattern pattern : patternProvider.getIndexPatterns()) {
        if (!collectPatternMatches(pattern, chars, commentStart, commentEnd, file, queryParameters.getRange(), consumer)) {
          return false;
        }
      }
    }
    else {
      if (!collectPatternMatches(queryParameters.getPattern(), chars, commentStart, commentEnd, file, queryParameters.getRange(),
                                 consumer)) {
        return false;
      }
    }
  }

  return true;
}
项目:tools-idea    文件:TodoIndex.java   
public TodoIndex(MessageBus messageBus) {
  messageBus.connect().subscribe(IndexPatternProvider.INDEX_PATTERNS_CHANGED, new PropertyChangeListener() {
    @Override
    public void propertyChange(PropertyChangeEvent evt) {
      FileBasedIndex.getInstance().requestRebuild(NAME);
    }
  });
}
项目:tools-idea    文件:IndexTodoCacheManagerImpl.java   
@Override
public int getTodoCount(@NotNull final VirtualFile file, final IndexPatternProvider patternProvider) {
  if (myProject.isDefault()) {
    return 0;
  }
  if (file instanceof VirtualFileWindow) return -1;
  final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
  int count = 0;
  for (IndexPattern indexPattern : patternProvider.getIndexPatterns()) {
    count += fetchCount(fileBasedIndex, file, indexPattern);
  }
  return count;
}
项目:consulo    文件:IndexPatternSearcher.java   
protected static boolean executeImpl(IndexPatternSearch.SearchParameters queryParameters,
                                     Processor<IndexPatternOccurrence> consumer) {
  final IndexPatternProvider patternProvider = queryParameters.getPatternProvider();
  final PsiFile file = queryParameters.getFile();
  TIntArrayList commentStarts = new TIntArrayList();
  TIntArrayList commentEnds = new TIntArrayList();

  final CharSequence chars = file.getViewProvider().getContents();
  findCommentTokenRanges(file, chars, queryParameters.getRange(), commentStarts, commentEnds);

  for (int i = 0; i < commentStarts.size(); i++) {
    int commentStart = commentStarts.get(i);
    int commentEnd = commentEnds.get(i);

    if (patternProvider != null) {
      for (final IndexPattern pattern : patternProvider.getIndexPatterns()) {
        if (!collectPatternMatches(pattern, chars, commentStart, commentEnd, file, queryParameters.getRange(), consumer)) {
          return false;
        }
      }
    }
    else {
      if (!collectPatternMatches(queryParameters.getPattern(), chars, commentStart, commentEnd, file, queryParameters.getRange(),
                                 consumer)) {
        return false;
      }
    }
  }

  return true;
}
项目:consulo    文件:IndexPatternUtil.java   
public static int getIndexPatternCount() {
  int patternsCount = 0;
  for(IndexPatternProvider provider: getIndexPatternProviders()) {
    patternsCount += provider.getIndexPatterns().length;
  }
  return patternsCount;
}
项目:consulo    文件:IndexPatternUtil.java   
public static IndexPattern[] getIndexPatterns() {
  IndexPattern[] result = new IndexPattern[getIndexPatternCount()];
  int destIndex = 0;
  for(IndexPatternProvider provider: getIndexPatternProviders()) {
    for(IndexPattern pattern: provider.getIndexPatterns()) {
      result [destIndex++] = pattern;
    }
  }
  return result;
}
项目:consulo    文件:IndexTodoCacheManagerImpl.java   
@Override
public int getTodoCount(@Nonnull final VirtualFile file, @Nonnull final IndexPatternProvider patternProvider) {
  if (myProject.isDefault()) {
    return 0;
  }
  if (file instanceof VirtualFileWindow) return -1;
  final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
  return Arrays.stream(patternProvider.getIndexPatterns()).mapToInt(indexPattern -> fetchCount(fileBasedIndex, file, indexPattern)).sum();
}
项目:intellij-ce-playground    文件:IndexPatternSearchImpl.java   
@Override
protected int getOccurrencesCountImpl(@NotNull PsiFile file, @NotNull IndexPatternProvider provider) {
  int count = TodoCacheManager.SERVICE.getInstance(file.getProject()).getTodoCount(file.getVirtualFile(), provider);
  if (count != -1) return count;
  return search(file, provider).findAll().size();
}
项目:intellij-ce-playground    文件:IndexPatternUtil.java   
public static IndexPatternProvider[] getIndexPatternProviders() {
  return Extensions.getExtensions(IndexPatternProvider.EP_NAME);
}
项目:intellij-ce-playground    文件:IndexPatternSearch.java   
public SearchParameters(@NotNull PsiFile file, @NotNull IndexPatternProvider patternProvider) {
  this(file, patternProvider,null);
}
项目:intellij-ce-playground    文件:IndexPatternSearch.java   
public SearchParameters(@NotNull PsiFile file, @NotNull IndexPatternProvider patternProvider, TextRange range) {
  myFile = file;
  myPatternProvider = patternProvider;
  myRange = range;
  myPattern = null;
}
项目:intellij-ce-playground    文件:IndexPatternSearch.java   
public IndexPatternProvider getPatternProvider() {
  return myPatternProvider;
}
项目:tools-idea    文件:IndexPatternUtil.java   
public static IndexPatternProvider[] getIndexPatternProviders() {
  return Extensions.getExtensions(IndexPatternProvider.EP_NAME);
}
项目:tools-idea    文件:IndexPatternSearch.java   
public SearchParameters(final PsiFile file, final IndexPatternProvider patternProvider) {
  myFile = file;
  myPatternProvider = patternProvider;
}
项目:tools-idea    文件:IndexPatternSearch.java   
public IndexPatternProvider getPatternProvider() {
  return myPatternProvider;
}
项目:tools-idea    文件:IndexPatternSearchImpl.java   
@Override
protected int getOccurrencesCountImpl(PsiFile file, IndexPatternProvider provider) {
  int count = TodoCacheManager.SERVICE.getInstance(file.getProject()).getTodoCount(file.getVirtualFile(), provider);
  if (count != -1) return count;
  return search(file, provider).findAll().size();
}
项目:consulo    文件:IndexPatternSearchImpl.java   
@Override
protected int getOccurrencesCountImpl(@Nonnull PsiFile file, @Nonnull IndexPatternProvider provider) {
  int count = TodoCacheManager.getInstance(file.getProject()).getTodoCount(file.getVirtualFile(), provider);
  if (count != -1) return count;
  return search(file, provider).findAll().size();
}
项目:consulo    文件:TodoIndex.java   
public TodoIndex(MessageBus messageBus, FileTypeRegistry manager) {
  myFileTypeManager = manager;
  messageBus.connect().subscribe(IndexPatternProvider.INDEX_PATTERNS_CHANGED, evt -> FileBasedIndex.getInstance().requestRebuild(NAME));
}
项目:consulo    文件:IndexPatternUtil.java   
public static IndexPatternProvider[] getIndexPatternProviders() {
  return Extensions.getExtensions(IndexPatternProvider.EP_NAME);
}
项目:consulo    文件:IndexPatternSearch.java   
public SearchParameters(final PsiFile file, final IndexPatternProvider patternProvider) {
  myFile = file;
  myPatternProvider = patternProvider;
}
项目:consulo    文件:IndexPatternSearch.java   
public IndexPatternProvider getPatternProvider() {
  return myPatternProvider;
}
项目:intellij-ce-playground    文件:IndexPatternSearch.java   
/**
 * Returns a query which can be used to process occurrences of any pattern from the
 * specified provider in the specified text range. The query is executed by parsing the
 * contents of the file.
 *
 * @param file            the file in which occurrences should be searched.
 * @param patternProvider the provider the patterns from which are searched.
 * @param startOffset     the start offset of the range to search.
 * @param endOffset       the end offset of the range to search.
 * @return the query instance.
 */
@NotNull
public static Query<IndexPatternOccurrence> search(@NotNull PsiFile file, @NotNull IndexPatternProvider patternProvider,
                                                   int startOffset, int endOffset) {
  final SearchParameters parameters = new SearchParameters(file, patternProvider, new TextRange(startOffset, endOffset));
  return Holder.INDEX_PATTERN_SEARCH_INSTANCE.createQuery(parameters);
}
项目:tools-idea    文件:IndexPatternSearch.java   
/**
 * Returns a query which can be used to process occurrences of any pattern from the
 * specified provider in the specified text range. The query is executed by parsing the
 * contents of the file.
 *
 * @param file            the file in which occurrences should be searched.
 * @param patternProvider the provider the patterns from which are searched.
 * @param startOffset     the start offset of the range to search.
 * @param endOffset       the end offset of the range to search.
 * @return the query instance.
 */
public static Query<IndexPatternOccurrence> search(PsiFile file, IndexPatternProvider patternProvider,
                                                   int startOffset, int endOffset) {
  final SearchParameters parameters = new SearchParameters(file, patternProvider);
  parameters.setRange(new TextRange(startOffset, endOffset));
  return INDEX_PATTERN_SEARCH_INSTANCE.createQuery(parameters);
}
项目:consulo    文件:IndexPatternSearch.java   
/**
 * Returns a query which can be used to process occurrences of any pattern from the
 * specified provider in the specified text range. The query is executed by parsing the
 * contents of the file.
 *
 * @param file            the file in which occurrences should be searched.
 * @param patternProvider the provider the patterns from which are searched.
 * @param startOffset     the start offset of the range to search.
 * @param endOffset       the end offset of the range to search.
 * @return the query instance.
 */
public static Query<IndexPatternOccurrence> search(PsiFile file, IndexPatternProvider patternProvider,
                                                   int startOffset, int endOffset) {
  final SearchParameters parameters = new SearchParameters(file, patternProvider);
  parameters.setRange(new TextRange(startOffset, endOffset));
  return INDEX_PATTERN_SEARCH_INSTANCE.createQuery(parameters);
}
项目:intellij-ce-playground    文件:TodoCacheManager.java   
/**
 * @return -1 if it's not known
 */
int getTodoCount(@NotNull VirtualFile file, @NotNull IndexPatternProvider patternProvider);
项目:intellij-ce-playground    文件:IndexPatternSearch.java   
/**
 * Returns a query which can be used to process occurrences of any pattern from the
 * specified provider in the specified file. The query is executed by parsing the
 * contents of the file.
 *
 * @param file            the file in which occurrences should be searched.
 * @param patternProvider the provider the patterns from which are searched.
 * @return the query instance.
 */
@NotNull
public static Query<IndexPatternOccurrence> search(@NotNull PsiFile file, @NotNull IndexPatternProvider patternProvider) {
  final SearchParameters parameters = new SearchParameters(file, patternProvider);
  return Holder.INDEX_PATTERN_SEARCH_INSTANCE.createQuery(parameters);
}
项目:intellij-ce-playground    文件:IndexPatternSearch.java   
/**
 * Returns the number of occurrences of any pattern from the specified provider
 * in the specified file. The returned value is taken from the index, and the file
 * is not parsed.
 *
 * @param file            the file in which occurrences should be searched.
 * @param patternProvider the provider the patterns from which are searched.
 * @return the number of pattern occurrences.
 */
public static int getOccurrencesCount(@NotNull PsiFile file, @NotNull IndexPatternProvider patternProvider) {
  return Holder.INDEX_PATTERN_SEARCH_INSTANCE.getOccurrencesCountImpl(file, patternProvider);
}
项目:tools-idea    文件:IndexPatternSearch.java   
/**
 * Returns a query which can be used to process occurrences of any pattern from the
 * specified provider in the specified file. The query is executed by parsing the
 * contents of the file.
 *
 * @param file            the file in which occurrences should be searched.
 * @param patternProvider the provider the patterns from which are searched.
 * @return the query instance.
 */
public static Query<IndexPatternOccurrence> search(PsiFile file, IndexPatternProvider patternProvider) {
  final SearchParameters parameters = new SearchParameters(file, patternProvider);
  return INDEX_PATTERN_SEARCH_INSTANCE.createQuery(parameters);
}
项目:tools-idea    文件:IndexPatternSearch.java   
/**
 * Returns the number of occurrences of any pattern from the specified provider
 * in the specified file. The returned value is taken from the index, and the file
 * is not parsed.
 *
 * @param file            the file in which occurrences should be searched.
 * @param patternProvider the provider the patterns from which are searched.
 * @return the number of pattern occurrences.
 */
public static int getOccurrencesCount(PsiFile file, IndexPatternProvider patternProvider) {
  return INDEX_PATTERN_SEARCH_INSTANCE.getOccurrencesCountImpl(file, patternProvider);
}