Search in sources :

Example 1 with GrForClause

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForClause in project intellij-community by JetBrains.

the class ForSurrounder method getSurroundSelectionRange.

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

Example 2 with GrForClause

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForClause in project intellij-community by JetBrains.

the class ReplaceDelimiterFix method processIntention.

@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
    final PsiFile file = element.getContainingFile();
    PsiElement at = file.findElementAt(editor.getCaretModel().getOffset());
    GrForStatement forStatement = PsiTreeUtil.getParentOfType(at, GrForStatement.class);
    if (forStatement == null)
        return;
    GrForClause clause = forStatement.getClause();
    if (clause instanceof GrForInClause) {
        GrForStatement stubFor = (GrForStatement) GroovyPsiElementFactory.getInstance(project).createStatementFromText("for (x in y){}");
        PsiElement newDelimiter = ((GrForInClause) stubFor.getClause()).getDelimiter();
        PsiElement delimiter = ((GrForInClause) clause).getDelimiter();
        delimiter.replace(newDelimiter);
    }
}
Also used : GrForInClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForInClause) GrForStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrForStatement) GrForClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForClause) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 3 with GrForClause

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForClause in project intellij-community by JetBrains.

the class RecursionUtils method forStatementDefinitelyRecurses.

private static boolean forStatementDefinitelyRecurses(GrForStatement forStatement, GrMethod method) {
    final GrForClause clause = forStatement.getClause();
    if (clause == null)
        return false;
    final GrVariable var = clause.getDeclaredVariable();
    if (var != null) {
        final GrExpression initializer = var.getInitializerGroovy();
        if (expressionDefinitelyRecurses(initializer, method)) {
            return true;
        }
    }
    return false;
}
Also used : GrForClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForClause)

Example 4 with GrForClause

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForClause in project intellij-community by JetBrains.

the class RecursionUtils method forStatementMayReturnBeforeRecursing.

private static boolean forStatementMayReturnBeforeRecursing(GrForStatement loopStatement, GrMethod method) {
    final GrForClause forClause = loopStatement.getClause();
    if (forClause != null) {
        final GrVariable var = forClause.getDeclaredVariable();
        if (var != null) {
            final GrExpression initializer = var.getInitializerGroovy();
            if (expressionDefinitelyRecurses(initializer, method)) {
                return false;
            }
        }
    }
    final GrStatement body = loopStatement.getBody();
    return statementMayReturnBeforeRecursing(body, method);
}
Also used : GrForClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForClause)

Example 5 with GrForClause

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForClause in project intellij-community by JetBrains.

the class EquivalenceChecker method forInStatementsAreEquivalent.

private static boolean forInStatementsAreEquivalent(@NotNull GrForStatement statement1, @NotNull GrForStatement statement2) {
    final GrForClause clause1 = statement1.getClause();
    final GrForClause clause2 = statement2.getClause();
    if (!forClausesAreEquivalent(clause1, clause2)) {
        return false;
    }
    final GrStatement body1 = statement1.getBody();
    final GrStatement body2 = statement2.getBody();
    return statementsAreEquivalent(body1, body2);
}
Also used : GrForClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForClause)

Aggregations

GrForClause (org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForClause)10 GrForInClause (org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForInClause)4 PsiElement (com.intellij.psi.PsiElement)3 GrForStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrForStatement)3 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)3 PsiFile (com.intellij.psi.PsiFile)2 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)2 Document (com.intellij.openapi.editor.Document)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)1 VariableInplaceRenamer (com.intellij.refactoring.rename.inplace.VariableInplaceRenamer)1 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)1 GrCondition (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition)1 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)1 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)1 GrTraditionalForClause (org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrTraditionalForClause)1 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)1 GrMethodCallExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression)1 GrParameterList (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList)1