mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
use BombedCharSequence for cancellability of reg exp based searches
This commit is contained in:
@@ -18,6 +18,7 @@ package com.intellij.find;
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase;
|
||||
import com.intellij.find.impl.FindInProjectUtil;
|
||||
import com.intellij.find.impl.FindResultImpl;
|
||||
import com.intellij.find.replaceInProject.ReplaceInProjectManager;
|
||||
import com.intellij.lang.properties.IProperty;
|
||||
import com.intellij.lang.properties.psi.PropertiesFile;
|
||||
@@ -29,9 +30,13 @@ import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.fileTypes.FileTypes;
|
||||
import com.intellij.openapi.fileTypes.PlainTextFileType;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.progress.util.ProgressIndicatorBase;
|
||||
import com.intellij.openapi.project.DumbServiceImpl;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.util.ProperTextRange;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
@@ -68,6 +73,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
/**
|
||||
* @author MYakovlev
|
||||
@@ -836,6 +842,41 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
assertSize(0, findUsages(findModel));
|
||||
}
|
||||
|
||||
public void testRegExpSearchDoesCheckCancelled() throws InterruptedException {
|
||||
String text = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
||||
FindModel findModel = FindManagerTestUtils.configureFindModel("(x+x+)+y");
|
||||
findModel.setRegularExpressions(true);
|
||||
|
||||
runAsyncTest(text, findModel);
|
||||
findModel.setSearchContext(FindModel.SearchContext.IN_COMMENTS);
|
||||
runAsyncTest("/*" + text + "*/", findModel);
|
||||
}
|
||||
|
||||
private void runAsyncTest(String text, FindModel findModel) throws InterruptedException {
|
||||
final Ref<FindResult> result = new Ref<>();
|
||||
final CountDownLatch progressStarted = new CountDownLatch(1);
|
||||
final ProgressIndicatorBase progressIndicatorBase = new ProgressIndicatorBase();
|
||||
final Thread thread = new Thread(() -> {
|
||||
ProgressManager.getInstance().runProcess(() -> {
|
||||
try {
|
||||
progressStarted.countDown();
|
||||
result.set(myFindManager.findString(text, 0, findModel, new LightVirtualFile("foo.java")));
|
||||
}
|
||||
catch (ProcessCanceledException ex) {
|
||||
result.set(new FindResultImpl());
|
||||
}
|
||||
}, progressIndicatorBase);
|
||||
});
|
||||
thread.start();
|
||||
|
||||
progressStarted.await();
|
||||
thread.join(100);
|
||||
progressIndicatorBase.cancel();
|
||||
thread.join(500);
|
||||
assertNotNull(result.get());
|
||||
assertTrue(!result.get().isStringFound());
|
||||
}
|
||||
|
||||
private void doTestRegexpReplace(String initialText, String searchString, String replaceString, String expectedResult) {
|
||||
configureByText(FileTypes.PLAIN_TEXT, initialText);
|
||||
FindModel model = new FindModel();
|
||||
|
||||
Reference in New Issue
Block a user