diff --git a/python/src/com/jetbrains/python/psi/impl/PyStringLiteralExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyStringLiteralExpressionImpl.java index 9402b873e5a7..5bc50dd269b8 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyStringLiteralExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyStringLiteralExpressionImpl.java @@ -173,6 +173,11 @@ public class PyStringLiteralExpressionImpl extends PyElementImpl implements PySt public String getValue() { return myValue; } + + @Override + public String toString() { + return String.format("DecodedFragmentImpl(%s, \"%s\")", myRange, myValue); + } } @Override diff --git a/python/src/com/jetbrains/python/spellchecker/PythonSpellcheckerStrategy.java b/python/src/com/jetbrains/python/spellchecker/PythonSpellcheckerStrategy.java index 4a0a59d15c1f..5d6033541294 100644 --- a/python/src/com/jetbrains/python/spellchecker/PythonSpellcheckerStrategy.java +++ b/python/src/com/jetbrains/python/spellchecker/PythonSpellcheckerStrategy.java @@ -26,7 +26,6 @@ import com.jetbrains.python.PyTokenTypes; import com.jetbrains.python.inspections.PyStringFormatParser; import com.jetbrains.python.psi.PyBinaryExpression; import com.jetbrains.python.psi.PyStringLiteralExpression; -import com.jetbrains.python.psi.impl.PyStringLiteralExpressionImpl; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -41,9 +40,11 @@ public class PythonSpellcheckerStrategy extends SpellcheckingStrategy { Splitter splitter = PlainTextSplitter.getInstance(); String text = element.getText(); if (text.indexOf('\\') >= 0) { - MyTextRangeConsumer textRangeConsumer = new MyTextRangeConsumer(element, consumer); - ((PyStringLiteralExpressionImpl) element).iterateCharacterRanges(textRangeConsumer); - textRangeConsumer.processCurrentToken(); // process last token + for (PyStringLiteralExpression.DecodedFragment fragment : element.getDecodedFragments()) { + final String value = fragment.getValue(); + consumer.consumeToken(element, value, false, fragment.getEncodedTextRange().getStartOffset(), TextRange.allOf(value), + PlainTextSplitter.getInstance()); + } } else if (text.startsWith("u") || text.startsWith("U") || text.startsWith("r") || text.startsWith("R") || text.startsWith("b") || text.startsWith("B")) { @@ -57,40 +58,6 @@ public class PythonSpellcheckerStrategy extends SpellcheckingStrategy { consumer.consumeToken(element, splitter); } } - - private static class MyTextRangeConsumer implements PyStringLiteralExpressionImpl.TextRangeConsumer { - private final StringBuilder myCurrentToken = new StringBuilder(); - private final PyStringLiteralExpression myElement; - private final TokenConsumer myTokenConsumer; - private int myTokenStart; - - public MyTextRangeConsumer(PyStringLiteralExpression element, TokenConsumer tokenConsumer) { - myElement = element; - myTokenConsumer = tokenConsumer; - } - - @Override - public boolean process(int startOffset, int endOffset, String value) { - if (endOffset == startOffset + 1) { - if (myCurrentToken.length() == 0) { - myTokenStart = startOffset; - } - myCurrentToken.append(value); - } - else { - if (myCurrentToken.length() > 0) { - processCurrentToken(); - myCurrentToken.setLength(0); - } - } - return true; - } - - private void processCurrentToken() { - String token = myCurrentToken.toString(); - myTokenConsumer.consumeToken(myElement, token, false, myTokenStart, TextRange.allOf(token), PlainTextSplitter.getInstance()); - } - } } private static class FormatStringTokenizer extends Tokenizer { diff --git a/python/testData/inspections/spelling/ignoreEscapeSequence.py b/python/testData/inspections/spelling/ignoreEscapeSequence.py index 3bd99651707d..95e8df407454 100644 --- a/python/testData/inspections/spelling/ignoreEscapeSequence.py +++ b/python/testData/inspections/spelling/ignoreEscapeSequence.py @@ -1 +1,2 @@ -print "foo\nsomething" \ No newline at end of file +print "foo\nsomething" +print """foo\nbrbrbr"""