Make continuation indent after continuation in indenting statement (PY-9573).

This commit is contained in:
Dmitry Trofimov
2014-01-18 02:03:32 +01:00
parent 14bdb823c0
commit 9ee1b1efad
6 changed files with 78 additions and 11 deletions
@@ -258,7 +258,7 @@ public class PyBlock implements ASTBlock {
while (prev != null && prev.getElementType() == TokenType.WHITE_SPACE) {
if (prev.getText().contains("\\") && !childIndent.equals(Indent.getContinuationIndent()) &&
!childIndent.equals(Indent.getContinuationIndent(true))) {
childIndent = Indent.getNormalIndent();
childIndent = isIndentNext(child) ? Indent.getContinuationIndent() : Indent.getNormalIndent();
break;
}
prev = prev.getTreePrev();
@@ -267,6 +267,19 @@ public class PyBlock implements ASTBlock {
return new PyBlock(this, child, childAlignment, childIndent, wrap, myContext);
}
private static boolean isIndentNext(ASTNode child) {
PsiElement psi = PsiTreeUtil.getParentOfType(child.getPsi(), PyStatement.class);
return psi instanceof PyIfStatement ||
psi instanceof PyForStatement ||
psi instanceof PyWithStatement ||
psi instanceof PyClass ||
psi instanceof PyFunction ||
psi instanceof PyTryExceptStatement ||
psi instanceof PyElsePart ||
psi instanceof PyIfPart;
}
private static boolean isSubscriptionOperand(ASTNode child) {
return child.getTreeParent().getElementType() == PyElementTypes.SUBSCRIPTION_EXPRESSION &&
child.getPsi() == ((PySubscriptionExpression)child.getTreeParent().getPsi()).getOperand();
@@ -438,7 +451,7 @@ public class PyBlock implements ASTBlock {
if ((node1.getElementType() == PyElementTypes.FUNCTION_DECLARATION || node1.getElementType() == PyElementTypes.CLASS_DECLARATION)
&& _node.getElementType() instanceof PyFileElementType) {
if (psi2 instanceof PsiComment) {
final PsiElement psi3 = PsiTreeUtil.getNextSiblingOfType(psi2, PyElement.class);
@@ -1,4 +0,0 @@
def is_false(value):
if value is None \
or value == 0:
return False
@@ -1,4 +0,0 @@
def is_false(value):
if value is None \
or value == 0:
return False
@@ -0,0 +1,31 @@
if True \
or False:
pass
elif \
False:
pass
for i in \
range(1, 100):
pass
with open('file1') as file1, \
open('file2') as file2:
pass
class \
A(object):
pass
def \
foo():
pass
try:
pass
except \
AttributeError:
pass
@@ -0,0 +1,31 @@
if True \
or False:
pass
elif \
False:
pass
for i in \
range(1, 100):
pass
with open('file1') as file1, \
open('file2') as file2:
pass
class \
A(object):
pass
def \
foo():
pass
try:
pass
except \
AttributeError:
pass
@@ -203,7 +203,7 @@ public class PyFormatterTest extends PyTestCase {
doTest();
}
public void testContinuationIndentAfterIf() { // PY-9573
public void testContinuationIndentInIndentingStatement() { // PY-9573
doTest();
}