@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); }
@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); }
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; }
@Override @NotNull public TodoItem[] findTodoItems(@NotNull PsiFile file, int startOffset, int endOffset) { final Collection<IndexPatternOccurrence> occurrences = IndexPatternSearch.search(file, TodoIndexPatternProvider.getInstance()).findAll(); if (occurrences.isEmpty()) { return EMPTY_TODO_ITEMS; } return processTodoOccurences(startOffset, endOffset, occurrences); }
@NotNull @Override public TodoItem[] findTodoItemsLight(@NotNull PsiFile file, int startOffset, int endOffset) { final Collection<IndexPatternOccurrence> occurrences = LightIndexPatternSearch.SEARCH.createQuery(new IndexPatternSearch.SearchParameters(file, TodoIndexPatternProvider.getInstance())).findAll(); if (occurrences.isEmpty()) { return EMPTY_TODO_ITEMS; } return processTodoOccurences(startOffset, endOffset, occurrences); }
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; }
@Override @Nonnull public TodoItem[] findTodoItems(@Nonnull PsiFile file, int startOffset, int endOffset) { final Collection<IndexPatternOccurrence> occurrences = IndexPatternSearch.search(file, TodoIndexPatternProvider.getInstance()).findAll(); if (occurrences.isEmpty()) { return EMPTY_TODO_ITEMS; } return processTodoOccurences(startOffset, endOffset, occurrences); }
@Nonnull @Override public TodoItem[] findTodoItemsLight(@Nonnull PsiFile file, int startOffset, int endOffset) { final Collection<IndexPatternOccurrence> occurrences = LightIndexPatternSearch.SEARCH.createQuery(new IndexPatternSearch.SearchParameters(file, TodoIndexPatternProvider.getInstance())).findAll(); if (occurrences.isEmpty()) { return EMPTY_TODO_ITEMS; } return processTodoOccurences(startOffset, endOffset, occurrences); }
@Override public boolean execute(@NotNull IndexPatternSearch.SearchParameters queryParameters, @NotNull Processor<IndexPatternOccurrence> consumer) { return executeImpl(queryParameters, consumer); }
private void checkEditedFragment(TodoItem newTodoItem) { if (myBeforeFile == null) { myBeforeFile = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile>() { @Override public PsiFile compute() { return myPsiFileFactory.createFileFromText("old" + myAfterFile.getName(), myAfterFile.getFileType(), myBeforeContent); } }); } if (myOldItems == null) { final Collection<IndexPatternOccurrence> all = LightIndexPatternSearch.SEARCH.createQuery(new IndexPatternSearch.SearchParameters(myBeforeFile, TodoIndexPatternProvider .getInstance())).findAll(); final TodoItemsCreator todoItemsCreator = new TodoItemsCreator(); myOldItems = new ArrayList<TodoItem>(); if (all.isEmpty()) { myAcceptor.addedOrEdited(newTodoItem); return; } for (IndexPatternOccurrence occurrence : all) { myOldItems.add(todoItemsCreator.createTodo(occurrence)); } applyFilterAndRemoveDuplicates(myOldItems, myTodoFilter); } if (myOldTodoTexts == null) { final StepIntersection<LineFragment, TodoItem> intersection = new StepIntersection<LineFragment, TodoItem>( LineFragmentConvertor.getInstance(), TodoItemConvertor.getInstance(), myOldItems, new Getter<String>() { @Override public String get() { return myBeforeContent; } }); myOldTodoTexts = new HashSet<String>(); intersection.process(Collections.singletonList(myCurrentLineFragment), new PairConsumer<LineFragment, TodoItem>() { @Override public void consume(LineFragment lineFragment, TodoItem todoItem) { myOldTodoTexts.add(getTodoText(todoItem, myBeforeContent)); } }); } final String text = getTodoText(newTodoItem, myAfterContent); if (! myOldTodoTexts.contains(text)) { myAcceptor.addedOrEdited(newTodoItem); } else { myAcceptor.inChanged(newTodoItem); } }
private void checkEditedFragment(TodoItem newTodoItem) { if (myBeforeFile == null) { myBeforeFile = myPsiFileFactory.createFileFromText("old" + myAfterFile.getName(), myAfterFile.getFileType(), myBeforeContent); } if (myOldItems == null) { final Collection<IndexPatternOccurrence> all = LightIndexPatternSearch.SEARCH.createQuery(new IndexPatternSearch.SearchParameters(myBeforeFile, TodoIndexPatternProvider .getInstance())).findAll(); final TodoItemsCreator todoItemsCreator = new TodoItemsCreator(); myOldItems = new ArrayList<TodoItem>(); if (all.isEmpty()) { myAcceptor.addedOrEdited(newTodoItem); return; } for (IndexPatternOccurrence occurrence : all) { myOldItems.add(todoItemsCreator.createTodo(occurrence)); } applyFilterAndRemoveDuplicates(myOldItems, myTodoFilter); } if (myOldTodoTexts == null) { final StepIntersection<LineFragment, TodoItem> intersection = new StepIntersection<LineFragment, TodoItem>( LineFragmentConvertor.getInstance(), TodoItemConvertor.getInstance(), myOldItems, new Getter<String>() { @Override public String get() { return myBeforeContent; } }); myOldTodoTexts = new HashSet<String>(); intersection.process(Collections.singletonList(myCurrentLineFragment), new PairConsumer<LineFragment, TodoItem>() { @Override public void consume(LineFragment lineFragment, TodoItem todoItem) { myOldTodoTexts.add(getTodoText(todoItem, myBeforeContent)); } }); } final String text = getTodoText(newTodoItem, myAfterContent); if (! myOldTodoTexts.contains(text)) { myAcceptor.addedOrEdited(newTodoItem); } else { myAcceptor.inChanged(newTodoItem); } }
@Override public boolean execute(@Nonnull IndexPatternSearch.SearchParameters queryParameters, @Nonnull Processor<IndexPatternOccurrence> consumer) { return executeImpl(queryParameters, consumer); }
public void testTodo() throws Throwable { configureByFile(); final IndexPattern indexPattern = new IndexPattern("TODO", true); assertEquals(2, IndexPatternSearch.search(myFixture.getFile(), indexPattern).toArray(new IndexPatternOccurrence[0]).length); }