mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Switched to new string value iteration in Python spellchecker
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<PyStringLiteralExpression> {
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
print "foo\nsomething"
|
||||
print "foo\nsomething"
|
||||
print """foo\n<TYPO descr="Typo: In word 'brbrbr'">brbrbr</TYPO>"""
|
||||
|
||||
Reference in New Issue
Block a user