fixed PY-8520 Refill Paragraph should not move first line in docstring to the line with quotes

do not move docstring if it is from the beginning at the first string (or the last) with quotes
This commit is contained in:
Ekaterina Tuzova
2013-03-28 14:58:18 +04:00
parent 89cbab5da0
commit 3fffafb7d8
4 changed files with 43 additions and 4 deletions
@@ -2,6 +2,7 @@ package com.jetbrains.python.actions;
import com.intellij.codeInsight.editorActions.fillParagraph.ParagraphFillHandler;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiComment;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
@@ -15,6 +16,8 @@ import com.jetbrains.python.psi.PyStringLiteralExpression;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* User : ktisha
*/
@@ -25,12 +28,22 @@ public class PyFillParagraphHandler extends ParagraphFillHandler {
final PyStringLiteralExpression stringLiteralExpression =
PsiTreeUtil.getParentOfType(element, PyStringLiteralExpression.class);
if (stringLiteralExpression != null) {
final String text = stringLiteralExpression.getText();
final Pair<String,String> quotes =
PythonStringUtil.getQuotes(stringLiteralExpression.getText());
PythonStringUtil.getQuotes(text);
final PyDocStringOwner docStringOwner = PsiTreeUtil.getParentOfType(stringLiteralExpression, PyDocStringOwner.class);
if (docStringOwner != null && stringLiteralExpression.equals(docStringOwner.getDocStringExpression())) {
String indent = getIndent(stringLiteralExpression);
return quotes != null? quotes.getFirst()+ indent : "\"" + indent;
if (quotes != null) {
final List<String> strings = StringUtil.split(text, "\n");
if (strings.get(0).trim().equals(quotes.getFirst())) {
return quotes.getFirst() + indent;
}
else {
return quotes.getFirst();
}
}
return "\"" + indent;
}
else
return quotes != null? quotes.getFirst() : "\"";
@@ -57,12 +70,22 @@ public class PyFillParagraphHandler extends ParagraphFillHandler {
final PyStringLiteralExpression stringLiteralExpression =
PsiTreeUtil.getParentOfType(element, PyStringLiteralExpression.class);
if (stringLiteralExpression != null) {
final String text = stringLiteralExpression.getText();
final Pair<String,String> quotes =
PythonStringUtil.getQuotes(stringLiteralExpression.getText());
PythonStringUtil.getQuotes(text);
final PyDocStringOwner docStringOwner = PsiTreeUtil.getParentOfType(stringLiteralExpression, PyDocStringOwner.class);
if (docStringOwner != null && stringLiteralExpression.equals(docStringOwner.getDocStringExpression())) {
String indent = getIndent(stringLiteralExpression);
return quotes != null? indent + quotes.getSecond() : indent + "\"";
if (quotes != null) {
final List<String> strings = StringUtil.split(text, "\n");
if (strings.get(strings.size()-1).trim().equals(quotes.getSecond())) {
return indent + quotes.getSecond();
}
else {
return quotes.getSecond();
}
}
return indent + "\"";
}
else
return quotes != null? quotes.getSecond() : "\"";
@@ -0,0 +1,6 @@
__author__ = 'ktisha'
def foo():
"""A M<caret>ap from key to total # of views by that key. This can be expensive to
the big fetch with blackjack and whores, so we generally want to fetch this only for keys that have a large
absolute number of views, a small number of days between views, etc."""
@@ -0,0 +1,6 @@
__author__ = 'ktisha'
def foo():
"""A Map from key to total # of views by that key. This can be expensive to the big fetch with blackjack and
whores, so we generally want to fetch this only for keys that have a large absolute number of views,
a small number of days between views, etc. """
@@ -36,6 +36,10 @@ public class PyFillParagraphTest extends PyTestCase {
doTest();
}
public void testPrefixPostfix() {
doTest();
}
private void doTest() {
String baseName = "/fillParagraph/" + getTestName(true);
myFixture.configureByFile(baseName + ".py");