Keep else part on unwrap for and while

fixed  PY-8569 Unwrap for loop statement should not delete else part
This commit is contained in:
Ekaterina Tuzova
2013-02-22 15:06:13 +04:00
parent 6ed91c8a01
commit 22ec0dd9b3
7 changed files with 16 additions and 0 deletions
@@ -28,6 +28,7 @@ public class PyForUnwrapper extends PyUnwrapper {
protected void doUnwrap(final PsiElement element, final Context context) throws IncorrectOperationException {
final PyForStatement forStatement = (PyForStatement)element;
context.extractPart(forStatement);
context.extractPart(forStatement.getElsePart());
context.delete(forStatement);
}
}
@@ -28,6 +28,7 @@ public class PyWhileUnwrapper extends PyUnwrapper {
protected void doUnwrap(final PsiElement element, final Context context) throws IncorrectOperationException {
final PyWhileStatement whileStatement = (PyWhileStatement)element;
context.extractPart(whileStatement);
context.extractPart(whileStatement.getElsePart());
context.delete(whileStatement);
}
}
@@ -0,0 +1,2 @@
print 1
print 2
@@ -0,0 +1,4 @@
for item in range(1):
prin<caret>t 1
else:
print 2
@@ -0,0 +1,2 @@
x = 1
print 2
@@ -0,0 +1,4 @@
while True:
x =<caret> 1
else:
print 2
@@ -21,6 +21,7 @@ public class PyUnwrapperTest extends PyTestCase {
public void testWhileUnwrap() throws Throwable {doTest();}
public void testWhileUnwrapEmpty() throws Throwable {doNegativeTest();}
public void testWhileUnwrapMultipleStatements() throws Throwable {doTest();}
public void testWhileElseUnwrap() throws Throwable {doTest();}
public void testIfWithElseUnwrap() throws Throwable {doTest();}
public void testIfInWhileUnwrap() throws Throwable {doTest();}
@@ -40,6 +41,7 @@ public class PyUnwrapperTest extends PyTestCase {
public void testTryElseFinallyUnwrap() throws Throwable {doTest();}
public void testForUnwrap() throws Throwable {doTest();}
public void testForElseUnwrap() throws Throwable {doTest();}
public void testWithUnwrap() throws Throwable {doTest(LanguageLevel.PYTHON32);}