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 go-lang-idea-plugin by go-lang-plugin-org.
the class GoMethodSeparatorProvider method findAnchorElement.
@NotNull
private static PsiElement findAnchorElement(@NotNull GoTopLevelDeclaration o) {
PsiElement result = o;
PsiElement p = o;
while ((p = p.getPrevSibling()) != null) {
if (p instanceof PsiComment) {
result = p;
} else if (p instanceof PsiWhiteSpace) {
if (p.getText().contains("\n\n"))
return result;
} else {
break;
}
}
return result;
}
use of com.intellij.psi.PsiComment in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoInspectionSuppressor method isSuppressedInStatement.
private static boolean isSuppressedInStatement(@NotNull String toolId, @Nullable PsiElement statement) {
if (statement != null) {
PsiElement prev = PsiTreeUtil.skipSiblingsBackward(statement, PsiWhiteSpace.class);
if (prev instanceof PsiComment) {
String text = prev.getText();
Matcher matcher = SuppressionUtil.SUPPRESS_IN_LINE_COMMENT_PATTERN.matcher(text);
return matcher.matches() && SuppressionUtil.isInspectionToolIdMentioned(matcher.group(1), toolId);
}
}
return false;
}
use of com.intellij.psi.PsiComment in project ideavim by JetBrains.
the class SearchHelper method findMatchingBlockCommentPair.
private static int findMatchingBlockCommentPair(@NotNull PsiElement element, int pos) {
final Language language = element.getLanguage();
final Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(language);
final PsiComment comment = PsiTreeUtil.getParentOfType(element, PsiComment.class, false);
if (comment != null) {
final int ret = findMatchingBlockCommentPair(comment, pos, commenter.getBlockCommentPrefix(), commenter.getBlockCommentSuffix());
if (ret >= 0) {
return ret;
}
if (commenter instanceof CodeDocumentationAwareCommenter) {
final CodeDocumentationAwareCommenter docCommenter = (CodeDocumentationAwareCommenter) commenter;
return findMatchingBlockCommentPair(comment, pos, docCommenter.getDocumentationCommentPrefix(), docCommenter.getDocumentationCommentSuffix());
}
}
return -1;
}
use of com.intellij.psi.PsiComment in project android by JetBrains.
the class AndroidBaseXmlRefactoringAction method getExtractableRange.
@Nullable
private static Pair<PsiElement, PsiElement> getExtractableRange(PsiFile file, int start, int end) {
PsiElement startElement = file.findElementAt(start);
PsiElement parent = startElement != null ? startElement.getParent() : null;
while (parent != null && !(parent instanceof PsiFile) && parent.getTextRange().getStartOffset() == startElement.getTextRange().getStartOffset()) {
startElement = parent;
parent = parent.getParent();
}
PsiElement endElement = file.findElementAt(end - 1);
parent = endElement != null ? endElement.getParent() : null;
while (parent != null && !(parent instanceof PsiFile) && parent.getTextRange().getEndOffset() == endElement.getTextRange().getEndOffset()) {
endElement = parent;
parent = parent.getParent();
}
if (startElement == null || endElement == null) {
return null;
}
final PsiElement commonParent = startElement.getParent();
if (commonParent == null || !(commonParent instanceof XmlTag) || commonParent != endElement.getParent()) {
return null;
}
PsiElement e = startElement;
boolean containTag = false;
while (e != null) {
if (!(e instanceof XmlText) && !(e instanceof XmlTag) && !(e instanceof PsiWhiteSpace) && !(e instanceof PsiComment)) {
return null;
}
if (e instanceof XmlTag) {
containTag = true;
}
if (e == endElement) {
break;
}
e = e.getNextSibling();
}
return e != null && containTag ? Pair.create(startElement, endElement) : null;
}
Aggregations