Search in sources :

Example 1 with GrCondition

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

the class GroovySimpleManyStatementsSurrounder method getSurroundSelectionRange.

@Override
protected final TextRange getSurroundSelectionRange(GroovyPsiElement element) {
    assert element instanceof GrMethodCallExpression;
    GrMethodCallExpression withCall = (GrMethodCallExpression) element;
    GrCondition condition = withCall.getExpressionArguments()[0];
    int endOffset = condition.getTextRange().getStartOffset();
    condition.getParent().getNode().removeChild(condition.getNode());
    return new TextRange(endOffset, endOffset);
}
Also used : GrMethodCallExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression) TextRange(com.intellij.openapi.util.TextRange) GrCondition(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition)

Example 2 with GrCondition

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

the class IfSurrounder method getSurroundSelectionRange.

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

Example 3 with GrCondition

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

the class RecursionUtils method whileStatementMayReturnBeforeRecursing.

private static boolean whileStatementMayReturnBeforeRecursing(GrWhileStatement loopStatement, GrMethod method) {
    final GrCondition condition = loopStatement.getCondition();
    if (!(condition instanceof GrExpression)) {
        return false;
    }
    if (expressionDefinitelyRecurses((GrExpression) condition, method)) {
        return false;
    }
    final GrStatement body = loopStatement.getBody();
    return statementMayReturnBeforeRecursing(body, method);
}
Also used : GrCondition(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition)

Example 4 with GrCondition

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

the class ControlFlowBuilder method visitWhileStatement.

@Override
public void visitWhileStatement(@NotNull GrWhileStatement whileStatement) {
    final InstructionImpl instruction = startNode(whileStatement);
    final GrCondition condition = whileStatement.getCondition();
    if (condition != null) {
        condition.accept(this);
    }
    if (!alwaysTrue(condition)) {
        //break
        addPendingEdge(whileStatement, myHead);
    }
    final GrCondition body = whileStatement.getBody();
    if (body != null) {
        body.accept(this);
    }
    //check for breaks targeted here
    checkPending(instruction);
    //loop
    if (myHead != null)
        addEdge(myHead, instruction);
    interruptFlow();
    finishNode(instruction);
}
Also used : GrCondition(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition)

Example 5 with GrCondition

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

the class CodeBlockGenerator method visitForStatement.

@Override
public void visitForStatement(@NotNull GrForStatement forStatement) {
    //final StringBuilder builder = new StringBuilder();
    builder.append("for(");
    final GrForClause clause = forStatement.getClause();
    ExpressionContext forContext = context.extend();
    if (clause instanceof GrForInClause) {
        final GrExpression expression = ((GrForInClause) clause).getIteratedExpression();
        final GrVariable declaredVariable = clause.getDeclaredVariable();
        LOG.assertTrue(declaredVariable != null);
        writeVariableWithoutSemicolonAndInitializer(builder, declaredVariable, context);
        builder.append(" : ");
        if (expression != null) {
            final ExpressionContext context = forContext.copy();
            writeExpression(expression, builder, context);
        }
    } else if (clause instanceof GrTraditionalForClause) {
        final GrTraditionalForClause cl = (GrTraditionalForClause) clause;
        final GrCondition initialization = cl.getInitialization();
        final GrExpression condition = cl.getCondition();
        final GrExpression update = cl.getUpdate();
        if (initialization instanceof GrParameter) {
            StringBuilder partBuilder = new StringBuilder();
            writeVariableWithoutSemicolonAndInitializer(partBuilder, (GrParameter) initialization, context);
            final GrExpression initializer = ((GrParameter) initialization).getInitializerGroovy();
            if (initializer != null) {
                final ExpressionContext partContext = forContext.copy();
                partBuilder.append(" = ");
                writeExpression(initializer, partBuilder, partContext);
                for (String statement : partContext.myStatements) {
                    builder.append(statement).append(", ");
                }
                builder.append(partBuilder);
            }
        } else if (initialization != null) {
            StringBuilder partBuilder = new StringBuilder();
            final ExpressionContext partContext = forContext.copy();
            genForPart(builder, initialization, new CodeBlockGenerator(partBuilder, partContext, null));
        }
        builder.append(';');
        if (condition != null) {
            //todo???
            genForPart(builder, condition, forContext.copy());
        }
        builder.append(';');
        if (update != null) {
            genForPart(builder, update, forContext.copy());
        }
    }
    builder.append(')');
    final GrStatement body = forStatement.getBody();
    if (body != null) {
        body.accept(new CodeBlockGenerator(builder, forContext, null));
    }
}
Also used : GrForInClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForInClause) GrForClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForClause) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) GrCondition(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition) GrTraditionalForClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrTraditionalForClause)

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