mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
groovy typecast surrounder shouldn't move caret to the start of the file
This commit is contained in:
+5
-7
@@ -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());
|
||||
|
||||
+1
-1
@@ -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();
|
||||
|
||||
+1
@@ -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()); }
|
||||
|
||||
|
||||
+1
-1
@@ -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
|
||||
Reference in New Issue
Block a user