mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-12145 Align closing brace when there is no hanging indent in parental expression
Also update expected test data in a couple of existing tests to be PEP8 complaint
This commit is contained in:
@@ -336,7 +336,16 @@ public class PyBlock implements ASTBlock {
|
||||
else if (elem instanceof PyFunction) {
|
||||
return hasHangingIndent(((PyFunction)elem).getParameterList());
|
||||
}
|
||||
else if (elem instanceof PySequenceExpression) {
|
||||
|
||||
final PsiElement firstChild = elem.getFirstChild();
|
||||
if (firstChild == null) {
|
||||
return false;
|
||||
}
|
||||
if (PyTokenTypes.OPEN_BRACES.contains(firstChild.getNode().getElementType()) && hasLineBreaksAfter(firstChild.getNode(), 1)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (elem instanceof PySequenceExpression) {
|
||||
items = ((PySequenceExpression)elem).getElements();
|
||||
}
|
||||
else if (elem instanceof PyParameterList) {
|
||||
@@ -345,14 +354,19 @@ public class PyBlock implements ASTBlock {
|
||||
else if (elem instanceof PyArgumentList) {
|
||||
items = ((PyArgumentList)elem).getArguments();
|
||||
}
|
||||
else if (elem instanceof PyParenthesizedExpression) {
|
||||
final PyParenthesizedExpression parenthesizedExpr = (PyParenthesizedExpression)elem;
|
||||
if (parenthesizedExpr.getContainedExpression() instanceof PyTupleExpression) {
|
||||
items = (((PyTupleExpression)parenthesizedExpr.getContainedExpression()).getElements());
|
||||
}
|
||||
else {
|
||||
items = new PsiElement[]{parenthesizedExpr.getContainedExpression()};
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
if (items.length == 0) {
|
||||
return true;
|
||||
}
|
||||
final PsiElement firstItem = items[0];
|
||||
return hasLineBreaksBefore(firstItem.getNode(), 1) || hasHangingIndent(firstItem);
|
||||
return items.length == 0 || hasHangingIndent(items[0]);
|
||||
}
|
||||
|
||||
private static boolean breaksAlignment(IElementType type) {
|
||||
@@ -439,7 +453,7 @@ public class PyBlock implements ASTBlock {
|
||||
myContext.getMode() == FormattingMode.ADJUST_INDENT) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return !hasHangingIndent(_node.getPsi());
|
||||
}
|
||||
if (_node.getElementType() == PyElementTypes.ARGUMENT_LIST) {
|
||||
if (!myContext.getSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS || hasHangingIndent(_node.getPsi())) {
|
||||
@@ -477,12 +491,18 @@ public class PyBlock implements ASTBlock {
|
||||
return node;
|
||||
}
|
||||
|
||||
private static boolean hasLineBreaksBefore(ASTNode child, int minCount) {
|
||||
private static boolean hasLineBreaksBefore(@NotNull ASTNode child, int minCount) {
|
||||
final ASTNode treePrev = child.getTreePrev();
|
||||
return (treePrev != null && isWhitespaceWithLineBreaks(TreeUtil.findLastLeaf(treePrev), minCount)) ||
|
||||
isWhitespaceWithLineBreaks(child.getFirstChildNode(), minCount);
|
||||
}
|
||||
|
||||
private static boolean hasLineBreaksAfter(@NotNull ASTNode child, int minCount) {
|
||||
final ASTNode treeNext = child.getTreeNext();
|
||||
return (treeNext != null && isWhitespaceWithLineBreaks(TreeUtil.findLastLeaf(treeNext), minCount)) ||
|
||||
isWhitespaceWithLineBreaks(child.getLastChildNode(), minCount);
|
||||
}
|
||||
|
||||
private static boolean isWhitespaceWithLineBreaks(ASTNode node, int minCount) {
|
||||
if (node != null && node.getElementType() == TokenType.WHITE_SPACE) {
|
||||
String prevNodeText = node.getText();
|
||||
|
||||
@@ -5,4 +5,4 @@ print(1 + (1 + (1
|
||||
+
|
||||
x.
|
||||
calc()
|
||||
))
|
||||
))
|
||||
@@ -0,0 +1,8 @@
|
||||
class Checkpoints(webapp2.RequestHandler):
|
||||
def get(self):
|
||||
self.response.write(json.dumps({"meta": {"code": 400,
|
||||
"errorType": "paramError",
|
||||
"errorDetail": "Parameter 'api_key' is missing"
|
||||
},
|
||||
"response": {}
|
||||
}))
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class Checkpoints(webapp2.RequestHandler):
|
||||
def get(self):
|
||||
self.response.write(json.dumps({"meta": {"code": 400,
|
||||
"errorType": "paramError",
|
||||
"errorDetail": "Parameter 'api_key' is missing"
|
||||
},
|
||||
"response": {}
|
||||
}))
|
||||
@@ -1,4 +1,4 @@
|
||||
urlpatterns = patterns('',
|
||||
(r'^admin/', include(admin.site.urls)),
|
||||
url(r'^', include('cms.urls')),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -466,6 +466,11 @@ public class PyFormatterTest extends PyTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
// PY-12145
|
||||
public void testAlignmentOfClosingBraceInDictLiteralWhenNoHangingIndent() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
/**
|
||||
* This test merely checks that call to {@link com.intellij.psi.codeStyle.CodeStyleManager#reformat(com.intellij.psi.PsiElement)}
|
||||
* is possible for Python sources.
|
||||
|
||||
Reference in New Issue
Block a user