mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
[spelling] IJPL-159316 Spelling: make Splitter implementations cancellable
GitOrigin-RevId: c192e1f540e26061634e3bc219da127f7f685b4d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7e75c193eb
commit
c52bceef8e
@@ -4,6 +4,7 @@ package com.intellij.spellchecker.inspections;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProgressIndicatorProvider;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Consumer;
|
||||
@@ -29,6 +30,8 @@ public abstract class BaseSplitter implements Splitter {
|
||||
if (tooShort) {
|
||||
return;
|
||||
}
|
||||
|
||||
ProgressManager.checkCanceled();
|
||||
consumer.consume(found);
|
||||
}
|
||||
|
||||
@@ -109,19 +112,27 @@ public abstract class BaseSplitter implements Splitter {
|
||||
}
|
||||
}
|
||||
|
||||
private static final int PROCESSING_TIME_LIMIT = 500;
|
||||
|
||||
/**
|
||||
* @throws TooLongBombedMatchingException in case processing is longer than {@link #PROCESSING_TIME_LIMIT}
|
||||
*/
|
||||
protected static CharSequence newBombedCharSequence(String text, TextRange range) {
|
||||
return newBombedCharSequence(range.substring(text));
|
||||
}
|
||||
|
||||
protected static CharSequence newBombedCharSequence(final String substring) {
|
||||
final long myTime = System.currentTimeMillis() + 500;
|
||||
/**
|
||||
* @throws TooLongBombedMatchingException in case processing is longer than {@link #PROCESSING_TIME_LIMIT}
|
||||
*/
|
||||
protected static CharSequence newBombedCharSequence(String substring) {
|
||||
return new StringUtil.BombedCharSequence(substring) {
|
||||
final long myTime = System.currentTimeMillis() + PROCESSING_TIME_LIMIT;
|
||||
|
||||
@Override
|
||||
protected void checkCanceled() {
|
||||
//todo[anna] if (ApplicationManager.getApplication().isHeadlessEnvironment()) return;
|
||||
long l = System.currentTimeMillis();
|
||||
if (l >= myTime) {
|
||||
throw new ProcessCanceledException();
|
||||
throw new TooLongBombedMatchingException();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -132,4 +143,7 @@ public abstract class BaseSplitter implements Splitter {
|
||||
ProgressIndicatorProvider.checkCanceled();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class TooLongBombedMatchingException extends ProcessCanceledException {
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.spellchecker.inspections;
|
||||
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.spellchecker.util.Strings;
|
||||
import com.intellij.util.Consumer;
|
||||
@@ -22,8 +21,6 @@ public class IdentifierSplitter extends BaseSplitter {
|
||||
}
|
||||
|
||||
private static final @NonNls Pattern WORD = Pattern.compile("\\b\\p{L}*'?\\p{L}*");
|
||||
|
||||
|
||||
private static final @NonNls Pattern WORD_IN_QUOTES = Pattern.compile("'([^']*)'");
|
||||
|
||||
@Override
|
||||
@@ -37,7 +34,7 @@ public class IdentifierSplitter extends BaseSplitter {
|
||||
for (TextRange textRange : extracted) {
|
||||
List<TextRange> words = splitByCase(text, textRange);
|
||||
|
||||
if (words.size() == 0) {
|
||||
if (words.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -65,7 +62,7 @@ public class IdentifierSplitter extends BaseSplitter {
|
||||
addWord(consumer, flag, found);
|
||||
}
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
catch (TooLongBombedMatchingException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -138,7 +135,7 @@ public class IdentifierSplitter extends BaseSplitter {
|
||||
|
||||
private static void add(String text, List<TextRange> result, int i, int s) {
|
||||
if (i - s > 3) {
|
||||
final TextRange textRange = new TextRange(s, i);
|
||||
TextRange textRange = new TextRange(s, i);
|
||||
//System.out.println("textRange = " + textRange + " = "+ textRange.substring(text));
|
||||
result.add(textRange);
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ public class PlainTextSplitter extends BaseSplitter {
|
||||
if (matcher.hitEnd()) break;
|
||||
}
|
||||
}
|
||||
catch (ProcessCanceledException ignored) {
|
||||
catch (TooLongBombedMatchingException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,6 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.spellchecker.inspections;
|
||||
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Consumer;
|
||||
@@ -51,7 +36,7 @@ public final class PropertiesSplitter extends BaseSplitter {
|
||||
splitter.split(text, found, consumer);
|
||||
}
|
||||
}
|
||||
catch (ProcessCanceledException ignored) {
|
||||
catch (TooLongBombedMatchingException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.spellchecker.inspections;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
@@ -20,7 +6,6 @@ import com.intellij.util.Consumer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
||||
public interface Splitter {
|
||||
void split(@Nullable String text, @NotNull TextRange range, Consumer<TextRange> consumer);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.spellchecker.inspections;
|
||||
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Consumer;
|
||||
@@ -51,7 +50,7 @@ public class TextSplitter extends BaseSplitter {
|
||||
ws.split(text, found, consumer);
|
||||
}
|
||||
}
|
||||
catch (ProcessCanceledException ignored) {
|
||||
catch (TooLongBombedMatchingException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,6 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.spellchecker.inspections;
|
||||
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.util.Consumer;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -39,6 +24,7 @@ public final class WordSplitter extends BaseSplitter {
|
||||
if (text == null || range.getLength() <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Matcher specialMatcher = SPECIAL.matcher(newBombedCharSequence(text));
|
||||
specialMatcher.region(range.getStartOffset(), range.getEndOffset());
|
||||
@@ -50,7 +36,7 @@ public final class WordSplitter extends BaseSplitter {
|
||||
IdentifierSplitter.getInstance().split(text, range, consumer);
|
||||
}
|
||||
}
|
||||
catch (ProcessCanceledException ignored) {
|
||||
catch (TooLongBombedMatchingException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user