Search in sources :

Example 41 with PsiComment

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

the class ChainedCallChunk method splitMethodCallOnChunksByDots.

@NotNull
private static List<ChainedCallChunk> splitMethodCallOnChunksByDots(@NotNull List<ASTNode> nodes) {
    List<ChainedCallChunk> result = new ArrayList<>();
    List<ASTNode> current = new ArrayList<>();
    for (ASTNode node : nodes) {
        if (node.getElementType() == JavaTokenType.DOT || node.getPsi() instanceof PsiComment) {
            if (!current.isEmpty()) {
                result.add(new ChainedCallChunk(current));
            }
            current = new ArrayList<>();
        }
        current.add(node);
    }
    if (!current.isEmpty()) {
        result.add(new ChainedCallChunk(current));
    }
    return result;
}
Also used : PsiComment(com.intellij.psi.PsiComment) ArrayList(java.util.ArrayList) ASTNode(com.intellij.lang.ASTNode) NotNull(org.jetbrains.annotations.NotNull)

Example 42 with PsiComment

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

the class SuppressionUtil method createSuppression.

public static void createSuppression(@NotNull Project project, @NotNull PsiElement container, @NotNull String id, @NotNull Language commentLanguage) {
    final String text = SUPPRESS_INSPECTIONS_TAG_NAME + " " + id;
    PsiComment comment = createComment(project, text, commentLanguage);
    container.getParent().addBefore(comment, container);
}
Also used : PsiComment(com.intellij.psi.PsiComment)

Example 43 with PsiComment

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

the class SuppressionUtil method getStatementToolSuppressedIn.

@Nullable
public static PsiElement getStatementToolSuppressedIn(@NotNull PsiElement place, @NotNull String toolId, @NotNull Class<? extends PsiElement> statementClass, @NotNull Pattern suppressInLineCommentPattern) {
    PsiElement statement = PsiTreeUtil.getNonStrictParentOfType(place, statementClass);
    if (statement != null) {
        PsiElement prev = PsiTreeUtil.skipSiblingsBackward(statement, PsiWhiteSpace.class);
        if (prev instanceof PsiComment) {
            String text = prev.getText();
            Matcher matcher = suppressInLineCommentPattern.matcher(text);
            if (matcher.matches() && isInspectionToolIdMentioned(matcher.group(1), toolId)) {
                return prev;
            }
        }
    }
    return null;
}
Also used : PsiComment(com.intellij.psi.PsiComment) Matcher(java.util.regex.Matcher) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 44 with PsiComment

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

the class LineCommentSelectioner method select.

@Override
public List<TextRange> select(PsiElement element, CharSequence editorText, int cursorOffset, Editor editor) {
    List<TextRange> result = super.select(element, editorText, cursorOffset, editor);
    PsiElement firstComment = element;
    PsiElement e = element;
    while (e.getPrevSibling() != null) {
        if (e instanceof PsiComment) {
            firstComment = e;
        } else if (!(e instanceof PsiWhiteSpace)) {
            break;
        }
        e = e.getPrevSibling();
    }
    PsiElement lastComment = element;
    e = element;
    while (e.getNextSibling() != null) {
        if (e instanceof PsiComment) {
            lastComment = e;
        } else if (!(e instanceof PsiWhiteSpace)) {
            break;
        }
        e = e.getNextSibling();
    }
    result.addAll(expandToWholeLine(editorText, new TextRange(firstComment.getTextRange().getStartOffset(), lastComment.getTextRange().getEndOffset())));
    return result;
}
Also used : PsiComment(com.intellij.psi.PsiComment) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 45 with PsiComment

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

the class GroovyStatementMover method getElementToMove.

@Nullable
private static GroovyPsiElement getElementToMove(GroovyFileBase file, int offset) {
    offset = CharArrayUtil.shiftForward(file.getText(), offset, " \t");
    PsiElement element = file.findElementAt(offset);
    final GrDocComment docComment = PsiTreeUtil.getParentOfType(element, GrDocComment.class);
    if (docComment != null) {
        final GrDocCommentOwner owner = docComment.getOwner();
        if (owner != null) {
            element = owner;
        }
    }
    if (element instanceof PsiComment) {
        element = PsiTreeUtil.nextVisibleLeaf(element);
    }
    return (GroovyPsiElement) PsiTreeUtil.findFirstParent(element, element11 -> isMoveable(element11));
}
Also used : GrMembersDeclaration(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMembersDeclaration) Document(com.intellij.openapi.editor.Document) GrCaseLabel(org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrCaseLabel) GrTypeDefinitionBody(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody) GrLiteral(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral) GrCodeBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock) GroovyFileBase(org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase) ArrayList(java.util.ArrayList) PsiRecursiveElementVisitor(com.intellij.psi.PsiRecursiveElementVisitor) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) GrStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement) GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) GrDocCommentOwner(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner) StringUtil(com.intellij.openapi.util.text.StringUtil) LineRange(com.intellij.codeInsight.editorActions.moveUpDown.LineRange) GrVariableDeclaration(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration) GrDocComment(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment) GrCaseSection(org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrCaseSection) Editor(com.intellij.openapi.editor.Editor) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) StatementUpDownMover(com.intellij.codeInsight.editorActions.moveUpDown.StatementUpDownMover) PsiComment(com.intellij.psi.PsiComment) HandlerUtils(org.jetbrains.plugins.groovy.editor.HandlerUtils) GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) NotNull(org.jetbrains.annotations.NotNull) CharArrayUtil(com.intellij.util.text.CharArrayUtil) PsiUtil(org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil) PsiComment(com.intellij.psi.PsiComment) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrDocCommentOwner(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrDocComment(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiComment (com.intellij.psi.PsiComment)60 PsiElement (com.intellij.psi.PsiElement)39 Nullable (org.jetbrains.annotations.Nullable)18 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)14 ArrayList (java.util.ArrayList)10 IElementType (com.intellij.psi.tree.IElementType)8 TextRange (com.intellij.openapi.util.TextRange)7 NotNull (org.jetbrains.annotations.NotNull)7 Matcher (java.util.regex.Matcher)6 FoldingDescriptor (com.intellij.lang.folding.FoldingDescriptor)5 PsiFile (com.intellij.psi.PsiFile)5 ASTNode (com.intellij.lang.ASTNode)4 Document (com.intellij.openapi.editor.Document)4 PsiDocComment (com.intellij.psi.javadoc.PsiDocComment)4 LineRange (com.intellij.codeInsight.editorActions.moveUpDown.LineRange)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