2323import com .jetbrains .python .psi .*;
2424import com .jetbrains .python .psi .types .PyType ;
2525import com .jetbrains .python .psi .types .TypeEvalContext ;
26+ import consulo .annotation .access .RequiredWriteAction ;
2627import consulo .codeEditor .Editor ;
27- import consulo .ide .impl .idea .util .NotNullFunction ;
2828import consulo .language .psi .PsiElement ;
2929import consulo .language .psi .PsiFile ;
3030import consulo .language .psi .util .PsiTreeUtil ;
3131import consulo .language .util .IncorrectOperationException ;
3232import consulo .project .Project ;
3333import consulo .python .impl .localize .PyLocalize ;
34+ import consulo .util .lang .Couple ;
3435import consulo .util .lang .Pair ;
3536import consulo .util .lang .StringUtil ;
3637import jakarta .annotation .Nonnull ;
3738
3839import java .util .ArrayList ;
3940import java .util .Collection ;
4041import java .util .List ;
42+ import java .util .function .Function ;
4143
4244/**
4345 * @author Alexey.Ivanov
@@ -126,6 +128,8 @@ private static Collection<PyElementType> getOperators(@Nonnull PyBinaryExpressio
126128 return res ;
127129 }
128130
131+ @ Override
132+ @ RequiredWriteAction
129133 public void doInvoke (@ Nonnull Project project , Editor editor , PsiFile file ) throws IncorrectOperationException {
130134 PsiElement element =
131135 PsiTreeUtil .getTopmostParentOfType (file .findElementAt (editor .getCaretModel ().getOffset ()), PyBinaryExpression .class );
@@ -136,18 +140,18 @@ public void doInvoke(@Nonnull Project project, Editor editor, PsiFile file) thro
136140 final LanguageLevel languageLevel = LanguageLevel .forElement (element );
137141 final boolean useFormatMethod = languageLevel .isAtLeast (LanguageLevel .PYTHON27 );
138142
139- NotNullFunction <String , String > escaper = consulo . ide . impl . idea . openapi . util . text . StringUtil .escaper (false , "\" \' \\ " );
143+ Function <String , String > escaper = StringUtil .escaper (false , "\" \' \\ " );
140144 StringBuilder stringLiteral = new StringBuilder ();
141145 List <String > parameters = new ArrayList <>();
142- Pair <String , String > quotes = Pair . create ("\" " , "\" " );
146+ Pair <String , String > quotes = Couple . of ("\" " , "\" " );
143147 boolean quotesDetected = false ;
144148 final TypeEvalContext context = TypeEvalContext .userInitiated (file .getProject (), file );
145149 int paramCount = 0 ;
146150 boolean isUnicode = false ;
147151 final PyClassTypeImpl unicodeType = PyBuiltinCache .getInstance (element ).getObjectType ("unicode" );
148152
149153 for (PyExpression expression : getSimpleExpressions ((PyBinaryExpression ) element )) {
150- if (expression instanceof PyStringLiteralExpression ) {
154+ if (expression instanceof PyStringLiteralExpression stringLiteral1 ) {
151155 final PyType type = context .getType (expression );
152156 if (type != null && type .equals (unicodeType )) {
153157 isUnicode = true ;
@@ -156,7 +160,7 @@ public void doInvoke(@Nonnull Project project, Editor editor, PsiFile file) thro
156160 quotes = PyStringLiteralUtil .getQuotes (expression .getText ());
157161 quotesDetected = true ;
158162 }
159- String value = (( PyStringLiteralExpression ) expression ) .getStringValue ();
163+ String value = stringLiteral1 .getStringValue ();
160164 if (!useFormatMethod ) {
161165 value = value .replace ("%" , "%%" );
162166 }
@@ -169,7 +173,7 @@ public void doInvoke(@Nonnull Project project, Editor editor, PsiFile file) thro
169173 }
170174 }
171175 if (quotes == null ) {
172- quotes = Pair . create ("\" " , "\" " );
176+ quotes = Couple . of ("\" " , "\" " );
173177 }
174178 stringLiteral .insert (0 , quotes .getFirst ());
175179 if (isUnicode && !quotes .getFirst ().toLowerCase ().contains ("u" )) {
0 commit comments