mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-83478 Find in Path is not working correctly (missing occurences)
This commit is contained in:
@@ -0,0 +1 @@
|
||||
// TargetWord
|
||||
@@ -0,0 +1 @@
|
||||
// TargetWord
|
||||
@@ -20,8 +20,14 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.testFramework.fixtures.TempDirTestFixture;
|
||||
import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.usages.Usage;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ThrowableRunnable;
|
||||
import com.intellij.util.WaitFor;
|
||||
|
||||
import java.io.File;
|
||||
@@ -360,4 +366,63 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
assertEquals(newText, getEditor().getDocument().getText());
|
||||
}
|
||||
|
||||
public void testFindInFileUnderLibraryUnderProject() throws Exception {
|
||||
initProject("libUnderProject", "src");
|
||||
PsiTestUtil.addLibrary(myModule, "lib", JavaTestUtil.getJavaTestDataPath() + "/find/libUnderProject/lib", new String[]{""}, ArrayUtil.EMPTY_STRING_ARRAY);
|
||||
|
||||
FindModel findModel = new FindModel();
|
||||
findModel.setStringToFind("TargetWord");
|
||||
findModel.setFromCursor(false);
|
||||
findModel.setGlobal(true);
|
||||
findModel.setMultipleFiles(true);
|
||||
|
||||
findModel.setWholeWordsOnly(false);
|
||||
assertSize(2, findUsages(findModel));
|
||||
|
||||
/* todo
|
||||
findModel.setWholeWordsOnly(true);
|
||||
assertSize(2, findUsages(findModel));
|
||||
*/
|
||||
}
|
||||
|
||||
public void testLocalScopeSearchPerformance() throws Exception {
|
||||
final int count = 3000;
|
||||
TempDirTestFixture fixture = new LightTempDirTestFixtureImpl();
|
||||
fixture.setUp();
|
||||
|
||||
try {
|
||||
String sampleText = StringUtil.repeat("zoo TargetWord foo bar goo\n", count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
fixture.createFile("a" + i + ".txt", sampleText);
|
||||
}
|
||||
PsiTestUtil.addSourceContentToRoots(myModule, fixture.getFile(""));
|
||||
|
||||
VirtualFile file = fixture.createFile("target.txt", sampleText);
|
||||
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
|
||||
final FindModel findModel = new FindModel();
|
||||
findModel.setStringToFind("TargetWord");
|
||||
findModel.setWholeWordsOnly(true);
|
||||
findModel.setFromCursor(false);
|
||||
findModel.setGlobal(true);
|
||||
findModel.setMultipleFiles(true);
|
||||
|
||||
ThrowableRunnable test = new ThrowableRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
assertSize(count, findUsages(findModel));
|
||||
}
|
||||
};
|
||||
|
||||
findModel.setCustomScope(GlobalSearchScope.fileScope(psiFile));
|
||||
PlatformTestUtil.startPerformanceTest("slow", 500, test).attempts(1).cpuBound().usesAllCPUCores().assertTiming();
|
||||
|
||||
findModel.setCustomScope(new LocalSearchScope(psiFile));
|
||||
PlatformTestUtil.startPerformanceTest("slow", 500, test).attempts(1).cpuBound().usesAllCPUCores().assertTiming();
|
||||
}
|
||||
finally {
|
||||
fixture.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -393,7 +393,7 @@ public class FindInProjectUtil {
|
||||
public boolean processFile(@NotNull VirtualFile virtualFile) {
|
||||
if (!virtualFile.isDirectory() &&
|
||||
(fileMaskRegExp == null || fileMaskRegExp.matcher(virtualFile.getName()).matches()) &&
|
||||
customScope.contains(virtualFile)) {
|
||||
(customScope == null || customScope.contains(virtualFile))) {
|
||||
final PsiFile psiFile = psiManager.findFile(virtualFile);
|
||||
if (psiFile != null && !filesForFastWordSearch.contains(psiFile)) {
|
||||
myFiles.add(psiFile);
|
||||
@@ -411,7 +411,7 @@ public class FindInProjectUtil {
|
||||
|
||||
if (psiDirectory == null) {
|
||||
boolean success = fileIndex.iterateContent(iterator);
|
||||
if (success && customScope.isSearchInLibraries()) {
|
||||
if (success && customScope != null && customScope.isSearchInLibraries()) {
|
||||
OrderEnumerator enumerator = module == null ? OrderEnumerator.orderEntries(project) : OrderEnumerator.orderEntries(module);
|
||||
final VirtualFile[] librarySources = enumerator.withoutModuleSourceEntries().withoutDepModules().getSourceRoots();
|
||||
iterateAll(librarySources, customScope, iterator);
|
||||
@@ -451,14 +451,11 @@ public class FindInProjectUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
private static GlobalSearchScope toGlobal(@NotNull Project project, @Nullable SearchScope scope) {
|
||||
if (scope instanceof GlobalSearchScope) {
|
||||
if (scope instanceof GlobalSearchScope || scope == null) {
|
||||
return (GlobalSearchScope)scope;
|
||||
}
|
||||
if (scope == null) {
|
||||
return projectContentScope(project);
|
||||
}
|
||||
Set<VirtualFile> files = new HashSet<VirtualFile>();
|
||||
for (PsiElement element : ((LocalSearchScope)scope).getScope()) {
|
||||
PsiFile file = element.getContainingFile();
|
||||
@@ -471,8 +468,8 @@ public class FindInProjectUtil {
|
||||
|
||||
@NotNull
|
||||
private static Pair<Boolean, Collection<PsiFile>> getFilesForFastWordSearch(@NotNull final FindModel findModel, @NotNull final Project project,
|
||||
@Nullable final PsiDirectory psiDirectory, final Pattern fileMaskRegExp,
|
||||
@Nullable final Module module) {
|
||||
@Nullable final PsiDirectory psiDirectory, final Pattern fileMaskRegExp,
|
||||
@Nullable final Module module) {
|
||||
if (DumbService.getInstance(project).isDumb()) {
|
||||
return new Pair<Boolean, Collection<PsiFile>>(false, Collections.<PsiFile>emptyList());
|
||||
}
|
||||
@@ -480,13 +477,16 @@ public class FindInProjectUtil {
|
||||
PsiManager pm = PsiManager.getInstance(project);
|
||||
CacheManager cacheManager = CacheManager.SERVICE.getInstance(project);
|
||||
SearchScope customScope = findModel.getCustomScope();
|
||||
@NotNull GlobalSearchScope scope = psiDirectory != null
|
||||
? GlobalSearchScopes.directoryScope(psiDirectory, true)
|
||||
: module != null
|
||||
? moduleContentScope(module)
|
||||
: customScope instanceof GlobalSearchScope
|
||||
? (GlobalSearchScope)customScope
|
||||
: toGlobal(project, customScope);
|
||||
GlobalSearchScope scope = psiDirectory != null
|
||||
? GlobalSearchScopes.directoryScope(psiDirectory, true)
|
||||
: module != null
|
||||
? moduleContentScope(module)
|
||||
: customScope instanceof GlobalSearchScope
|
||||
? (GlobalSearchScope)customScope
|
||||
: toGlobal(project, customScope);
|
||||
if (scope == null) {
|
||||
scope = GlobalSearchScope.projectScope(project);
|
||||
}
|
||||
|
||||
Set<Integer> keys = new THashSet<Integer>(30);
|
||||
Set<PsiFile> resultFiles = new THashSet<PsiFile>();
|
||||
@@ -554,16 +554,7 @@ public class FindInProjectUtil {
|
||||
return new Pair<Boolean, Collection<PsiFile>>(fast, resultFiles);
|
||||
}
|
||||
|
||||
private static GlobalSearchScope projectContentScope(final Project project) {
|
||||
GlobalSearchScope result = null;
|
||||
for (Module module : ModuleManager.getInstance(project).getModules()) {
|
||||
GlobalSearchScope moduleContent = moduleContentScope(module);
|
||||
result = result == null ? moduleContent : result.uniteWith(moduleContent);
|
||||
}
|
||||
return result == null ? GlobalSearchScope.EMPTY_SCOPE : result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NotNull
|
||||
private static GlobalSearchScope moduleContentScope(@NotNull final Module module) {
|
||||
VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots();
|
||||
GlobalSearchScope result = null;
|
||||
|
||||
@@ -286,7 +286,7 @@ import java.util.Collection;
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
final String parentUrl = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, libDir);
|
||||
final String parentUrl = VirtualFileManager.constructUrl(classRoots[0].endsWith(".jar!/") ? JarFileSystem.PROTOCOL : LocalFileSystem.PROTOCOL, libDir);
|
||||
final Library library = model.getModuleLibraryTable().createLibrary(libName);
|
||||
final Library.ModifiableModel libModifiableModel = library.getModifiableModel();
|
||||
for (String classRoot : classRoots) {
|
||||
|
||||
Reference in New Issue
Block a user