mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-13114 "Inline" refactoring doesn't insert redundant parenthesis
This commit is contained in:
@@ -61,21 +61,26 @@ public class PyReplaceExpressionUtil implements PyElementTypes {
|
||||
|
||||
private PyReplaceExpressionUtil() {}
|
||||
|
||||
/**
|
||||
* @param oldExpr old expression that will be substituted
|
||||
* @param newExpr new expression to substitute with
|
||||
* @return whether new expression should be wrapped in parenthesis to preserve original semantics
|
||||
*/
|
||||
public static boolean isNeedParenthesis(@NotNull final PyElement oldExpr, @NotNull final PyElement newExpr) {
|
||||
final PyElement parentExpr = (PyElement)oldExpr.getParent();
|
||||
if (parentExpr instanceof PyArgumentList) {
|
||||
return newExpr instanceof PyTupleExpression;
|
||||
}
|
||||
if (!(parentExpr instanceof PyExpression)) {
|
||||
if (parentExpr instanceof PyParenthesizedExpression || !(parentExpr instanceof PyExpression)) {
|
||||
return false;
|
||||
}
|
||||
int newPriority = getExpressionPriority(newExpr);
|
||||
int parentPriority = getExpressionPriority(parentExpr);
|
||||
final int newPriority = getExpressionPriority(newExpr);
|
||||
final int parentPriority = getExpressionPriority(parentExpr);
|
||||
if (parentPriority > newPriority) {
|
||||
return true;
|
||||
} else if (parentPriority == newPriority && parentPriority != 0) {
|
||||
if (parentExpr instanceof PyBinaryExpression) {
|
||||
PyBinaryExpression binaryExpression = (PyBinaryExpression)parentExpr;
|
||||
final PyBinaryExpression binaryExpression = (PyBinaryExpression)parentExpr;
|
||||
if (isNotAssociative(binaryExpression) && oldExpr.equals(binaryExpression.getRightExpression())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
print ('spam!' * 42)
|
||||
('spam!' * 42)
|
||||
hex('spam!' * 42)
|
||||
@@ -0,0 +1,5 @@
|
||||
x<caret> = 'spam!' * 42
|
||||
|
||||
print (x)
|
||||
(x)
|
||||
hex(x)
|
||||
@@ -81,7 +81,13 @@ public class PyInlineLocalTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-12401
|
||||
public void testComment() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-13114
|
||||
public void testReferenceInParenthesis() {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user