use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.
the class GroovySuppressableInspectionTool method getElementToolSuppressedIn.
@Nullable
public static PsiElement getElementToolSuppressedIn(final PsiElement place, @NotNull String toolId) {
if (place == null)
return null;
AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
try {
final PsiElement statement = PsiUtil.findEnclosingStatement(place);
if (statement != null) {
PsiElement prev = statement.getPrevSibling();
while (prev != null && StringUtil.isEmpty(prev.getText().trim())) {
prev = prev.getPrevSibling();
}
if (prev instanceof PsiComment) {
String text = prev.getText();
Matcher matcher = SuppressionUtil.SUPPRESS_IN_LINE_COMMENT_PATTERN.matcher(text);
if (matcher.matches() && SuppressionUtil.isInspectionToolIdMentioned(matcher.group(1), toolId)) {
return prev;
}
}
}
GrMember member = null;
GrDocComment docComment = PsiTreeUtil.getParentOfType(place, GrDocComment.class);
if (docComment != null) {
GrDocCommentOwner owner = docComment.getOwner();
if (owner instanceof GrMember) {
member = (GrMember) owner;
}
}
if (member == null) {
member = PsiTreeUtil.getNonStrictParentOfType(place, GrMember.class);
}
while (member != null) {
GrModifierList modifierList = member.getModifierList();
for (String ids : getInspectionIdsSuppressedInAnnotation(modifierList)) {
if (SuppressionUtil.isInspectionToolIdMentioned(ids, toolId)) {
return modifierList;
}
}
member = PsiTreeUtil.getParentOfType(member, GrMember.class);
}
return null;
} finally {
accessToken.finish();
}
}
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 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);
}
use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.
the class CommentBreakerEnterProcessor method doEnter.
@Override
public boolean doEnter(Editor editor, PsiElement psiElement, boolean isModified) {
if (isModified)
return false;
final PsiElement atCaret = psiElement.getContainingFile().findElementAt(editor.getCaretModel().getOffset());
final PsiComment comment = PsiTreeUtil.getParentOfType(atCaret, PsiComment.class, false);
if (comment != null) {
plainEnter(editor);
if (comment.getTokenType() == JavaTokenType.END_OF_LINE_COMMENT) {
EditorModificationUtil.insertStringAtCaret(editor, "// ");
}
return true;
}
return false;
}
Aggregations