Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
0c3f4294
Commit
0c3f4294
authored
11 years ago
by
Ekaterina Tuzova
Committed by
Andrey Vlasovskikh
11 years ago
Browse files
Options
Download
Email Patches
Plain Diff
extracted tests for PyConvertFormatOperatorToMethodIntention
parent
05eb673f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python/src/com/jetbrains/python/codeInsight/intentions/PyStringConcatenationToFormatIntention.java
+10
-0
...ht/intentions/PyStringConcatenationToFormatIntention.java
with
10 additions
and
0 deletions
+10
-0
python/src/com/jetbrains/python/codeInsight/intentions/PyStringConcatenationToFormatIntention.java
+
10
-
0
View file @
0c3f4294
...
...
@@ -30,6 +30,7 @@ import com.jetbrains.python.PyTokenTypes;
import
com.jetbrains.python.PythonStringUtil
;
import
com.jetbrains.python.psi.*
;
import
com.jetbrains.python.psi.impl.PyBuiltinCache
;
import
com.jetbrains.python.psi.types.PyClassTypeImpl
;
import
com.jetbrains.python.psi.types.PyType
;
import
com.jetbrains.python.psi.types.PyTypeChecker
;
import
com.jetbrains.python.psi.types.TypeEvalContext
;
...
...
@@ -136,9 +137,16 @@ public class PyStringConcatenationToFormatIntention extends BaseIntentionAction
List
<
String
>
parameters
=
new
ArrayList
<
String
>();
Pair
<
String
,
String
>
quotes
=
new
Pair
<
String
,
String
>(
"\""
,
"\""
);
boolean
quotesDetected
=
false
;
final
TypeEvalContext
context
=
TypeEvalContext
.
userInitiated
(
file
);
int
paramCount
=
0
;
boolean
isUnicode
=
false
;
final
PyClassTypeImpl
unicodeType
=
PyBuiltinCache
.
getInstance
(
element
).
getObjectType
(
"unicode"
);
for
(
PyExpression
expression
:
getSimpleExpressions
((
PyBinaryExpression
)
element
))
{
if
(
expression
instanceof
PyStringLiteralExpression
)
{
final
PyType
type
=
context
.
getType
(
expression
);
if
(
PyTypeChecker
.
match
(
unicodeType
,
type
,
context
))
{
isUnicode
=
true
;
}
if
(!
quotesDetected
)
{
quotes
=
PythonStringUtil
.
getQuotes
(
expression
.
getText
());
quotesDetected
=
true
;
...
...
@@ -157,6 +165,8 @@ public class PyStringConcatenationToFormatIntention extends BaseIntentionAction
if
(
quotes
==
null
)
quotes
=
new
Pair
<
String
,
String
>(
"\""
,
"\""
);
stringLiteral
.
insert
(
0
,
quotes
.
getFirst
());
if
(
isUnicode
&&
!
quotes
.
getFirst
().
toLowerCase
().
contains
(
"u"
))
stringLiteral
.
insert
(
0
,
"u"
);
stringLiteral
.
append
(
quotes
.
getSecond
());
PyElementGenerator
elementGenerator
=
PyElementGenerator
.
getInstance
(
project
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help