mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-12008 Keep existing behavior when all statement conditions are not aligned
This commit is contained in:
@@ -79,7 +79,7 @@ public class PyBlock implements ASTBlock {
|
||||
PyElementTypes.FROM_IMPORT_STATEMENT);
|
||||
|
||||
public static final Key<Boolean> IMPORT_GROUP_BEGIN = Key.create("com.jetbrains.python.formatter.importGroupBegin");
|
||||
private static final boolean ALIGN_IF_CONDITION_WITHOUT_PARENTHESES = false;
|
||||
private static final boolean ALIGN_CONDITIONS_WITHOUT_PARENTHESES = false;
|
||||
|
||||
@NotNull
|
||||
public static PyBlock createBlock(@Nullable PyBlock parent,
|
||||
@@ -258,7 +258,7 @@ public class PyBlock implements ASTBlock {
|
||||
}
|
||||
if (childAlignment == null && topmostBinary != null &&
|
||||
!isParenthesisedIfCondition(topmostBinary.myNode) &&
|
||||
!(isIfCondition(topmostBinary.myNode) && !ALIGN_IF_CONDITION_WITHOUT_PARENTHESES)) {
|
||||
!(isCondition(topmostBinary.myNode) && !ALIGN_CONDITIONS_WITHOUT_PARENTHESES)) {
|
||||
childAlignment = topmostBinary.getAlignmentForChildren();
|
||||
}
|
||||
childIndent = Indent.getContinuationWithoutFirstIndent();
|
||||
@@ -431,15 +431,17 @@ public class PyBlock implements ASTBlock {
|
||||
return parens != null && isIfCondition(parens);
|
||||
}
|
||||
|
||||
private static boolean isIfCondition(@NotNull ASTNode node) {
|
||||
return isIfCondition(node.getPsi(PyExpression.class));
|
||||
}
|
||||
|
||||
private static boolean isIfCondition(@NotNull PyExpression expr) {
|
||||
final PyIfPart ifPart = as(expr.getParent(), PyIfPart.class);
|
||||
return ifPart != null && ifPart.getCondition() == expr && !ifPart.isElif();
|
||||
}
|
||||
|
||||
private static boolean isCondition(@NotNull ASTNode node) {
|
||||
final PsiElement element = node.getPsi();
|
||||
final PyConditionalStatementPart conditionalStatement = as(element.getParent(), PyConditionalStatementPart.class);
|
||||
return conditionalStatement != null && conditionalStatement.getCondition() == element;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PyBlock findTopmostBinaryExpressionBlock(@NotNull ASTNode child) {
|
||||
assert child.getElementType() != PyElementTypes.BINARY_EXPRESSION;
|
||||
|
||||
@@ -2,8 +2,8 @@ if foo and \
|
||||
bar == 42:
|
||||
pass
|
||||
elif foo and \
|
||||
bar:
|
||||
bar:
|
||||
pass
|
||||
elif foo and \
|
||||
bar == 24:
|
||||
bar == 24:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user