diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyQuotedStringIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyQuotedStringIntention.java index e349cc1e6dda..a0820bcbb1cc 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyQuotedStringIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyQuotedStringIntention.java @@ -60,7 +60,7 @@ public class PyQuotedStringIntention extends BaseIntentionAction { string.replace(st); } if (stringText.startsWith("\"") && stringText.endsWith("\"")) { - String result = convertDoubleToSingleQuoted(stringText); + String result = convertDoubleToSingleQuoted(string.getStringValue()); PyStringLiteralExpression st = elementGenerator.createStringLiteralAlreadyEscaped(result); string.replace(st); } @@ -68,7 +68,8 @@ public class PyQuotedStringIntention extends BaseIntentionAction { } private static String convertDoubleToSingleQuoted(String stringText) { - StringBuilder stringBuilder = new StringBuilder(); + StringBuilder stringBuilder = new StringBuilder("'"); + boolean skipNext = false; char[] charArr = stringText.toCharArray(); for (int i = 0; i != charArr.length; ++i) { @@ -78,7 +79,8 @@ public class PyQuotedStringIntention extends BaseIntentionAction { continue; } if (ch == '"') { - stringBuilder.append('\''); + continue; + // stringBuilder.append('\''); } else if (ch == '\'') { stringBuilder.append("\\\'"); @@ -91,11 +93,13 @@ public class PyQuotedStringIntention extends BaseIntentionAction { stringBuilder.append(ch); } } + + stringBuilder.append("'"); return stringBuilder.toString(); } private static String convertSingleToDoubleQuoted(String stringText) { - StringBuilder stringBuilder = new StringBuilder(); + StringBuilder stringBuilder = new StringBuilder("\""); boolean skipNext = false; char[] charArr = stringText.toCharArray(); for (int i = 0; i != charArr.length; ++i) { @@ -105,7 +109,8 @@ public class PyQuotedStringIntention extends BaseIntentionAction { continue; } if (ch == '\'') { - stringBuilder.append('"'); + continue; + //stringBuilder.append('"'); } else if (ch == '"') { stringBuilder.append("\\\""); @@ -118,6 +123,7 @@ public class PyQuotedStringIntention extends BaseIntentionAction { stringBuilder.append(ch); } } + stringBuilder.append("\""); return stringBuilder.toString(); } } diff --git a/python/testData/intentions/afterDoubledQuotedString.py b/python/testData/intentions/afterDoubledQuotedString.py new file mode 100644 index 000000000000..c44de2c7846d --- /dev/null +++ b/python/testData/intentions/afterDoubledQuotedString.py @@ -0,0 +1 @@ +test_function('String resuming string'.format(a, b)) \ No newline at end of file diff --git a/python/testData/intentions/beforeDoubledQuotedString.py b/python/testData/intentions/beforeDoubledQuotedString.py new file mode 100644 index 000000000000..ed7db6283861 --- /dev/null +++ b/python/testData/intentions/beforeDoubledQuotedString.py @@ -0,0 +1,2 @@ +test_function("String " + "resuming string".format(a, b)) \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyIntentionTest.java b/python/testSrc/com/jetbrains/python/PyIntentionTest.java index 3213e35b068b..44fe95721e30 100644 --- a/python/testSrc/com/jetbrains/python/PyIntentionTest.java +++ b/python/testSrc/com/jetbrains/python/PyIntentionTest.java @@ -145,6 +145,10 @@ public class PyIntentionTest extends PyLightFixtureTestCase { doTest(PyBundle.message("INTN.quoted.string.single.to.double")); } + public void testDoubledQuotedString() { //PY-2689 + doTest(PyBundle.message("INTN.quoted.string.double.to.single")); + } + public void testConvertLambdaToFunction() { doTest(PyBundle.message("INTN.convert.lambda.to.function")); }