mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-3239 "Remove redundant parentheses" quickfix doesn't work
This commit is contained in:
@@ -29,8 +29,11 @@ public class RedundantParenthesesQuickFix implements LocalQuickFix {
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
PsiElement element = descriptor.getPsiElement();
|
||||
PsiElement binaryExpression = ((PyParenthesizedExpression)element).getContainedExpression();
|
||||
if (binaryExpression instanceof PyBinaryExpression)
|
||||
replaceBinaryExpression((PyBinaryExpression)binaryExpression);
|
||||
if (binaryExpression instanceof PyBinaryExpression) {
|
||||
if (!replaceBinaryExpression((PyBinaryExpression)binaryExpression)) {
|
||||
element.replace(binaryExpression);
|
||||
}
|
||||
}
|
||||
else {
|
||||
while (element instanceof PyParenthesizedExpression) {
|
||||
PyExpression expression = ((PyParenthesizedExpression)element).getContainedExpression();
|
||||
@@ -41,7 +44,7 @@ public class RedundantParenthesesQuickFix implements LocalQuickFix {
|
||||
}
|
||||
}
|
||||
|
||||
private static void replaceBinaryExpression(PyBinaryExpression element) {
|
||||
private static boolean replaceBinaryExpression(PyBinaryExpression element) {
|
||||
PyExpression left = element.getLeftExpression();
|
||||
PyExpression right = element.getRightExpression();
|
||||
if (left instanceof PyParenthesizedExpression &&
|
||||
@@ -51,7 +54,9 @@ public class RedundantParenthesesQuickFix implements LocalQuickFix {
|
||||
if (leftContained != null && rightContained != null) {
|
||||
left.replace(leftContained);
|
||||
right.replace(rightContained);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
while <warning descr="Remove redundant parentheses">((close_hr - current_hr_it) >= .<caret>5)</warning>:
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
while (close_hr - current_hr_it) >= .5:
|
||||
pass
|
||||
@@ -179,6 +179,11 @@ public class PyQuickFixTest extends PyLightFixtureTestCase {
|
||||
PyBundle.message("QFIX.redundant.parentheses"), true, true);
|
||||
}
|
||||
|
||||
public void testRedundantParenthesesMore() { // PY-3239
|
||||
doInspectionTest("RedundantParenthesesMore.py", PyRedundantParenthesesInspection.class,
|
||||
PyBundle.message("QFIX.redundant.parentheses"), true, true);
|
||||
}
|
||||
|
||||
public void testAugmentAssignment() { // PY-1415
|
||||
doInspectionTest("AugmentAssignment.py", PyAugmentAssignmentInspection.class,
|
||||
PyBundle.message("QFIX.augment.assignment"), true, true);
|
||||
|
||||
Reference in New Issue
Block a user