Search in sources :

Example 91 with PsiElement

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

the class GroovyBlockGenerator method calculateAlignments.

private void calculateAlignments(List<ASTNode> children, boolean classLevel) {
    List<GrStatement> currentGroup = null;
    boolean spock = true;
    for (ASTNode child : children) {
        PsiElement psi = child.getPsi();
        if (psi instanceof GrLabeledStatement) {
            alignGroup(currentGroup, spock, classLevel);
            currentGroup = ContainerUtil.newArrayList();
            spock = true;
        } else if (currentGroup != null && spock && isTablePart(psi)) {
            currentGroup.add((GrStatement) psi);
        } else if (psi instanceof GrVariableDeclaration) {
            GrVariable[] variables = ((GrVariableDeclaration) psi).getVariables();
            if (variables.length > 0) {
                if (!classLevel || currentGroup == null || fieldGroupEnded(psi) || spock) {
                    alignGroup(currentGroup, spock, classLevel);
                    currentGroup = ContainerUtil.newArrayList();
                    spock = false;
                }
                currentGroup.add((GrStatement) psi);
            }
        } else {
            if (shouldSkip(classLevel, psi))
                continue;
            alignGroup(currentGroup, spock, classLevel);
            currentGroup = null;
        }
    }
    if (currentGroup != null) {
        alignGroup(currentGroup, spock, classLevel);
    }
}
Also used : GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) GrVariableDeclaration(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration) ASTNode(com.intellij.lang.ASTNode) GrLabeledStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrLabeledStatement) PsiElement(com.intellij.psi.PsiElement) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) GrStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)

Example 92 with PsiElement

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

the class GroovyIndentProcessor method getChildIndent.

/**
   * Calculates indent, based on code style, between parent block and child node
   *
   * @param parentBlock parent block
   * @param child       child node
   * @return indent
   */
@NotNull
public Indent getChildIndent(@NotNull final GroovyBlock parentBlock, @NotNull final ASTNode child) {
    myChildType = child.getElementType();
    if (parentBlock instanceof ClosureBodyBlock) {
        if (myChildType == GroovyElementTypes.PARAMETERS_LIST) {
            return Indent.getNoneIndent();
        } else if (myChildType != GroovyTokenTypes.mLCURLY && myChildType != GroovyTokenTypes.mRCURLY) {
            return Indent.getNormalIndent();
        }
    }
    if (parentBlock instanceof GrLabelBlock) {
        ASTNode first = parentBlock.getNode().getFirstChildNode();
        return child == first ? Indent.getNoneIndent() : Indent.getLabelIndent();
    }
    if (GSTRING_TOKENS_INNER.contains(myChildType)) {
        return Indent.getAbsoluteNoneIndent();
    }
    final PsiElement parent = parentBlock.getNode().getPsi();
    if (parent instanceof GroovyPsiElement) {
        myBlock = parentBlock;
        myChild = child.getPsi();
        ((GroovyPsiElement) parent).accept(this);
        if (myResult != null)
            return myResult;
    }
    return Indent.getNoneIndent();
}
Also used : GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrLabelBlock(org.jetbrains.plugins.groovy.formatter.blocks.GrLabelBlock) ASTNode(com.intellij.lang.ASTNode) ClosureBodyBlock(org.jetbrains.plugins.groovy.formatter.blocks.ClosureBodyBlock) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 93 with PsiElement

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

the class GroovySpacingProcessor method init.

private boolean init(ASTNode node) {
    _init(node);
    if (myChild1 == null || myChild2 == null) {
        return true;
    }
    PsiElement psi1 = myChild1.getPsi();
    PsiElement psi2 = myChild2.getPsi();
    if (psi1 == null || psi2 == null) {
        return true;
    }
    if (psi1.getLanguage() != GroovyLanguage.INSTANCE || psi2.getLanguage() != GroovyLanguage.INSTANCE) {
        return true;
    }
    return false;
}
Also used : GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) PsiElement(com.intellij.psi.PsiElement)

Example 94 with PsiElement

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

the class DemorgansLawIntention method processIntention.

@Override
public void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
    GrBinaryExpression exp = (GrBinaryExpression) element;
    final IElementType tokenType = exp.getOperationTokenType();
    PsiElement parent = exp.getParent();
    while (isConjunctionExpression(parent, tokenType)) {
        exp = (GrBinaryExpression) parent;
        assert exp != null;
        parent = exp.getParent();
    }
    final String newExpression = convertConjunctionExpression(exp, tokenType);
    replaceExpressionWithNegatedExpressionString(newExpression, exp);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) GrBinaryExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression) PsiElement(com.intellij.psi.PsiElement)

Example 95 with PsiElement

use of com.intellij.psi.PsiElement 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)

Aggregations

PsiElement (com.intellij.psi.PsiElement)3198 Nullable (org.jetbrains.annotations.Nullable)493 PsiFile (com.intellij.psi.PsiFile)474 NotNull (org.jetbrains.annotations.NotNull)442 TextRange (com.intellij.openapi.util.TextRange)239 PsiReference (com.intellij.psi.PsiReference)227 Project (com.intellij.openapi.project.Project)222 VirtualFile (com.intellij.openapi.vfs.VirtualFile)210 ArrayList (java.util.ArrayList)195 ASTNode (com.intellij.lang.ASTNode)142 XmlTag (com.intellij.psi.xml.XmlTag)134 PsiClass (com.intellij.psi.PsiClass)115 Editor (com.intellij.openapi.editor.Editor)112 Document (com.intellij.openapi.editor.Document)109 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)85 PsiDirectory (com.intellij.psi.PsiDirectory)80 IElementType (com.intellij.psi.tree.IElementType)78 Module (com.intellij.openapi.module.Module)77 PsiMethod (com.intellij.psi.PsiMethod)73 UsageInfo (com.intellij.usageView.UsageInfo)70