Search in sources :

Example 1 with PsiComment

use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.

the class GroovyStatementMover method nlsAfter.

private static boolean nlsAfter(@Nullable PsiElement element) {
    if (element == null)
        return false;
    PsiElement sibling = element;
    while (true) {
        sibling = PsiTreeUtil.nextLeaf(sibling);
        if (sibling == null) {
            //eof
            return true;
        }
        final String text = sibling.getText();
        if (text.contains("\n")) {
            return text.charAt(CharArrayUtil.shiftForward(text, 0, " \t")) == '\n';
        }
        if (!(sibling instanceof PsiComment) && !StringUtil.isEmptyOrSpaces(text) && !text.equals(";")) {
            return false;
        }
    }
}
Also used : PsiComment(com.intellij.psi.PsiComment) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 2 with PsiComment

use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.

the class CStyleCommentPredicate method satisfiedBy.

@Override
public boolean satisfiedBy(PsiElement element) {
    if (!(element instanceof PsiComment)) {
        return false;
    }
    if (element instanceof PsiDocComment) {
        return false;
    }
    final PsiComment comment = (PsiComment) element;
    final IElementType type = comment.getTokenType();
    if (!GroovyTokenTypes.mML_COMMENT.equals(type)) {
        return false;
    }
    final PsiElement sibling = PsiTreeUtil.nextLeaf(comment);
    if (sibling == null) {
        return true;
    }
    if (!(isWhitespace(sibling))) {
        return false;
    }
    final String whitespaceText = sibling.getText();
    return whitespaceText.indexOf((int) '\n') >= 0 || whitespaceText.indexOf((int) '\r') >= 0;
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) IElementType(com.intellij.psi.tree.IElementType) PsiComment(com.intellij.psi.PsiComment) PsiElement(com.intellij.psi.PsiElement)

Example 3 with PsiComment

use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.

the class ChangeToCStyleCommentIntention method isEndOfLineComment.

private boolean isEndOfLineComment(PsiElement element) {
    if (!(element instanceof PsiComment)) {
        return false;
    }
    final PsiComment comment = (PsiComment) element;
    final IElementType tokenType = comment.getTokenType();
    return GroovyTokenTypes.mSL_COMMENT.equals(tokenType);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiComment(com.intellij.psi.PsiComment)

Example 4 with PsiComment

use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.

the class IdRefReference method getIdValue.

@Nullable
protected String getIdValue(final PsiElement element) {
    if (element instanceof XmlTag) {
        final XmlTag tag = (XmlTag) element;
        String s = tag.getAttributeValue(IdReferenceProvider.ID_ATTR_NAME);
        if (!myIdAttrsOnly) {
            if (s == null)
                s = tag.getAttributeValue(IdReferenceProvider.NAME_ATTR_NAME);
            if (s == null)
                s = tag.getAttributeValue(IdReferenceProvider.STYLE_ID_ATTR_NAME);
        }
        return s != null ? s : getImplicitIdRefValue(tag);
    } else if (element instanceof PsiComment) {
        return getImplicitIdValue((PsiComment) element);
    }
    return null;
}
Also used : PsiComment(com.intellij.psi.PsiComment) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with PsiComment

use of com.intellij.psi.PsiComment in project kotlin by JetBrains.

the class KotlinDeclarationMover method getElementSourceLineRange.

@Override
protected LineRange getElementSourceLineRange(@NotNull PsiElement element, @NotNull Editor editor, @NotNull LineRange oldRange) {
    PsiElement first;
    PsiElement last;
    if (element instanceof KtDeclaration) {
        first = element.getFirstChild();
        last = element.getLastChild();
        if (first == null || last == null)
            return null;
    } else {
        first = last = element;
    }
    TextRange textRange1 = first.getTextRange();
    TextRange textRange2 = last.getTextRange();
    Document doc = editor.getDocument();
    if (doc.getTextLength() < textRange2.getEndOffset())
        return null;
    int startLine = editor.offsetToLogicalPosition(textRange1.getStartOffset()).line;
    int endLine = editor.offsetToLogicalPosition(textRange2.getEndOffset()).line + 1;
    if (element instanceof PsiComment || startLine == oldRange.startLine || startLine == oldRange.endLine || endLine == oldRange.startLine || endLine == oldRange.endLine) {
        return new LineRange(startLine, endLine);
    }
    TextRange lineTextRange = new TextRange(doc.getLineStartOffset(oldRange.startLine), doc.getLineEndOffset(oldRange.endLine));
    if (element instanceof KtDeclaration) {
        for (PsiElement anchor : getDeclarationAnchors((KtDeclaration) element)) {
            TextRange suspectTextRange = anchor.getTextRange();
            if (suspectTextRange != null && lineTextRange.intersects(suspectTextRange))
                return new LineRange(startLine, endLine);
        }
    }
    return null;
}
Also used : PsiComment(com.intellij.psi.PsiComment) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) LineRange(com.intellij.codeInsight.editorActions.moveUpDown.LineRange) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiComment (com.intellij.psi.PsiComment)68 PsiElement (com.intellij.psi.PsiElement)47 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)21 Nullable (org.jetbrains.annotations.Nullable)19 IElementType (com.intellij.psi.tree.IElementType)11 ArrayList (java.util.ArrayList)11 TextRange (com.intellij.openapi.util.TextRange)9 PsiFile (com.intellij.psi.PsiFile)8 NotNull (org.jetbrains.annotations.NotNull)8 FoldingDescriptor (com.intellij.lang.folding.FoldingDescriptor)7 ASTNode (com.intellij.lang.ASTNode)6 Matcher (java.util.regex.Matcher)6 Document (com.intellij.openapi.editor.Document)4 LineRange (com.intellij.codeInsight.editorActions.moveUpDown.LineRange)3 PsiDocComment (com.intellij.psi.javadoc.PsiDocComment)3 XmlTag (com.intellij.psi.xml.XmlTag)3 Commenter (com.intellij.lang.Commenter)2 Language (com.intellij.lang.Language)2 Editor (com.intellij.openapi.editor.Editor)2 UnfairTextRange (com.intellij.openapi.util.UnfairTextRange)2