This commit is contained in:
Maxim Medvedev
2011-03-11 14:46:55 +03:00
parent c31fd541aa
commit 33206911da
7 changed files with 18 additions and 4 deletions
@@ -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);
}
@@ -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);
}
}
@@ -6,7 +6,7 @@ protected def getGeneratedFileNames(String name, int boo) {
-----
protected def getGeneratedFileNames(String name, int boo) {
def names
names = <caret>testMethod()
names = <caret>testMethod()
names
}
@@ -15,7 +15,7 @@ class S {
Closure sin = {x -> Math.sin(x)}
<caret>testMethod(sin)
<caret>testMethod(sin)
}
@@ -0,0 +1 @@
new A().doSmth({ println "smth" })
@@ -0,0 +1 @@
new A().doSmth()
@@ -0,0 +1,6 @@
class A {
void doSmth() {
[1, 2, 3].each <selection>{ println "smth" }</selection>
}
}