PY-994 don't put parenthesis if putting into non-expression element

This commit is contained in:
Dennis Ushakov
2010-05-16 14:23:03 +04:00
parent 572c6a97ff
commit 1f56dab2e2
4 changed files with 21 additions and 7 deletions
@@ -16,18 +16,21 @@ public class PyReplaceExpressionUtil implements PyElementTypes {
public static boolean isNeedParenthesis(@NotNull final PyElement oldExpr, @NotNull final PyElement newExpr) {
final PyElement parentExpr = (PyElement)oldExpr.getParent();
if (!(parentExpr instanceof PyExpression)) {
return false;
}
int newPriority = getExpressionPriority(newExpr);
int parentPriority = getExpressionPriority(parentExpr);
if (parentPriority > newPriority) {
return true;
} else if (parentPriority == newPriority && parentPriority != 0) {
if (parentExpr instanceof PyBinaryExpression) {
PyBinaryExpression binaryExpression = (PyBinaryExpression) parentExpr;
if (isNotAssociative(binaryExpression) && oldExpr.equals(binaryExpression.getRightExpression())) {
return true;
}
return true;
} else if (parentPriority == newPriority && parentPriority != 0) {
if (parentExpr instanceof PyBinaryExpression) {
PyBinaryExpression binaryExpression = (PyBinaryExpression)parentExpr;
if (isNotAssociative(binaryExpression) && oldExpr.equals(binaryExpression.getRightExpression())) {
return true;
}
}
}
return false;
}
@@ -0,0 +1,3 @@
class C:
def foo(self):
return Conference()
@@ -0,0 +1,4 @@
class C:
def foo(self):
co<caret>nf = Conference()
return conf
@@ -55,4 +55,8 @@ public class PyInlineLocalTest extends LightMarkedTestCase {
public void testMultiple() throws Exception {
doTest();
}
public void testPy994() throws Exception {
doTest();
}
}