Search in sources :

Example 6 with TodoItem

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

the class TodoCommentInspection method checkFile.

@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
    final TodoItem[] todoItems = PsiTodoSearchHelper.SERVICE.getInstance(file.getProject()).findTodoItems(file);
    final List<ProblemDescriptor> result = new ArrayList<>();
    final THashSet<PsiComment> comments = new THashSet<>();
    for (TodoItem todoItem : todoItems) {
        final PsiComment comment = PsiTreeUtil.getParentOfType(file.findElementAt(todoItem.getTextRange().getStartOffset()), PsiComment.class, false);
        if (comment != null && comments.add(comment)) {
            result.add(manager.createProblemDescriptor(comment, InspectionsBundle.message("todo.comment.problem.descriptor"), isOnTheFly, null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
        }
    }
    return result.toArray(new ProblemDescriptor[result.size()]);
}
Also used : PsiComment(com.intellij.psi.PsiComment) TodoItem(com.intellij.psi.search.TodoItem) ArrayList(java.util.ArrayList) THashSet(gnu.trove.THashSet) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with TodoItem

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

the class TodoFileNode method createGeneralList.

private Collection<AbstractTreeNode> createGeneralList() {
    ArrayList<AbstractTreeNode> children = new ArrayList<>();
    PsiFile psiFile = getValue();
    final TodoItem[] items = findAllTodos(psiFile, myBuilder.getTodoTreeStructure().getSearchHelper());
    final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(psiFile);
    if (document != null) {
        for (final TodoItem todoItem : items) {
            if (todoItem.getTextRange().getEndOffset() < document.getTextLength() + 1) {
                final SmartTodoItemPointer pointer = new SmartTodoItemPointer(todoItem, document);
                TodoFilter todoFilter = getToDoFilter();
                if (todoFilter != null) {
                    if (todoFilter.contains(todoItem.getPattern())) {
                        children.add(new TodoItemNode(getProject(), pointer, myBuilder));
                    }
                } else {
                    children.add(new TodoItemNode(getProject(), pointer, myBuilder));
                }
            }
        }
    }
    Collections.sort(children, SmartTodoItemPointerComparator.ourInstance);
    return children;
}
Also used : TodoItem(com.intellij.psi.search.TodoItem) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Document(com.intellij.openapi.editor.Document)

Example 8 with TodoItem

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

the class CustomChangelistTodosTreeBuilder method findPatternedTodoItems.

private TodoItem[] findPatternedTodoItems(PsiFile file, final TodoFilter todoFilter) {
    if (!myIncludedFiles.contains(file))
        return EMPTY_ITEMS;
    if (myDirtyFileSet.contains(file.getVirtualFile())) {
        myMap.remove(file);
        final Change change = myChangeListManager.getChange(file.getVirtualFile());
        if (change != null) {
            final TodoCheckinHandlerWorker worker = new TodoCheckinHandlerWorker(myProject, Collections.singletonList(change), todoFilter, true);
            worker.execute();
            final List<TodoItem> todoItems = worker.inOneList();
            if (todoItems != null && !todoItems.isEmpty()) {
                for (TodoItem todoItem : todoItems) {
                    myMap.putValue(file, todoItem);
                }
            }
        }
    }
    final Collection<TodoItem> todoItems = myMap.get(file);
    return todoItems == null || todoItems.isEmpty() ? EMPTY_ITEMS : todoItems.toArray(new TodoItem[todoItems.size()]);
}
Also used : TodoItem(com.intellij.psi.search.TodoItem) Change(com.intellij.openapi.vcs.changes.Change) TodoCheckinHandlerWorker(com.intellij.openapi.vcs.checkin.TodoCheckinHandlerWorker)

Example 9 with TodoItem

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

the class GeneralHighlightingPass method highlightTodos.

static void highlightTodos(@NotNull PsiFile file, @NotNull CharSequence text, int startOffset, int endOffset, @NotNull ProgressIndicator progress, @NotNull ProperTextRange priorityRange, @NotNull Collection<HighlightInfo> insideResult, @NotNull Collection<HighlightInfo> outsideResult) {
    PsiTodoSearchHelper helper = PsiTodoSearchHelper.SERVICE.getInstance(file.getProject());
    if (helper == null || !shouldHighlightTodos(helper, file))
        return;
    TodoItem[] todoItems = helper.findTodoItems(file, startOffset, endOffset);
    if (todoItems.length == 0)
        return;
    for (TodoItem todoItem : todoItems) {
        progress.checkCanceled();
        TextRange range = todoItem.getTextRange();
        TextAttributes attributes = todoItem.getPattern().getAttributes().getTextAttributes();
        HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(HighlightInfoType.TODO).range(range);
        builder.textAttributes(attributes);
        String description = text.subSequence(range.getStartOffset(), range.getEndOffset()).toString();
        builder.description(description);
        builder.unescapedToolTip(StringUtil.shortenPathWithEllipsis(description, 1024));
        HighlightInfo info = builder.createUnconditionally();
        (priorityRange.containsRange(info.getStartOffset(), info.getEndOffset()) ? insideResult : outsideResult).add(info);
    }
}
Also used : PsiTodoSearchHelper(com.intellij.psi.search.PsiTodoSearchHelper) TodoItem(com.intellij.psi.search.TodoItem) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes)

