groovy typecast surrounder shouldn't move caret to the start of the file

This commit is contained in:
peter
2011-03-29 20:06:37 +02:00
parent 1a0f374df2
commit f1e086cf3c
7 changed files with 21 additions and 11 deletions
@@ -79,18 +79,16 @@ public abstract class GroovyManyStatementsSurrounder implements Surrounder {
if (parentNode != element.getParent().getNode()) return null;
final int endOffset = element.getTextRange().getEndOffset();
final PsiElement semicolon = PsiTreeUtil.findElementOfClassAtRange(element.getContainingFile(), endOffset, endOffset + 1, PsiElement.class);
final PsiElement semicolon = PsiTreeUtil.findElementOfClassAtOffset(element.getContainingFile(), endOffset, PsiElement.class, false);
if (semicolon != null && ";".equals(semicolon.getText())) {
assert parentNode == semicolon.getParent().getNode();
parentNode.removeChild(semicolon.getNode());
}
if (i < elements.length - 1) {
final PsiElement newLine = PsiTreeUtil.findElementOfClassAtRange(element.getContainingFile(), endOffset, elements[i + 1].getTextRange().getStartOffset(), PsiElement.class);
if (newLine != null && GroovyElementTypes.mNLS.equals(newLine.getNode().getElementType())) {
assert parentNode == newLine.getParent().getNode();
parentNode.removeChild(newLine.getNode());
}
final PsiElement newLine = PsiTreeUtil.findElementOfClassAtOffset(element.getContainingFile(), endOffset, PsiElement.class, false);
if (newLine != null && GroovyElementTypes.mNLS.equals(newLine.getNode().getElementType())) {
assert parentNode == newLine.getParent().getNode();
parentNode.removeChild(newLine.getNode());
}
parentNode.removeChild(element.getNode());
@@ -32,7 +32,7 @@ public class GroovyWithTypeCastSurrounder extends GroovyExpressionSurrounder {
GrTypeCastExpression typeCast = (GrTypeCastExpression) parenthesized.getOperand();
replaceToOldExpression(typeCast.getOperand(), expression);
GrTypeElement typeElement = typeCast.getCastTypeElement();
int endOffset = typeElement.getTextRange().getStartOffset();
int endOffset = typeElement.getTextRange().getStartOffset() + expression.getTextRange().getStartOffset();
parenthesized = (GrParenthesizedExpression) expression.replaceWithExpression(parenthesized, false);
final GrTypeCastExpression newTypeCast = (GrTypeCastExpression)parenthesized.getOperand();
@@ -18,6 +18,7 @@ public class SurroundExpressionTest extends SurroundTestCase {
public void testIf1() throws Exception { doTest(new GroovyWithIfExprSurrounder()); }
public void testIf_else1() throws Exception { doTest(new GroovyWithIfElseExprSurrounder()); }
public void testType_cast1() throws Exception { doTest(new GroovyWithTypeCastSurrounder()); }
public void testType_cast2() throws Exception { doTest(new GroovyWithTypeCastSurrounder()); }
public void testWhile1() throws Exception { doTest(new GroovyWithWhileExprSurrounder()); }
public void testWith2() throws Exception { doTest(new GroovyWithWithExprSurrounder()); }
@@ -25,6 +25,6 @@ public abstract class SurroundTestCase extends LightGroovyTestCase {
}
});
assertEquals(data.get(1), myFixture.getFile().getText().trim());
myFixture.checkResult(data.get(1));
}
}
@@ -0,0 +1,7 @@
println foo
<selection>expr</selection>
-----
println foo
((<caret>) expr)
@@ -1,7 +1,9 @@
<selection>a - b
a - b</selection>
println foo
-----
shouldFail() {
a - b
a - b
}
}
println foo
@@ -1,7 +1,9 @@
<selection>a - b
a - b</selection>
println foo
-----
with() {
a - b
a - b
}
}
println foo