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()]);
}
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;
}
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()]);
}
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);
}
}
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);
}
}
}
Aggregations