mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-3197 Quck fix doesn't work for string with string formatting symbols
This commit is contained in:
@@ -5,6 +5,7 @@ import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.impl.PyAugAssignmentStatementImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -48,9 +49,8 @@ public class AugmentedAssignmentQuickFix implements LocalQuickFix {
|
||||
if (leftExpression != null
|
||||
&& (leftExpression instanceof PyReferenceExpression || leftExpression instanceof PySubscriptionExpression)) {
|
||||
if (leftExpression.getText().equals(target.getText())) {
|
||||
if (rightExpression instanceof PyNumericLiteralExpression ||
|
||||
rightExpression instanceof PyStringLiteralExpression
|
||||
|| rightExpression instanceof PyReferenceExpression) {
|
||||
if (rightExpression instanceof PyNumericLiteralExpression || rightExpression instanceof PyStringLiteralExpression
|
||||
|| rightExpression instanceof PyReferenceExpression || isPercentage(rightExpression) ) {
|
||||
|
||||
PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
@@ -64,4 +64,10 @@ public class AugmentedAssignmentQuickFix implements LocalQuickFix {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPercentage(PyExpression rightExpression) {
|
||||
return (rightExpression instanceof PyBinaryExpression &&
|
||||
((PyBinaryExpression)rightExpression).getLeftExpression() instanceof PyStringLiteralExpression &&
|
||||
((PyBinaryExpression)rightExpression).getOperator() == PyTokenTypes.PERC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<warning descr="Assignment can be replaced with augmented assignment">request = request + " FROM bugs WHERE bug_id = %s" % (str(bug_id))</warning>
|
||||
@@ -0,0 +1 @@
|
||||
request += " FROM bugs WHERE bug_id = %s" % (str(bug_id))
|
||||
@@ -189,6 +189,11 @@ public class PyQuickFixTest extends PyLightFixtureTestCase {
|
||||
PyBundle.message("QFIX.augment.assignment"), true, true);
|
||||
}
|
||||
|
||||
public void testAugmentAssignmentPerc() { // PY-3197
|
||||
doInspectionTest("AugmentAssignmentPerc.py", PyAugmentAssignmentInspection.class,
|
||||
PyBundle.message("QFIX.augment.assignment"), true, true);
|
||||
}
|
||||
|
||||
public void testChainedComparisons() { // PY-1020
|
||||
doInspectionTest("ChainedComparisons.py", PyChainedComparisonsInspection.class,
|
||||
PyBundle.message("QFIX.chained.comparison"), true, true);
|
||||
|
||||
Reference in New Issue
Block a user