mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
introduce variable handles multiline string literals (PY-6698)
This commit is contained in:
@@ -3,6 +3,7 @@ package com.jetbrains.python.refactoring.introduce;
|
||||
import com.intellij.codeInsight.CodeInsightUtilBase;
|
||||
import com.intellij.codeInsight.template.impl.TemplateManagerImpl;
|
||||
import com.intellij.codeInsight.template.impl.TemplateState;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
@@ -18,6 +19,7 @@ import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiWhiteSpace;
|
||||
import com.intellij.psi.TokenType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.IntroduceTargetChooser;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
@@ -447,6 +449,26 @@ abstract public class IntroduceHandler implements RefactoringActionHandler {
|
||||
myResult.append(space.getText().replace('\n', ' ').replace("\\", ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyStringLiteralExpression(PyStringLiteralExpression node) {
|
||||
ASTNode child = node.getNode().getFirstChildNode();
|
||||
while (child != null) {
|
||||
String text = child.getText();
|
||||
if (child.getElementType() == TokenType.WHITE_SPACE) {
|
||||
if (text.contains("\n")) {
|
||||
if (!text.contains("\\")) {
|
||||
myResult.append("\\");
|
||||
}
|
||||
myResult.append(text);
|
||||
}
|
||||
}
|
||||
else {
|
||||
myResult.append(text);
|
||||
}
|
||||
child = child.getTreeNext();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitElement(PsiElement element) {
|
||||
if (element.getChildren().length == 0) {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
a = "foo"\
|
||||
"bar"
|
||||
x(a)
|
||||
@@ -0,0 +1,2 @@
|
||||
x(<selection>"foo"
|
||||
"bar"</selection>)
|
||||
@@ -84,6 +84,10 @@ public class PyIntroduceVariableTest extends PyIntroduceTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testMultipartString() { // PY-6698
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTestCannotPerform() {
|
||||
boolean thrownExpectedException = false;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user