From 8278ad5e3aedb1e0561397fb435aca48088fdcdd Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Tue, 26 Feb 2013 14:41:59 +0400 Subject: [PATCH] Took into account Parenthesized Expressions fixed PY-7151 Convert triple-quoted string to single-quoted string: do not wrap string with parenthesis if initial string is already inside them --- .../intentions/PyConvertTripleQuotedStringIntention.java | 3 ++- .../afterConvertTripleQuotedStringInParenthesized.py | 2 ++ .../beforeConvertTripleQuotedStringInParenthesized.py | 3 +++ python/testSrc/com/jetbrains/python/PyIntentionTest.java | 4 ++++ 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 python/testData/intentions/afterConvertTripleQuotedStringInParenthesized.py create mode 100644 python/testData/intentions/beforeConvertTripleQuotedStringInParenthesized.py diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyConvertTripleQuotedStringIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyConvertTripleQuotedStringIntention.java index 5fc125748e1c..a84d19f71dd7 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyConvertTripleQuotedStringIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyConvertTripleQuotedStringIntention.java @@ -94,7 +94,8 @@ public class PyConvertTripleQuotedStringIntention extends BaseIntentionAction { PyExpressionStatement e = elementGenerator.createFromText(LanguageLevel.forElement(string), PyExpressionStatement.class, result.toString()); PyExpression expression = e.getExpression(); - if (parent instanceof PyTupleExpression && expression instanceof PyParenthesizedExpression) + if ((parent instanceof PyParenthesizedExpression || parent instanceof PyTupleExpression) + && expression instanceof PyParenthesizedExpression) expression = ((PyParenthesizedExpression)expression).getContainedExpression(); if (expression != null) string.replace(expression); diff --git a/python/testData/intentions/afterConvertTripleQuotedStringInParenthesized.py b/python/testData/intentions/afterConvertTripleQuotedStringInParenthesized.py new file mode 100644 index 000000000000..794289cbc830 --- /dev/null +++ b/python/testData/intentions/afterConvertTripleQuotedStringInParenthesized.py @@ -0,0 +1,2 @@ +t = ("string\n" + "some\n") \ No newline at end of file diff --git a/python/testData/intentions/beforeConvertTripleQuotedStringInParenthesized.py b/python/testData/intentions/beforeConvertTripleQuotedStringInParenthesized.py new file mode 100644 index 000000000000..eca7b7334919 --- /dev/null +++ b/python/testData/intentions/beforeConvertTripleQuotedStringInParenthesized.py @@ -0,0 +1,3 @@ +t = ("""string +some +""") \ 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 e9a69cf2cd3e..44c0a6902e69 100644 --- a/python/testSrc/com/jetbrains/python/PyIntentionTest.java +++ b/python/testSrc/com/jetbrains/python/PyIntentionTest.java @@ -253,6 +253,10 @@ public class PyIntentionTest extends PyTestCase { doTest(PyBundle.message("INTN.triple.quoted.string")); } + public void testConvertTripleQuotedStringInParenthesized() { //PY-7883 + doTest(PyBundle.message("INTN.triple.quoted.string")); + } + public void testConvertTripleQuotedUnicodeString() { //PY-7152 doTest(PyBundle.message("INTN.triple.quoted.string")); }