use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.
the class XmlDeclareIdInCommentAction method applyFix.
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
final PsiElement psiElement = descriptor.getPsiElement();
final PsiFile psiFile = psiElement.getContainingFile();
new WriteCommandAction(project, psiFile) {
@Override
protected void run(@NotNull final Result result) throws Throwable {
final XmlTag tag = PsiTreeUtil.getParentOfType(psiElement, XmlTag.class);
if (tag == null)
return;
final Language language = psiFile.getViewProvider().getBaseLanguage();
final Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(language);
if (commenter == null)
return;
final PsiFile tempFile = PsiFileFactory.getInstance(project).createFileFromText("dummy", language.getAssociatedFileType(), commenter.getBlockCommentPrefix() + "@declare id=\"" + myId + "\"" + commenter.getBlockCommentSuffix() + "\n");
final XmlTag parent = tag.getParentTag();
if (parent != null && parent.isValid()) {
final XmlTag[] tags = parent.getSubTags();
if (tags.length > 0) {
final PsiFile psi = tempFile.getViewProvider().getPsi(language);
if (psi != null) {
final PsiElement element = psi.findElementAt(1);
if (element instanceof PsiComment) {
parent.getNode().addChild(element.getNode(), tags[0].getNode());
}
}
}
}
}
}.execute();
}
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 ballerina by ballerina-lang.
the class BallerinaFoldingBuilder method addFoldingDescriptor.
private void addFoldingDescriptor(@NotNull List<FoldingDescriptor> descriptors, PsiElement node, PsiElement bodyNode) {
// Sometimes the body node might start with a comment node.
PsiElement prevSibling = bodyNode.getPrevSibling();
while (prevSibling != null && (prevSibling instanceof PsiComment || prevSibling instanceof PsiWhiteSpace)) {
prevSibling = prevSibling.getPrevSibling();
}
if (prevSibling != null) {
// Calculate the start and end offsets.
int startOffset = prevSibling.getTextRange().getStartOffset();
int endOffset = node.getTextRange().getEndOffset();
// Add the new folding descriptor.
descriptors.add(new NamedFoldingDescriptor(node, startOffset, endOffset, null, "{...}"));
}
}
use of com.intellij.psi.PsiComment in project Perl5-IDEA by Camelcade.
the class PerlTemplateContextType method isInContext.
@Override
public boolean isInContext(@NotNull PsiFile psiFile, int fileOffset) {
if (!PsiUtilCore.getLanguageAtOffset(psiFile, fileOffset).isKindOf(PerlLanguage.INSTANCE)) {
return false;
}
PsiElement element = psiFile.findElementAt(fileOffset);
if (element == null) {
element = psiFile.findElementAt(fileOffset - 1);
}
if (element == null) {
return false;
}
IElementType tokenType = PsiUtilCore.getElementType(element);
return !(element instanceof PsiWhiteSpace || element instanceof PerlStringContentElementImpl || element instanceof PsiComment || tokenType == PerlElementTypes.REGEX_TOKEN) && isInContext(element);
}
Aggregations