From afeed89a5964fe2dbea1516dab257c893275a2e2 Mon Sep 17 00:00:00 2001 From: Olga Strizhenko Date: Wed, 14 Mar 2018 15:01:39 +0300 Subject: [PATCH] Spellchecker: WI-36515 IDEA 11.1.3 hanging up on text changes newBombedCharSequence in spellchecker's splitters [IDEA-CR-30609] --- .../spellchecker/inspections/IdentifierSplitter.java | 4 +++- .../spellchecker/inspections/PlainTextSplitter.java | 6 ++++-- .../spellchecker/inspections/PropertiesSplitter.java | 4 +++- .../com/intellij/spellchecker/inspections/TextSplitter.java | 4 +++- .../com/intellij/spellchecker/inspections/WordSplitter.java | 4 +++- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/spellchecker/src/com/intellij/spellchecker/inspections/IdentifierSplitter.java b/spellchecker/src/com/intellij/spellchecker/inspections/IdentifierSplitter.java index 7fb1f56041c8..7c5d69a4d0b5 100644 --- a/spellchecker/src/com/intellij/spellchecker/inspections/IdentifierSplitter.java +++ b/spellchecker/src/com/intellij/spellchecker/inspections/IdentifierSplitter.java @@ -27,6 +27,8 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static com.intellij.openapi.util.text.StringUtil.newBombedCharSequence; + public class IdentifierSplitter extends BaseSplitter { private static final IdentifierSplitter INSTANCE = new IdentifierSplitter(); @@ -74,7 +76,7 @@ public class IdentifierSplitter extends BaseSplitter { for (TextRange word : words) { boolean uc = Strings.isUpperCased(text, word); boolean flag = (uc && !isAllWordsAreUpperCased); - Matcher matcher = WORD.matcher(text.substring(word.getStartOffset(), word.getEndOffset())); + Matcher matcher = WORD.matcher(newBombedCharSequence(text.substring(word.getStartOffset(), word.getEndOffset()), 500)); if (matcher.find()) { TextRange found = matcherRange(word, matcher); addWord(consumer, flag, found); diff --git a/spellchecker/src/com/intellij/spellchecker/inspections/PlainTextSplitter.java b/spellchecker/src/com/intellij/spellchecker/inspections/PlainTextSplitter.java index cd464c9a557a..31d584d3cfa5 100644 --- a/spellchecker/src/com/intellij/spellchecker/inspections/PlainTextSplitter.java +++ b/spellchecker/src/com/intellij/spellchecker/inspections/PlainTextSplitter.java @@ -28,10 +28,12 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static com.intellij.openapi.util.text.StringUtil.newBombedCharSequence; import static com.intellij.util.io.URLUtil.URL_PATTERN; public class PlainTextSplitter extends BaseSplitter { private static final PlainTextSplitter INSTANCE = new PlainTextSplitter(); + public static final int DELAY = 500; public static PlainTextSplitter getInstance() { return INSTANCE; @@ -52,14 +54,14 @@ public class PlainTextSplitter extends BaseSplitter { } final String substring = range.substring(text).replace('\b', '\n').replace('\f', '\n'); - if (Verifier.checkCharacterData(SPLIT_PATTERN.matcher(substring).replaceAll("")) != null) { + if (Verifier.checkCharacterData(SPLIT_PATTERN.matcher(newBombedCharSequence(substring, DELAY)).replaceAll("")) != null) { return; } final TextSplitter ws = TextSplitter.getInstance(); int from = range.getStartOffset(); int till; - Matcher matcher = SPLIT_PATTERN.matcher(range.substring(text)); + Matcher matcher = SPLIT_PATTERN.matcher(newBombedCharSequence(range.substring(text), DELAY)); while (true) { checkCancelled(); List toCheck; diff --git a/spellchecker/src/com/intellij/spellchecker/inspections/PropertiesSplitter.java b/spellchecker/src/com/intellij/spellchecker/inspections/PropertiesSplitter.java index 77e6117774cc..1f2d2e7bd642 100644 --- a/spellchecker/src/com/intellij/spellchecker/inspections/PropertiesSplitter.java +++ b/spellchecker/src/com/intellij/spellchecker/inspections/PropertiesSplitter.java @@ -25,6 +25,8 @@ import org.jetbrains.annotations.Nullable; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static com.intellij.openapi.util.text.StringUtil.newBombedCharSequence; + public class PropertiesSplitter extends BaseSplitter { private static final PropertiesSplitter INSTANCE = new PropertiesSplitter(); @@ -41,7 +43,7 @@ public class PropertiesSplitter extends BaseSplitter { return; } final IdentifierSplitter splitter = IdentifierSplitter.getInstance(); - Matcher matcher = WORD.matcher(range.substring(text)); + Matcher matcher = WORD.matcher(newBombedCharSequence(range.substring(text), 500)); while (matcher.find()) { if (matcher.end() - matcher.start() < MIN_RANGE_LENGTH) { continue; diff --git a/spellchecker/src/com/intellij/spellchecker/inspections/TextSplitter.java b/spellchecker/src/com/intellij/spellchecker/inspections/TextSplitter.java index ee1bb895e57d..fcc784883a9e 100644 --- a/spellchecker/src/com/intellij/spellchecker/inspections/TextSplitter.java +++ b/spellchecker/src/com/intellij/spellchecker/inspections/TextSplitter.java @@ -24,6 +24,8 @@ import org.jetbrains.annotations.Nullable; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static com.intellij.openapi.util.text.StringUtil.newBombedCharSequence; + public class TextSplitter extends BaseSplitter { private static final TextSplitter INSTANCE = new TextSplitter(); @@ -43,7 +45,7 @@ public class TextSplitter extends BaseSplitter { protected void doSplit(@NotNull String text, @NotNull TextRange range, Consumer consumer) { final WordSplitter ws = WordSplitter.getInstance(); - Matcher matcher = EXTENDED_WORD_AND_SPECIAL.matcher(text); + Matcher matcher = EXTENDED_WORD_AND_SPECIAL.matcher(newBombedCharSequence(text, 500)); matcher.region(range.getStartOffset(), range.getEndOffset()); while (matcher.find()) { TextRange found = new TextRange(matcher.start(), matcher.end()); diff --git a/spellchecker/src/com/intellij/spellchecker/inspections/WordSplitter.java b/spellchecker/src/com/intellij/spellchecker/inspections/WordSplitter.java index e4290d578d59..12b8579a5a33 100644 --- a/spellchecker/src/com/intellij/spellchecker/inspections/WordSplitter.java +++ b/spellchecker/src/com/intellij/spellchecker/inspections/WordSplitter.java @@ -24,6 +24,8 @@ import org.jetbrains.annotations.Nullable; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static com.intellij.openapi.util.text.StringUtil.newBombedCharSequence; + public class WordSplitter extends BaseSplitter { private static final WordSplitter INSTANCE = new WordSplitter(); @@ -39,7 +41,7 @@ public class WordSplitter extends BaseSplitter { if (text == null || range.getLength() <= 1) { return; } - Matcher specialMatcher = SPECIAL.matcher(text); + Matcher specialMatcher = SPECIAL.matcher(newBombedCharSequence(text, 500)); specialMatcher.region(range.getStartOffset(), range.getEndOffset()); if (specialMatcher.find()) { TextRange found = new TextRange(specialMatcher.start(), specialMatcher.end());