Search in sources :

Example 1 with GrLabelBlock

use of org.jetbrains.plugins.groovy.formatter.blocks.GrLabelBlock 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)

Aggregations

ASTNode (com.intellij.lang.ASTNode)1 PsiElement (com.intellij.psi.PsiElement)1 NotNull (org.jetbrains.annotations.NotNull)1 ClosureBodyBlock (org.jetbrains.plugins.groovy.formatter.blocks.ClosureBodyBlock)1 GrLabelBlock (org.jetbrains.plugins.groovy.formatter.blocks.GrLabelBlock)1 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)1