Search in sources :

Example 6 with GrForStatement

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrForStatement 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 7 with GrForStatement

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

the class ForToEachPredicate method satisfiedBy.

@Override
public boolean satisfiedBy(PsiElement element) {
    if (!(element instanceof GrForStatement)) {
        return false;
    }
    final GrForStatement statement = (GrForStatement) element;
    final GrForClause clause = statement.getClause();
    if (!(clause instanceof GrForInClause) || ((GrForInClause) clause).getIteratedExpression() == null) {
        return false;
    }
    return !ErrorUtil.containsError(element);
}
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)

Aggregations

GrForStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrForStatement)7 GrForClause (org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForClause)3 GrForInClause (org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForInClause)3 PsiElement (com.intellij.psi.PsiElement)2 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)2 GrBlockStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrBlockStatement)2 Document (com.intellij.openapi.editor.Document)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiFile (com.intellij.psi.PsiFile)1 NonNls (org.jetbrains.annotations.NonNls)1 GrStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)1 GrSwitchStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrSwitchStatement)1 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)1 GrCodeBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock)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