下面列出了com.intellij.psi.search.GlobalSearchScope#getScopeRestrictedByFileTypes ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void iterateXmlDocumentRoots(Module module, Consumer<XmlTag> rootTag) {
final GlobalSearchScope moduleScope = module.getModuleContentScope();
final GlobalSearchScope xmlFiles = GlobalSearchScope.getScopeRestrictedByFileTypes(moduleScope, XmlFileType.INSTANCE);
ModuleFileIndex fileIndex = ModuleRootManager.getInstance(module).getFileIndex();
fileIndex.iterateContent(f -> {
if (xmlFiles.contains(f)) {
PsiFile file = PsiManager.getInstance(module.getProject()).findFile(f);
if (file instanceof XmlFile) {
XmlFile xmlFile = (XmlFile) file;
XmlTag root = xmlFile.getRootTag();
if (root != null) {
rootTag.accept(xmlFile.getRootTag());
}
}
}
return true;
});
}
public SchemaIDLTypeDefinitionRegistry(Project project) {
this.project = project;
scope = GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.projectScope(project), GraphQLFileType.INSTANCE);
introspectionScope = GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.projectScope(project), JsonFileType.INSTANCE);
psiManager = PsiManager.getInstance(project);
graphQLEndpointNamedTypeRegistry = JSGraphQLEndpointNamedTypeRegistry.getService(project);
graphQLPsiSearchHelper = GraphQLPsiSearchHelper.getService(project);
graphQLConfigManager = GraphQLConfigManager.getService(project);
graphQLInjectionSearchHelper = ServiceManager.getService(GraphQLInjectionSearchHelper.class);
project.getMessageBus().connect().subscribe(GraphQLSchemaChangeListener.TOPIC, new GraphQLSchemaEventListener() {
@Override
public void onGraphQLSchemaChanged(Integer schemaVersion) {
scopeToRegistry.clear();
}
});
}
@Nullable
@Override
public GlobalSearchScope getScopeToExclude(PsiElement element) {
if (!enabled.getValue()) {
return null;
}
if (element instanceof PsiFileSystemItem) {
return GlobalSearchScope.getScopeRestrictedByFileTypes(
new EverythingGlobalScope(), BuildFileType.INSTANCE);
}
return null;
}
private static void searchForString(
SearchParameters params, SearchScope scope, PsiElement element, String string) {
if (scope instanceof GlobalSearchScope) {
scope =
GlobalSearchScope.getScopeRestrictedByFileTypes(
(GlobalSearchScope) scope, BuildFileType.INSTANCE);
}
params.getOptimizer().searchWord(string, scope, UsageSearchContext.IN_STRINGS, true, element);
}
public static GlobalSearchScope bashOnly(GlobalSearchScope scope) {
return GlobalSearchScope.getScopeRestrictedByFileTypes(scope, BashFileType.BASH_FILE_TYPE);
}
/**
* So support only some file types, so we can filter them and xml and yaml for now
*/
public static GlobalSearchScope getRestrictedFileTypesScope(@NotNull Project project) {
return GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), XmlFileType.INSTANCE, YAMLFileType.YML, PhpFileType.INSTANCE);
}