Search in sources :

Example 6 with GrCondition

use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition in project intellij-community by JetBrains.

the class GrTraditionalForClauseImpl method getConditionInner.

private GrCondition getConditionInner(final int i) {
    int passed = 0;
    boolean waitForSemicolon = false;
    for (ASTNode child = getNode().getFirstChildNode(); child != null; child = child.getTreeNext()) {
        if (child.getElementType() == GroovyTokenTypes.mSEMI) {
            if (waitForSemicolon) {
                waitForSemicolon = false;
            } else {
                if (passed == i) {
                    return null;
                }
                passed++;
            }
        } else if (child.getPsi() instanceof GrCondition) {
            if (passed == i) {
                return (GrCondition) child.getPsi();
            }
            passed++;
            waitForSemicolon = true;
        }
    }
    return null;
}
Also used : ASTNode(com.intellij.lang.ASTNode) GrCondition(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition)

Example 7 with GrCondition

use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition in project intellij-community by JetBrains.

the class ControlFlowBuilder method visitSwitchStatement.

@Override
public void visitSwitchStatement(@NotNull GrSwitchStatement switchStatement) {
    final GrCondition condition = switchStatement.getCondition();
    if (condition != null) {
        condition.accept(this);
    }
    final InstructionImpl instruction = startNode(switchStatement);
    final GrCaseSection[] sections = switchStatement.getCaseSections();
    if (!containsAllCases(switchStatement)) {
        addPendingEdge(switchStatement, instruction);
    }
    for (GrCaseSection section : sections) {
        myHead = instruction;
        section.accept(this);
    }
    finishNode(instruction);
}
Also used : GrCondition(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition)

Example 8 with GrCondition

use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition in project intellij-community by JetBrains.

the class ControlFlowBuilder method visitIfStatement.

@Override
public void visitIfStatement(@NotNull GrIfStatement ifStatement) {
    InstructionImpl ifInstruction = startNode(ifStatement);
    FList<ConditionInstruction> conditionsBefore = myConditions;
    final GrCondition condition = ifStatement.getCondition();
    final GrStatement thenBranch = ifStatement.getThenBranch();
    final GrStatement elseBranch = ifStatement.getElseBranch();
    InstructionImpl conditionEnd = null;
    InstructionImpl thenEnd = null;
    InstructionImpl elseEnd = null;
    if (condition != null) {
        condition.accept(this);
        conditionEnd = myHead;
    }
    List<GotoInstruction> negations = collectAndRemoveAllPendingNegations(ifStatement);
    if (thenBranch != null) {
        thenBranch.accept(this);
        handlePossibleReturn(thenBranch);
        thenEnd = myHead;
        interruptFlow();
        readdPendingEdge(ifStatement);
    }
    myHead = reduceAllNegationsIntoInstruction(ifStatement, negations);
    if (myHead == null && conditionEnd != null) {
        myHead = conditionEnd;
    }
    if (elseBranch != null) {
        elseBranch.accept(this);
        handlePossibleReturn(elseBranch);
        elseEnd = myHead;
        interruptFlow();
    }
    if (thenBranch != null || elseBranch != null) {
        if (thenEnd != null || elseEnd != null || elseBranch == null) {
            final InstructionImpl end = new IfEndInstruction(ifStatement);
            addNode(end);
            if (thenEnd != null) {
                addEdge(thenEnd, end);
            }
            if (elseEnd != null) {
                addEdge(elseEnd, end);
            } else if (elseBranch == null) {
            //    addEdge(conditionEnd != null ? conditionEnd : ifInstruction, end);
            }
        }
    }
    myConditions = conditionsBefore;
    finishNode(ifInstruction);
}
Also used : GrCondition(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition)

Example 9 with GrCondition

use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition in project intellij-community by JetBrains.

the class GrWhileConditionFixer method apply.

@Override
public void apply(@NotNull Editor editor, @NotNull GroovySmartEnterProcessor processor, @NotNull PsiElement psiElement) {
    if (psiElement instanceof GrWhileStatement) {
        final Document doc = editor.getDocument();
        final GrWhileStatement whileStatement = (GrWhileStatement) psiElement;
        final PsiElement rParenth = whileStatement.getRParenth();
        final PsiElement lParenth = whileStatement.getLParenth();
        final GrCondition condition = whileStatement.getCondition();
        if (condition == null) {
            if (lParenth == null || rParenth == null) {
                int stopOffset = doc.getLineEndOffset(doc.getLineNumber(whileStatement.getTextRange().getStartOffset()));
                final GrStatement block = whileStatement.getBody();
                if (block != null) {
                    stopOffset = Math.min(stopOffset, block.getTextRange().getStartOffset());
                }
                stopOffset = Math.min(stopOffset, whileStatement.getTextRange().getEndOffset());
                doc.replaceString(whileStatement.getTextRange().getStartOffset(), stopOffset, "while ()");
                processor.registerUnresolvedError(whileStatement.getTextRange().getStartOffset() + "while (".length());
            } else {
                processor.registerUnresolvedError(lParenth.getTextRange().getEndOffset());
            }
        } else if (rParenth == null) {
            doc.insertString(condition.getTextRange().getEndOffset(), ")");
        }
    }
}
Also used : GrWhileStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrWhileStatement) Document(com.intellij.openapi.editor.Document) GrCondition(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition) PsiElement(com.intellij.psi.PsiElement) GrStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)

Example 10 with GrCondition

use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition in project intellij-community by JetBrains.

the class WhileSurrounder method getSurroundSelectionRange.

@Override
protected TextRange getSurroundSelectionRange(GroovyPsiElement element) {
    assert element instanceof GrWhileStatement;
    GrCondition condition = ((GrWhileStatement) element).getCondition();
    int endOffset = element.getTextRange().getEndOffset();
    if (condition != null) {
        endOffset = condition.getTextRange().getStartOffset();
        condition.getParent().getNode().removeChild(condition.getNode());
    }
    return new TextRange(endOffset, endOffset);
}
Also used : GrWhileStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrWhileStatement) TextRange(com.intellij.openapi.util.TextRange) GrCondition(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition)

Aggregations

GrCondition (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition)10 TextRange (com.intellij.openapi.util.TextRange)3 PsiElement (com.intellij.psi.PsiElement)2 GrWhileStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrWhileStatement)2 ASTNode (com.intellij.lang.ASTNode)1 Document (com.intellij.openapi.editor.Document)1 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)1 GrIfStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement)1 GrStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)1 GrForClause (org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForClause)1 GrForInClause (org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForInClause)1 GrTraditionalForClause (org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrTraditionalForClause)1 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)1 GrMethodCallExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression)1 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)1