use of com.intellij.psi.PsiComment in project kotlin by JetBrains.
the class UpdateKotlinCopyright method scanFile.
@Override
protected void scanFile() {
PsiElement first = getFile().getFirstChild();
PsiElement last = first;
PsiElement next = first;
while (next != null) {
if (next instanceof PsiComment || next instanceof PsiWhiteSpace) {
next = getNextSibling(next);
} else {
break;
}
last = next;
}
if (first != null) {
checkComments(first, last, true);
}
}
use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.
the class AbstractSuppressByNoInspectionCommentFix method invoke.
@Override
public void invoke(@NotNull final Project project, @Nullable Editor editor, @NotNull final PsiElement element) throws IncorrectOperationException {
PsiElement container = getContainer(element);
if (container == null)
return;
final List<? extends PsiElement> comments = getCommentsFor(container);
if (comments != null) {
for (PsiElement comment : comments) {
if (comment instanceof PsiComment && SuppressionUtil.isSuppressionComment(comment)) {
replaceSuppressionComment(comment);
return;
}
}
}
boolean caretWasBeforeStatement = editor != null && editor.getCaretModel().getOffset() == container.getTextRange().getStartOffset();
try {
createSuppression(project, element, container);
} catch (IncorrectOperationException e) {
if (!ApplicationManager.getApplication().isUnitTestMode() && editor != null) {
Messages.showErrorDialog(editor.getComponent(), InspectionsBundle.message("suppress.inspection.annotation.syntax.error", e.getMessage()));
}
}
if (caretWasBeforeStatement) {
editor.getCaretModel().moveToOffset(container.getTextRange().getStartOffset());
}
UndoUtil.markPsiFileForUndo(element.getContainingFile());
}
use of com.intellij.psi.PsiComment 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.PsiComment in project intellij-community by JetBrains.
the class PsiCommentManipulator method handleContentChange.
@Override
public PsiComment handleContentChange(@NotNull PsiComment psiComment, @NotNull TextRange range, String newContent) throws IncorrectOperationException {
String oldText = psiComment.getText();
String newText = oldText.substring(0, range.getStartOffset()) + newContent + oldText.substring(range.getEndOffset());
FileType type = psiComment.getContainingFile().getFileType();
PsiFile fromText = PsiFileFactory.getInstance(psiComment.getProject()).createFileFromText("__." + type.getDefaultExtension(), type, newText);
PsiComment newElement = PsiTreeUtil.getParentOfType(fromText.findElementAt(0), psiComment.getClass(), false);
assert newElement != null : type + " " + type.getDefaultExtension() + " " + newText;
return (PsiComment) psiComment.replace(newElement);
}
use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.
the class DuplocatorUtil method isIgnoredNode.
public static boolean isIgnoredNode(PsiElement element) {
if (element instanceof PsiWhiteSpace || element instanceof PsiErrorElement || element instanceof PsiComment) {
return true;
}
if (!(element instanceof LeafElement)) {
return false;
}
if (CharArrayUtil.containsOnlyWhiteSpaces(element.getText())) {
return true;
}
EquivalenceDescriptorProvider descriptorProvider = EquivalenceDescriptorProvider.getInstance(element);
if (descriptorProvider == null) {
return false;
}
final IElementType elementType = ((LeafElement) element).getElementType();
return descriptorProvider.getIgnoredTokens().contains(elementType);
}
Aggregations