mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-20803 Disable 'Replace with str.format method call' for string with * character in chunks
This commit is contained in:
+15
-3
@@ -30,6 +30,7 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.PyNames;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.inspections.PyStringFormatParser;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.impl.PyBuiltinCache;
|
||||
import com.jetbrains.python.psi.impl.PyPsiUtils;
|
||||
@@ -235,10 +236,21 @@ public class ConvertFormatOperatorToMethodIntention extends BaseIntentionAction
|
||||
if (binaryExpression.getLeftExpression() instanceof PyStringLiteralExpression
|
||||
&& binaryExpression.getOperator() == PyTokenTypes.PERC) {
|
||||
final PyStringLiteralExpression str = (PyStringLiteralExpression)binaryExpression.getLeftExpression();
|
||||
if (!(str.getText().length() > 0 && Character.toUpperCase(str.getText().charAt(0)) == 'B')) {
|
||||
setText(PyBundle.message("INTN.replace.with.method"));
|
||||
return true;
|
||||
if ((str.getText().length() > 0 && Character.toUpperCase(str.getText().charAt(0)) == 'B')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final List<PyStringFormatParser.SubstitutionChunk> chunks =
|
||||
PyStringFormatParser.filterSubstitutions(PyStringFormatParser.parsePercentFormat(binaryExpression.getLeftExpression().getText()));
|
||||
|
||||
for (PyStringFormatParser.SubstitutionChunk chunk : chunks) {
|
||||
if ("*".equals(chunk.getWidth()) || "*".equals(chunk.getPrecision())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
setText(PyBundle.message("INTN.replace.with.method"));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
s = '%.*s = %.*f' % (3, 'Gibberish', 3, 2.7182)
|
||||
@@ -0,0 +1 @@
|
||||
s = '%*d' % (4, 5)
|
||||
+1
@@ -0,0 +1 @@
|
||||
s = '%*.*f' % (5, 2, 2.7182)
|
||||
+15
@@ -67,5 +67,20 @@ public class PyConvertFormatOperatorToMethodIntentionTest extends PyIntentionTes
|
||||
// PY-20800
|
||||
public void testRepr() {
|
||||
doTest(PyBundle.message("INTN.replace.with.method"), LanguageLevel.PYTHON26);
|
||||
}
|
||||
|
||||
// PY-20803
|
||||
public void testStarWidth() {
|
||||
doNegativeTest(PyBundle.message("INTN.replace.with.method"));
|
||||
}
|
||||
|
||||
// PY-20803
|
||||
public void testStarPrecision() {
|
||||
doNegativeTest(PyBundle.message("INTN.replace.with.method"));
|
||||
}
|
||||
|
||||
// PY-20803
|
||||
public void testStarWidthPrecision() {
|
||||
doNegativeTest(PyBundle.message("INTN.replace.with.method"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user