From a1f887806e0bcd43cb0111328e7a31d79d168015 Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Mon, 18 Apr 2011 18:21:35 +0400 Subject: [PATCH] api for GrIfStatement --- .../codeInspection/bugs/RecursionUtils.java | 28 +++++++---------- .../confusing/GroovyNegatedIfInspection.java | 7 ++--- .../GroovyConstantIfStatementInspection.java | 10 +++--- .../GroovyDoubleCheckedLockingInspection.java | 14 ++++----- .../utils/EquivalenceChecker.java | 4 +-- .../control/MergeIfAndIntention.java | 9 +++--- .../control/SplitElseIfIntention.java | 1 - .../smartEnter/fixers/GrIfConditionFixer.java | 5 ++- .../fixers/GrMissingIfStatement.java | 1 - .../psi/api/statements/GrIfStatement.java | 31 ++++++++++--------- .../impl/statements/GrIfStatementImpl.java | 20 +++++++----- .../surroundWith/IfElseExprSurrounder.java | 2 +- .../lang/surroundWith/IfExprSurrounder.java | 2 +- .../convertToJava/CodeBlockGenerator.java | 2 +- 14 files changed, 65 insertions(+), 71 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/bugs/RecursionUtils.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/bugs/RecursionUtils.java index 3e0e4c594378..f995c4d0357c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/bugs/RecursionUtils.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/bugs/RecursionUtils.java @@ -167,12 +167,10 @@ class RecursionUtils { private static boolean ifStatementMayReturnBeforeRecursing( GrIfStatement ifStatement, GrMethod method) { - GrCondition condition = ifStatement.getCondition(); - if (!(condition instanceof GrExpression)) { - return false; - } - final GrExpression test = (GrExpression) condition; - if (expressionDefinitelyRecurses(test, method)) { + GrExpression condition = ifStatement.getCondition(); + if (condition == null) return false; + + if (expressionDefinitelyRecurses(condition, method)) { return false; } final GrStatement thenBranch = ifStatement.getThenBranch(); @@ -476,9 +474,8 @@ class RecursionUtils { } } - private static boolean switchStatementDefinitelyRecurses( - GrSwitchStatement switchStatement, GrMethod method) { - final GrExpression switchExpression = (GrExpression) switchStatement.getCondition(); + private static boolean switchStatementDefinitelyRecurses(GrSwitchStatement switchStatement, GrMethod method) { + final GrExpression switchExpression = switchStatement.getCondition(); return expressionDefinitelyRecurses(switchExpression, method); } @@ -511,11 +508,10 @@ class RecursionUtils { private static boolean ifStatementDefinitelyRecurses( GrIfStatement ifStatement, GrMethod method) { - final GrCondition condition = ifStatement.getCondition(); - if (!(condition instanceof GrExpression)) { - return false; - } - if (expressionDefinitelyRecurses((GrExpression) condition, method)) { + final GrExpression condition = ifStatement.getCondition(); + if (condition == null) return false; + + if (expressionDefinitelyRecurses(condition, method)) { return true; } final GrStatement thenBranch = ifStatement.getThenBranch(); @@ -527,9 +523,9 @@ class RecursionUtils { statementDefinitelyRecurses(elseBranch, method); } - private static boolean forStatementDefinitelyRecurses( - GrForStatement forStatement, GrMethod method) { + 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(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/confusing/GroovyNegatedIfInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/confusing/GroovyNegatedIfInspection.java index 27e827c9a7b0..d61f3ab119b0 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/confusing/GroovyNegatedIfInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/confusing/GroovyNegatedIfInspection.java @@ -21,7 +21,6 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.codeInspection.BaseInspection; import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor; import org.jetbrains.plugins.groovy.intentions.utils.BoolUtils; -import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; @@ -53,11 +52,11 @@ public class GroovyNegatedIfInspection extends BaseInspection { public void visitIfStatement(GrIfStatement grIfStatement) { super.visitIfStatement(grIfStatement); - final GrCondition condition = grIfStatement.getCondition(); - if (!(condition instanceof GrExpression)) { + final GrExpression condition = grIfStatement.getCondition(); + if (condition == null) { return; } - if (!BoolUtils.isNegation((GrExpression) condition)) { + if (!BoolUtils.isNegation(condition)) { return; } if (grIfStatement.getElseBranch() == null || grIfStatement.getThenBranch() == null) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/control/GroovyConstantIfStatementInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/control/GroovyConstantIfStatementInspection.java index dfddb10b3aa7..6c2cffddb0e9 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/control/GroovyConstantIfStatementInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/control/GroovyConstantIfStatementInspection.java @@ -24,7 +24,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.codeInspection.BaseInspection; import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor; import org.jetbrains.plugins.groovy.codeInspection.GroovyFix; -import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; @@ -72,7 +71,7 @@ public class GroovyConstantIfStatementInspection extends BaseInspection { assert ifStatement != null; final GrStatement thenBranch = ifStatement.getThenBranch(); final GrStatement elseBranch = ifStatement.getElseBranch(); - final GrExpression condition = (GrExpression) ifStatement.getCondition(); + final GrExpression condition = ifStatement.getCondition(); // todo still needs some handling for conflicting declarations if (isFalse(condition)) { if (elseBranch != null) { @@ -91,16 +90,15 @@ public class GroovyConstantIfStatementInspection extends BaseInspection { public void visitIfStatement(GrIfStatement statement) { super.visitIfStatement(statement); - final GrCondition condition = statement.getCondition(); - if (!(condition instanceof GrExpression)) { + final GrExpression condition = statement.getCondition(); + if (condition == null) { return; } final GrStatement thenBranch = statement.getThenBranch(); if (thenBranch == null) { return; } - final GrExpression conditionExpression = (GrExpression) condition; - if (isTrue(conditionExpression) || isFalse(conditionExpression)) { + if (isTrue(condition) || isFalse(condition)) { registerStatementError(statement); } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/threading/GroovyDoubleCheckedLockingInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/threading/GroovyDoubleCheckedLockingInspection.java index a9a9fe02581a..ba14e1dbd2f3 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/threading/GroovyDoubleCheckedLockingInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/threading/GroovyDoubleCheckedLockingInspection.java @@ -27,7 +27,6 @@ import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor; import org.jetbrains.plugins.groovy.codeInspection.utils.ControlFlowUtils; import org.jetbrains.plugins.groovy.codeInspection.utils.EquivalenceChecker; import org.jetbrains.plugins.groovy.codeInspection.utils.SideEffectChecker; -import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrSynchronizedStatement; @@ -77,11 +76,11 @@ public class GroovyDoubleCheckedLockingInspection extends BaseInspection { public void visitIfStatement(@NotNull GrIfStatement statement) { super.visitIfStatement(statement); - final GrCondition outerCondition = statement.getCondition(); - if (!(outerCondition instanceof GrExpression)) { + final GrExpression outerCondition = statement.getCondition(); + if (outerCondition == null) { return; } - if (SideEffectChecker.mayHaveSideEffects((GrExpression) outerCondition)) { + if (SideEffectChecker.mayHaveSideEffects(outerCondition)) { return; } GrStatement thenBranch = statement.getThenBranch(); @@ -106,12 +105,11 @@ public class GroovyDoubleCheckedLockingInspection extends BaseInspection { return; } final GrIfStatement innerIf = (GrIfStatement) statements[0]; - final GrCondition innerCondition = innerIf.getCondition(); - if (!(innerCondition instanceof GrExpression)) { + final GrExpression innerCondition = innerIf.getCondition(); + if (innerCondition == null) { return; } - if (!EquivalenceChecker.expressionsAreEquivalent((GrExpression) innerCondition, - (GrExpression) outerCondition)) { + if (!EquivalenceChecker.expressionsAreEquivalent(innerCondition, outerCondition)) { return; } if (ignoreOnVolatileVariables && diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/utils/EquivalenceChecker.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/utils/EquivalenceChecker.java index f80a8f2fa278..fdde5dd99efd 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/utils/EquivalenceChecker.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/utils/EquivalenceChecker.java @@ -377,8 +377,8 @@ public class EquivalenceChecker { private static boolean ifStatementsAreEquivalent(@NotNull GrIfStatement statement1, @NotNull GrIfStatement statement2) { - final GrExpression condition1 = (GrExpression) statement1.getCondition(); - final GrExpression condition2 = (GrExpression) statement2.getCondition(); + final GrExpression condition1 = statement1.getCondition(); + final GrExpression condition2 = statement2.getCondition(); final GrStatement thenBranch1 = statement1.getThenBranch(); final GrStatement thenBranch2 = statement2.getThenBranch(); final GrStatement elseBranch1 = statement1.getElseBranch(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/MergeIfAndIntention.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/MergeIfAndIntention.java index 83146f354a44..b49515c3eda8 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/MergeIfAndIntention.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/MergeIfAndIntention.java @@ -42,12 +42,11 @@ public class MergeIfAndIntention extends Intention { throws IncorrectOperationException { final GrIfStatement parentStatement = (GrIfStatement) element; - assert parentStatement != null; - final GrStatement parentThenBranch = (GrStatement) parentStatement.getThenBranch(); + final GrStatement parentThenBranch = parentStatement.getThenBranch(); final GrIfStatement childStatement = (GrIfStatement) ConditionalUtils.stripBraces(parentThenBranch); - final GrExpression childCondition = (GrExpression) childStatement.getCondition(); + final GrExpression childCondition = childStatement.getCondition(); final String childConditionText; if (ParenthesesUtils.getPrecendence(childCondition) > ParenthesesUtils.AND_PRECEDENCE) { @@ -56,7 +55,7 @@ public class MergeIfAndIntention extends Intention { childConditionText = childCondition.getText(); } - final GrExpression parentCondition = (GrExpression) parentStatement.getCondition(); + final GrExpression parentCondition = parentStatement.getCondition(); final String parentConditionText; if (ParenthesesUtils.getPrecendence(parentCondition) > ParenthesesUtils.AND_PRECEDENCE) { @@ -65,7 +64,7 @@ public class MergeIfAndIntention extends Intention { parentConditionText = parentCondition.getText(); } - final GrStatement childThenBranch = (GrStatement) childStatement.getThenBranch(); + final GrStatement childThenBranch = childStatement.getThenBranch(); @NonNls final String statement = "if(" + parentConditionText + "&&" + childConditionText + ')' + childThenBranch.getText(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/SplitElseIfIntention.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/SplitElseIfIntention.java index 7bf1a4b1d1a8..497b2699d64c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/SplitElseIfIntention.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/SplitElseIfIntention.java @@ -36,7 +36,6 @@ public class SplitElseIfIntention extends Intention { public void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException { final GrIfStatement parentStatement = (GrIfStatement) element; - assert parentStatement != null; final GrStatement elseBranch = parentStatement.getElseBranch(); IntentionUtils.replaceStatement("if(" + parentStatement.getCondition().getText()+ ")"+ parentStatement.getThenBranch().getText() + "else{\n" + elseBranch.getText() +"\n}", parentStatement); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/smartEnter/fixers/GrIfConditionFixer.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/smartEnter/fixers/GrIfConditionFixer.java index a66e9a994181..8978985876a2 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/smartEnter/fixers/GrIfConditionFixer.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/smartEnter/fixers/GrIfConditionFixer.java @@ -15,15 +15,14 @@ */ package org.jetbrains.plugins.groovy.lang.completion.smartEnter.fixers; -import org.jetbrains.plugins.groovy.lang.completion.smartEnter.fixers.GrFixer; import org.jetbrains.plugins.groovy.lang.completion.smartEnter.GroovySmartEnterProcessor; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement; -import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.Document; import com.intellij.psi.PsiElement; import com.intellij.util.IncorrectOperationException; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; /** * User: Dmitry.Krasilschikov @@ -36,7 +35,7 @@ public class GrIfConditionFixer implements GrFixer { final GrIfStatement ifStatement = (GrIfStatement) psiElement; final PsiElement rParen = ifStatement.getRParenth(); final PsiElement lParen = ifStatement.getLParenth(); - final GrCondition condition = ifStatement.getCondition(); + final GrExpression condition = ifStatement.getCondition(); if (condition == null) { if (lParen == null || rParen == null) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/smartEnter/fixers/GrMissingIfStatement.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/smartEnter/fixers/GrMissingIfStatement.java index 95a8897a630a..308561fa83ee 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/smartEnter/fixers/GrMissingIfStatement.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/smartEnter/fixers/GrMissingIfStatement.java @@ -22,7 +22,6 @@ import com.intellij.util.IncorrectOperationException; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrBlockStatement; -import org.jetbrains.plugins.groovy.lang.completion.smartEnter.fixers.GrFixer; import org.jetbrains.plugins.groovy.lang.completion.smartEnter.GroovySmartEnterProcessor; /** diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/GrIfStatement.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/GrIfStatement.java index 36e75d546c15..44dd216fa9d6 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/GrIfStatement.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/GrIfStatement.java @@ -16,35 +16,36 @@ package org.jetbrains.plugins.groovy.lang.psi.api.statements; -import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition; import org.jetbrains.plugins.groovy.lang.psi.api.formatter.GrControlStatement; -import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; import org.jetbrains.annotations.Nullable; import com.intellij.util.IncorrectOperationException; -import com.intellij.psi.PsiJavaToken; import com.intellij.psi.PsiElement; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; /** * @autor: ilyas */ public interface GrIfStatement extends GrStatement, GrControlStatement { - public GrCondition getCondition(); - - public GrStatement getThenBranch(); - - public GrStatement getElseBranch(); - - public GrStatement replaceThenBranch(GrStatement newBranch) throws IncorrectOperationException; - - public GrStatement replaceElseBranch(GrStatement newBranch) throws IncorrectOperationException; + @Nullable + GrExpression getCondition(); @Nullable - public PsiElement getElseKeyword(); + GrStatement getThenBranch(); @Nullable - public PsiElement getRParenth(); + GrStatement getElseBranch(); + + GrStatement replaceThenBranch(GrStatement newBranch) throws IncorrectOperationException; + + GrStatement replaceElseBranch(GrStatement newBranch) throws IncorrectOperationException; @Nullable - public PsiElement getLParenth(); + PsiElement getElseKeyword(); + + @Nullable + PsiElement getRParenth(); + + @Nullable + PsiElement getLParenth(); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrIfStatementImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrIfStatementImpl.java index 221145213a39..7d608f4b8e8e 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrIfStatementImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrIfStatementImpl.java @@ -20,12 +20,14 @@ import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElement; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrCondition; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiElementImpl; /** @@ -44,17 +46,19 @@ public class GrIfStatementImpl extends GroovyPsiElementImpl implements GrIfState return "IF statement"; } - public GrCondition getCondition() { + @Nullable + public GrExpression getCondition() { PsiElement lParenth = getLParenth(); if (lParenth == null) return null; PsiElement afterLParen = lParenth.getNextSibling(); - if (afterLParen instanceof GrCondition) return ((GrCondition) afterLParen); + if (afterLParen instanceof GrExpression) return (GrExpression)afterLParen; return null; } + @Nullable public GrStatement getThenBranch() { GrStatement[] statements = findChildrenByClass(GrStatement.class); @@ -64,6 +68,7 @@ public class GrIfStatementImpl extends GroovyPsiElementImpl implements GrIfState return null; } + @Nullable public GrStatement getElseBranch() { GrStatement[] statements = findChildrenByClass(GrStatement.class); if (statements.length == 3 && (statements[2] instanceof GrStatement)) { @@ -74,11 +79,12 @@ public class GrIfStatementImpl extends GroovyPsiElementImpl implements GrIfState } public GrStatement replaceThenBranch(GrStatement newBranch) throws IncorrectOperationException { - if (getThenBranch() == null || + final GrStatement thenBranch = getThenBranch(); + if (thenBranch == null || newBranch == null) { throw new IncorrectOperationException(); } - ASTNode oldBodyNode = getThenBranch().getNode(); + ASTNode oldBodyNode = thenBranch.getNode(); if (oldBodyNode.getTreePrev() != null && GroovyTokenTypes.mNLS.equals(oldBodyNode.getTreePrev().getElementType())) { ASTNode whiteNode = GroovyPsiElementFactory.getInstance(getProject()).createWhiteSpace().getNode(); @@ -93,11 +99,11 @@ public class GrIfStatementImpl extends GroovyPsiElementImpl implements GrIfState } public GrStatement replaceElseBranch(GrStatement newBranch) throws IncorrectOperationException { - if (getElseBranch() == null || - newBranch == null) { + final GrStatement elseBranch = getElseBranch(); + if (elseBranch == null || newBranch == null) { throw new IncorrectOperationException(); } - ASTNode oldBodyNode = getElseBranch().getNode(); + ASTNode oldBodyNode = elseBranch.getNode(); if (oldBodyNode.getTreePrev() != null && GroovyTokenTypes.mNLS.equals(oldBodyNode.getTreePrev().getElementType())) { ASTNode whiteNode = GroovyPsiElementFactory.getInstance(getProject()).createWhiteSpace().getNode(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/surroundWith/IfElseExprSurrounder.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/surroundWith/IfElseExprSurrounder.java index 63f4b391d8ad..442c8d60e4dd 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/surroundWith/IfElseExprSurrounder.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/surroundWith/IfElseExprSurrounder.java @@ -29,7 +29,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpres public class IfElseExprSurrounder extends GroovyConditionSurrounder { protected TextRange surroundExpression(GrExpression expression) { GrIfStatement ifStatement = (GrIfStatement) GroovyPsiElementFactory.getInstance(expression.getProject()).createTopElementFromText("if(a){4\n} else{\n}"); - replaceToOldExpression((GrExpression) ifStatement.getCondition(), expression); + replaceToOldExpression(ifStatement.getCondition(), expression); ifStatement = expression.replaceWithStatement(ifStatement); GrStatement psiElement = ifStatement.getThenBranch(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/surroundWith/IfExprSurrounder.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/surroundWith/IfExprSurrounder.java index f242f3653e0e..cb458784df91 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/surroundWith/IfExprSurrounder.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/surroundWith/IfExprSurrounder.java @@ -29,7 +29,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpres public class IfExprSurrounder extends GroovyConditionSurrounder { protected TextRange surroundExpression(GrExpression expression) { GrIfStatement ifStatement = (GrIfStatement) GroovyPsiElementFactory.getInstance(expression.getProject()).createTopElementFromText("if(a){4\n}"); - replaceToOldExpression((GrExpression)ifStatement.getCondition(), expression); + replaceToOldExpression(ifStatement.getCondition(), expression); ifStatement = expression.replaceWithStatement(ifStatement); GrStatement thenBranch = ifStatement.getThenBranch(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/CodeBlockGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/CodeBlockGenerator.java index 8f1b931b28da..d07c609660a5 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/CodeBlockGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/CodeBlockGenerator.java @@ -173,7 +173,7 @@ public class CodeBlockGenerator extends Generator { @Override public void visitIfStatement(GrIfStatement ifStatement) { - final GrCondition condition = ifStatement.getCondition(); + final GrExpression condition = ifStatement.getCondition(); final GrStatement thenBranch = ifStatement.getThenBranch(); final GrStatement elseBranch = ifStatement.getElseBranch();