diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/surroundWith/surrounders/surroundersImpl/expressions/GroovyWithTypeCastSurrounder.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/surroundWith/surrounders/surroundersImpl/expressions/GroovyWithTypeCastSurrounder.java index 6724da5e03b6..a4f063e069e7 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/surroundWith/surrounders/surroundersImpl/expressions/GroovyWithTypeCastSurrounder.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/surroundWith/surrounders/surroundersImpl/expressions/GroovyWithTypeCastSurrounder.java @@ -29,13 +29,15 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement; public class GroovyWithTypeCastSurrounder extends GroovyExpressionSurrounder { protected TextRange surroundExpression(GrExpression expression) { GrParenthesizedExpression parenthesized = (GrParenthesizedExpression) GroovyPsiElementFactory.getInstance(expression.getProject()).createTopElementFromText("((Type)a)"); - parenthesized = (GrParenthesizedExpression) expression.replaceWithExpression(parenthesized, false); GrTypeCastExpression typeCast = (GrTypeCastExpression) parenthesized.getOperand(); replaceToOldExpression(typeCast.getOperand(), expression); GrTypeElement typeElement = typeCast.getCastTypeElement(); int endOffset = typeElement.getTextRange().getStartOffset(); + parenthesized = (GrParenthesizedExpression) expression.replaceWithExpression(parenthesized, false); - typeCast.getNode().removeChild(typeElement.getNode()); + final GrTypeCastExpression newTypeCast = (GrTypeCastExpression)parenthesized.getOperand(); + final GrTypeElement newTypeElement = newTypeCast.getCastTypeElement(); + newTypeElement.delete(); return new TextRange(endOffset, endOffset); } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/GrIntroduceParameterTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/GrIntroduceParameterTest.java index 31ca9497a12a..ecfeec9e4020 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/GrIntroduceParameterTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/GrIntroduceParameterTest.java @@ -289,4 +289,8 @@ public class GrIntroduceParameterTest extends LightCodeInsightFixtureTestCase { public void testIncorrectArgumentList() { doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, true, false, true); } + + public void testClosure() { + doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, false); + } } diff --git a/plugins/groovy/testdata/groovy/refactoring/extractMethod/expr1.test b/plugins/groovy/testdata/groovy/refactoring/extractMethod/expr1.test index 3d395d6f7528..705f2f5c5657 100644 --- a/plugins/groovy/testdata/groovy/refactoring/extractMethod/expr1.test +++ b/plugins/groovy/testdata/groovy/refactoring/extractMethod/expr1.test @@ -6,7 +6,7 @@ protected def getGeneratedFileNames(String name, int boo) { ----- protected def getGeneratedFileNames(String name, int boo) { def names - names = testMethod() + names = testMethod() names } diff --git a/plugins/groovy/testdata/groovy/refactoring/extractMethod/input1.test b/plugins/groovy/testdata/groovy/refactoring/extractMethod/input1.test index b42d78fa4e79..a1cdec21b192 100644 --- a/plugins/groovy/testdata/groovy/refactoring/extractMethod/input1.test +++ b/plugins/groovy/testdata/groovy/refactoring/extractMethod/input1.test @@ -15,7 +15,7 @@ class S { Closure sin = {x -> Math.sin(x)} - testMethod(sin) + testMethod(sin) } diff --git a/plugins/groovy/testdata/refactoring/introduceParameterGroovy/closure/ClosureAfter.groovy b/plugins/groovy/testdata/refactoring/introduceParameterGroovy/closure/ClosureAfter.groovy new file mode 100644 index 000000000000..5ec9c955f113 --- /dev/null +++ b/plugins/groovy/testdata/refactoring/introduceParameterGroovy/closure/ClosureAfter.groovy @@ -0,0 +1 @@ +new A().doSmth({ println "smth" }) \ No newline at end of file diff --git a/plugins/groovy/testdata/refactoring/introduceParameterGroovy/closure/ClosureBefore.groovy b/plugins/groovy/testdata/refactoring/introduceParameterGroovy/closure/ClosureBefore.groovy new file mode 100644 index 000000000000..df0b92127858 --- /dev/null +++ b/plugins/groovy/testdata/refactoring/introduceParameterGroovy/closure/ClosureBefore.groovy @@ -0,0 +1 @@ +new A().doSmth() \ No newline at end of file diff --git a/plugins/groovy/testdata/refactoring/introduceParameterGroovy/closure/ClosureMyClass.groovy b/plugins/groovy/testdata/refactoring/introduceParameterGroovy/closure/ClosureMyClass.groovy new file mode 100644 index 000000000000..59a1a626d833 --- /dev/null +++ b/plugins/groovy/testdata/refactoring/introduceParameterGroovy/closure/ClosureMyClass.groovy @@ -0,0 +1,6 @@ +class A { + void doSmth() { + [1, 2, 3].each { println "smth" } + } +} +