mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-994 don't put parenthesis if putting into non-expression element
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user