mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ensure usages in comments are not found in scratches during safe delete (IDEA-165748)
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
class Test {
|
||||
public void na<caret>me() {}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
class Test {
|
||||
}
|
||||
@@ -61,6 +61,7 @@ import com.intellij.usageView.UsageViewUtil;
|
||||
import com.intellij.usages.*;
|
||||
import com.intellij.usages.rules.PsiElementUsage;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.ThrowableRunnable;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
@@ -74,6 +75,7 @@ import java.util.*;
|
||||
|
||||
public abstract class BaseRefactoringProcessor implements Runnable {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.BaseRefactoringProcessor");
|
||||
private static boolean PREVIEW_IN_TESTS = true;
|
||||
|
||||
@NotNull
|
||||
protected final Project myProject;
|
||||
@@ -226,8 +228,20 @@ public abstract class BaseRefactoringProcessor implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public static <T extends Throwable> void runWithDisabledPreview(ThrowableRunnable<T> runnable) throws T {
|
||||
PREVIEW_IN_TESTS = false;
|
||||
try {
|
||||
runnable.run();
|
||||
}
|
||||
finally {
|
||||
PREVIEW_IN_TESTS = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected void previewRefactoring(@NotNull UsageInfo[] usages) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
if (!PREVIEW_IN_TESTS) throw new RuntimeException("Unexpected preview in tests: " + StringUtil.join(usages, info -> info.toString(), ", "));
|
||||
ensureElementsWritable(usages, createUsageViewDescriptor(usages));
|
||||
execute(usages);
|
||||
return;
|
||||
|
||||
@@ -76,7 +76,7 @@ public class TextOccurrencesUtil {
|
||||
@NotNull final PairProcessor<PsiElement, TextRange> processor) {
|
||||
PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(element.getProject());
|
||||
SearchScope scope = helper.getUseScope(element);
|
||||
scope = GlobalSearchScope.projectScope(element.getProject()).intersectWith(scope);
|
||||
scope = scope.intersectWith(GlobalSearchScope.projectScope(element.getProject()));
|
||||
Processor<PsiElement> commentOrLiteralProcessor = literal -> processTextIn(literal, stringToSearch, ignoreReferences, processor);
|
||||
return processStringLiteralsContainingIdentifier(stringToSearch, scope, helper, commentOrLiteralProcessor) &&
|
||||
helper.processCommentsContainingIdentifier(stringToSearch, scope, commentOrLiteralProcessor);
|
||||
|
||||
Reference in New Issue
Block a user