mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
introduce predefined ProjectScope#getEverythingScope
This commit is contained in:
@@ -193,10 +193,16 @@ public abstract class GlobalSearchScope extends SearchScope implements ProjectAw
|
||||
return ProjectScope.getProjectScope(project);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static GlobalSearchScope everythingScope(@NotNull Project project) {
|
||||
return ProjectScope.getEverythingScope(project);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static GlobalSearchScope notScope(@NotNull final GlobalSearchScope scope) {
|
||||
return new NotScope(scope);
|
||||
}
|
||||
|
||||
private static class NotScope extends DelegatingGlobalSearchScope {
|
||||
private NotScope(@NotNull GlobalSearchScope scope) {
|
||||
super(scope);
|
||||
@@ -322,8 +328,8 @@ public abstract class GlobalSearchScope extends SearchScope implements ProjectAw
|
||||
|
||||
/**
|
||||
* Optimization. By default FilesScope makes a decision about searching in libraries by checking that
|
||||
* at least one file is placed out of module roots. So if you're sure about files placement you can explicitly say FilesScope whether
|
||||
* it should include libraries or not in order to avoid checking each file.
|
||||
* at least one file is placed out of module roots. So if you're sure about files placement you can explicitly say FilesScope whether
|
||||
* it should include libraries or not in order to avoid checking each file.
|
||||
* Also, if you have a lot of files it might be faster to always search in libraries.
|
||||
*/
|
||||
@NotNull
|
||||
@@ -331,7 +337,7 @@ public abstract class GlobalSearchScope extends SearchScope implements ProjectAw
|
||||
if (files.isEmpty()) return EMPTY_SCOPE;
|
||||
return new FilesScope(project, files, false);
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static GlobalSearchScope filesWithLibrariesScope(@NotNull Project project, @NotNull Collection<VirtualFile> files) {
|
||||
if (files.isEmpty()) return EMPTY_SCOPE;
|
||||
@@ -805,7 +811,7 @@ public abstract class GlobalSearchScope extends SearchScope implements ProjectAw
|
||||
public int hashCode() {
|
||||
return myFiles.hashCode();
|
||||
}
|
||||
|
||||
|
||||
private boolean hasFilesOutOfProjectRoots() {
|
||||
if (myHasFilesOutOfProjectRoots == null) {
|
||||
myHasFilesOutOfProjectRoots = false;
|
||||
|
||||
@@ -20,40 +20,89 @@
|
||||
package com.intellij.psi.search;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.UserDataHolderEx;
|
||||
import com.intellij.openapi.util.NotNullLazyKey;
|
||||
import com.intellij.util.NotNullFunction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ProjectScope {
|
||||
private static final Key<GlobalSearchScope> ALL_SCOPE_KEY = new Key<GlobalSearchScope>("ALL_SCOPE_KEY");
|
||||
private static final Key<GlobalSearchScope> PROJECT_SCOPE_KEY = new Key<GlobalSearchScope>("PROJECT_SCOPE_KEY");
|
||||
private static final Key<GlobalSearchScope> LIBRARIES_SCOPE_KEY = new Key<GlobalSearchScope>("LIBRARIES_SCOPE_KEY");
|
||||
private static final Key<GlobalSearchScope> CONTENT_SCOPE_KEY = new Key<GlobalSearchScope>("CONTENT_SCOPE_KEY");
|
||||
|
||||
private static final NotNullLazyKey<GlobalSearchScope, Project> ALL_SCOPE_KEY = NotNullLazyKey.create(
|
||||
"ALL_SCOPE_KEY",
|
||||
new NotNullFunction<Project, GlobalSearchScope>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public GlobalSearchScope fun(Project project) {
|
||||
return ProjectScopeBuilder.getInstance(project).buildAllScope();
|
||||
}
|
||||
});
|
||||
private static final NotNullLazyKey<GlobalSearchScope, Project> PROJECT_SCOPE_KEY = NotNullLazyKey.create(
|
||||
"PROJECT_SCOPE_KEY",
|
||||
new NotNullFunction<Project, GlobalSearchScope>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public GlobalSearchScope fun(Project project) {
|
||||
return ProjectScopeBuilder.getInstance(project).buildProjectScope();
|
||||
}
|
||||
});
|
||||
private static final NotNullLazyKey<GlobalSearchScope, Project> LIBRARIES_SCOPE_KEY = NotNullLazyKey.create(
|
||||
"LIBRARIES_SCOPE_KEY",
|
||||
new NotNullFunction<Project, GlobalSearchScope>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public GlobalSearchScope fun(Project project) {
|
||||
return ProjectScopeBuilder.getInstance(project).buildLibrariesScope();
|
||||
}
|
||||
});
|
||||
private static final NotNullLazyKey<GlobalSearchScope, Project> CONTENT_SCOPE_KEY = NotNullLazyKey.create(
|
||||
"CONTENT_SCOPE_KEY",
|
||||
new NotNullFunction<Project, GlobalSearchScope>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public GlobalSearchScope fun(Project project) {
|
||||
return ProjectScopeBuilder.getInstance(project).buildContentScope();
|
||||
}
|
||||
});
|
||||
private static final NotNullLazyKey<EverythingGlobalScope, Project> EVERYTHING_SCOPE_KEY = NotNullLazyKey.create(
|
||||
"ALL_PLACES",
|
||||
new NotNullFunction<Project, EverythingGlobalScope>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public EverythingGlobalScope fun(Project project) {
|
||||
return new EverythingGlobalScope(project) {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "All Places";
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
private ProjectScope() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static GlobalSearchScope getAllScope(@NotNull Project project) {
|
||||
GlobalSearchScope cached = project.getUserData(ALL_SCOPE_KEY);
|
||||
return cached != null ? cached : ((UserDataHolderEx)project).putUserDataIfAbsent(ALL_SCOPE_KEY, ProjectScopeBuilder.getInstance(project).buildAllScope());
|
||||
return ALL_SCOPE_KEY.getValue(project);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static GlobalSearchScope getProjectScope(@NotNull Project project) {
|
||||
GlobalSearchScope cached = project.getUserData(PROJECT_SCOPE_KEY);
|
||||
return cached != null ? cached : ((UserDataHolderEx)project).putUserDataIfAbsent(PROJECT_SCOPE_KEY, ProjectScopeBuilder.getInstance(project).buildProjectScope());
|
||||
return PROJECT_SCOPE_KEY.getValue(project);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static GlobalSearchScope getLibrariesScope(@NotNull Project project) {
|
||||
GlobalSearchScope cached = project.getUserData(LIBRARIES_SCOPE_KEY);
|
||||
return cached != null ? cached : ((UserDataHolderEx)project).putUserDataIfAbsent(LIBRARIES_SCOPE_KEY, ProjectScopeBuilder.getInstance(project).buildLibrariesScope());
|
||||
return LIBRARIES_SCOPE_KEY.getValue(project);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static GlobalSearchScope getContentScope(@NotNull Project project) {
|
||||
GlobalSearchScope cached = project.getUserData(CONTENT_SCOPE_KEY);
|
||||
return cached != null ? cached : ((UserDataHolderEx)project).putUserDataIfAbsent(CONTENT_SCOPE_KEY, ProjectScopeBuilder.getInstance(project).buildContentScope());
|
||||
return CONTENT_SCOPE_KEY.get(project);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static GlobalSearchScope getEverythingScope(@NotNull Project project) {
|
||||
return EVERYTHING_SCOPE_KEY.getValue(project);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ public class PredefinedSearchScopeProviderImpl extends PredefinedSearchScopeProv
|
||||
boolean usageView,
|
||||
boolean showEmptyScopes) {
|
||||
Collection<SearchScope> result = ContainerUtil.newLinkedHashSet();
|
||||
result.add(GlobalSearchScope.everythingScope(project));
|
||||
result.add(GlobalSearchScope.projectScope(project));
|
||||
if (suggestSearchInLibs) {
|
||||
result.add(GlobalSearchScope.allScope(project));
|
||||
|
||||
Reference in New Issue
Block a user