Example 10 with TodoItem

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

the class TodoCheckinHandlerWorker method execute.

public void execute() {
    for (Change change : changes) {
        ProgressManager.checkCanceled();
        if (change.getAfterRevision() == null)
            continue;
        final VirtualFile afterFile = getFileWithRefresh(change.getAfterRevision().getFile());
        if (afterFile == null || afterFile.isDirectory() || afterFile.getFileType().isBinary())
            continue;
        myPsiFile = null;
        if (afterFile.isValid()) {
            myPsiFile = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile>() {

                @Override
                public PsiFile compute() {
                    return myPsiManager.findFile(afterFile);
                }
            });
        }
        if (myPsiFile == null) {
            mySkipped.add(Pair.create(change.getAfterRevision().getFile(), ourInvalidFile));
            continue;
        }
        myNewTodoItems = new ArrayList<>(Arrays.asList(ApplicationManager.getApplication().runReadAction(new Computable<TodoItem[]>() {

            @Override
            public TodoItem[] compute() {
                return mySearchHelper.findTodoItems(myPsiFile);
            }
        })));
        applyFilterAndRemoveDuplicates(myNewTodoItems, myTodoFilter);
        if (change.getBeforeRevision() == null) {
            // take just all todos
            if (myNewTodoItems.isEmpty())
                continue;
            myAddedOrEditedTodos.addAll(myNewTodoItems);
        } else {
            myEditedFileProcessor.process(change, myNewTodoItems);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TodoItem(com.intellij.psi.search.TodoItem) Change(com.intellij.openapi.vcs.changes.Change) Computable(com.intellij.openapi.util.Computable)

Aggregations

TodoItem (com.intellij.psi.search.TodoItem)11 Document (com.intellij.openapi.editor.Document)4 TextRange (com.intellij.openapi.util.TextRange)3 ArrayList (java.util.ArrayList)3 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)2 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)2 Change (com.intellij.openapi.vcs.changes.Change)2 NotNull (org.jetbrains.annotations.NotNull)2 DocumentWindow (com.intellij.injected.editor.DocumentWindow)1 RangeMarker (com.intellij.openapi.editor.RangeMarker)1 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)1 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)1 Computable (com.intellij.openapi.util.Computable)1 TodoCheckinHandlerWorker (com.intellij.openapi.vcs.checkin.TodoCheckinHandlerWorker)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiComment (com.intellij.psi.PsiComment)1 TodoItemImpl (com.intellij.psi.impl.search.TodoItemImpl)1 IndexPatternOccurrence (com.intellij.psi.search.IndexPatternOccurrence)1 PsiTodoSearchHelper (com.intellij.psi.search.PsiTodoSearchHelper)1 HighlightedRegion (com.intellij.ui.HighlightedRegion)1