Search in sources :

Example 1 with TodoItemImpl

use of com.intellij.psi.impl.search.TodoItemImpl in project intellij-community by JetBrains.

the class TodoFileNode method findAllTodos.

public static TodoItem[] findAllTodos(final PsiFile psiFile, final PsiTodoSearchHelper helper) {
    final List<TodoItem> todoItems = new ArrayList<>(Arrays.asList(helper.findTodoItems(psiFile)));
    psiFile.accept(new PsiRecursiveElementWalkingVisitor() {

        @Override
        public void visitElement(PsiElement element) {
            if (element instanceof PsiLanguageInjectionHost) {
                InjectedLanguageUtil.enumerate(element, new PsiLanguageInjectionHost.InjectedPsiVisitor() {

                    @Override
                    public void visit(@NotNull PsiFile injectedPsi, @NotNull List<PsiLanguageInjectionHost.Shred> places) {
                        if (places.size() == 1) {
                            Document document = PsiDocumentManager.getInstance(injectedPsi.getProject()).getCachedDocument(injectedPsi);
                            if (!(document instanceof DocumentWindow))
                                return;
                            for (TodoItem item : helper.findTodoItems(injectedPsi)) {
                                TextRange rangeInHost = ((DocumentWindow) document).injectedToHost(item.getTextRange());
                                todoItems.add(new TodoItemImpl(psiFile, rangeInHost.getStartOffset(), rangeInHost.getEndOffset(), item.getPattern()));
                            }
                        }
                    }
                });
            }
            super.visitElement(element);
        }
    });
    return todoItems.toArray(new TodoItem[todoItems.size()]);
}
Also used : TodoItem(com.intellij.psi.search.TodoItem) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) TodoItemImpl(com.intellij.psi.impl.search.TodoItemImpl) NotNull(org.jetbrains.annotations.NotNull) DocumentWindow(com.intellij.injected.editor.DocumentWindow)

Aggregations

DocumentWindow (com.intellij.injected.editor.DocumentWindow)1 Document (com.intellij.openapi.editor.Document)1 TextRange (com.intellij.openapi.util.TextRange)1 TodoItemImpl (com.intellij.psi.impl.search.TodoItemImpl)1 TodoItem (com.intellij.psi.search.TodoItem)1 NotNull (org.jetbrains.annotations.NotNull)1