Pass project explicitly to JetSourceFilterScope

This commit is contained in:
Pavel V. Talanov
2014-07-23 17:12:23 +04:00
committed by Alexander Udalov
parent 3f7050635c
commit 9c58cb9f31
17 changed files with 32 additions and 28 deletions
@@ -160,13 +160,13 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport
@NotNull @NotNull
@Override @Override
public Collection<JetClassOrObject> findClassOrObjectDeclarations(@NotNull FqName fqName, @NotNull GlobalSearchScope searchScope) { public Collection<JetClassOrObject> findClassOrObjectDeclarations(@NotNull FqName fqName, @NotNull GlobalSearchScope searchScope) {
return JetFullClassNameIndex.getInstance().get(fqName.asString(), project, kotlinSources(searchScope)); return JetFullClassNameIndex.getInstance().get(fqName.asString(), project, kotlinSources(searchScope, project));
} }
@NotNull @NotNull
@Override @Override
public Collection<JetFile> findFilesForPackage(@NotNull FqName fqName, @NotNull GlobalSearchScope searchScope) { public Collection<JetFile> findFilesForPackage(@NotNull FqName fqName, @NotNull GlobalSearchScope searchScope) {
return PackageIndexUtil.findFilesWithExactPackage(fqName, kotlinSources(searchScope), project); return PackageIndexUtil.findFilesWithExactPackage(fqName, kotlinSources(searchScope, project), project);
} }
@NotNull @NotNull
@@ -174,18 +174,18 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport
public Collection<JetClassOrObject> findClassOrObjectDeclarationsInPackage( public Collection<JetClassOrObject> findClassOrObjectDeclarationsInPackage(
@NotNull FqName packageFqName, @NotNull GlobalSearchScope searchScope @NotNull FqName packageFqName, @NotNull GlobalSearchScope searchScope
) { ) {
return JetClassByPackageIndex.getInstance().get(packageFqName.asString(), project, kotlinSources(searchScope)); return JetClassByPackageIndex.getInstance().get(packageFqName.asString(), project, kotlinSources(searchScope, project));
} }
@Override @Override
public boolean packageExists(@NotNull FqName fqName, @NotNull GlobalSearchScope scope) { public boolean packageExists(@NotNull FqName fqName, @NotNull GlobalSearchScope scope) {
return !JetAllPackagesIndex.getInstance().get(fqName.asString(), project, kotlinSources(scope)).isEmpty(); return !JetAllPackagesIndex.getInstance().get(fqName.asString(), project, kotlinSources(scope, project)).isEmpty();
} }
@NotNull @NotNull
@Override @Override
public Collection<FqName> getSubPackages(@NotNull FqName fqn, @NotNull GlobalSearchScope scope) { public Collection<FqName> getSubPackages(@NotNull FqName fqn, @NotNull GlobalSearchScope scope) {
return PackageIndexUtil.getSubPackageFqNames(fqn, kotlinSources(scope), project); return PackageIndexUtil.getSubPackageFqNames(fqn, kotlinSources(scope, project), project);
} }
@Nullable @Nullable
@@ -136,7 +136,7 @@ class KotlinCacheService(val project: Project) {
} }
private fun kotlinSourcesInProjectScope(): GlobalSearchScope { private fun kotlinSourcesInProjectScope(): GlobalSearchScope {
return JetSourceFilterScope.kotlinSources(GlobalSearchScope.allScope(project)) return JetSourceFilterScope.kotlinSources(GlobalSearchScope.allScope(project), project)
} }
public fun <T> get(extension: CacheExtension<T>): T { public fun <T> get(extension: CacheExtension<T>): T {
@@ -31,7 +31,7 @@ public class PluginJetFilesProvider {
@NotNull @NotNull
public static Collection<JetFile> allFilesInProject(@NotNull Project project) { public static Collection<JetFile> allFilesInProject(@NotNull Project project) {
return JetAllPackagesIndex.getInstance().get(FqName.ROOT.asString(), project, return JetAllPackagesIndex.getInstance().get(FqName.ROOT.asString(), project,
JetSourceFilterScope.kotlinSources(GlobalSearchScope.allScope(project))); JetSourceFilterScope.kotlinSources(GlobalSearchScope.allScope(project), project));
} }
private PluginJetFilesProvider() { private PluginJetFilesProvider() {
@@ -52,6 +52,6 @@ public class JetAllPackagesIndex extends StringStubIndexExtension<JetFile> {
@NotNull @NotNull
@Override @Override
public Collection<JetFile> get(String fqName, Project project, @NotNull GlobalSearchScope scope) { public Collection<JetFile> get(String fqName, Project project, @NotNull GlobalSearchScope scope) {
return super.get(fqName, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope)); return super.get(fqName, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope, project));
} }
} }
@@ -44,6 +44,6 @@ public class JetAnnotationsIndex extends StringStubIndexExtension<JetAnnotationE
@Override @Override
public Collection<JetAnnotationEntry> get(String s, Project project, @NotNull GlobalSearchScope scope) { public Collection<JetAnnotationEntry> get(String s, Project project, @NotNull GlobalSearchScope scope) {
return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope)); return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope, project));
} }
} }
@@ -44,6 +44,6 @@ public class JetClassByPackageIndex extends StringStubIndexExtension<JetClassOrO
@Override @Override
public Collection<JetClassOrObject> get(String fqName, Project project, @NotNull GlobalSearchScope scope) { public Collection<JetClassOrObject> get(String fqName, Project project, @NotNull GlobalSearchScope scope) {
return super.get(fqName, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope)); return super.get(fqName, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope, project));
} }
} }
@@ -44,6 +44,6 @@ public class JetClassShortNameIndex extends StringStubIndexExtension<JetClassOrO
@Override @Override
public Collection<JetClassOrObject> get(String s, Project project, @NotNull GlobalSearchScope scope) { public Collection<JetClassOrObject> get(String s, Project project, @NotNull GlobalSearchScope scope) {
return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope)); return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope, project));
} }
} }
@@ -46,6 +46,6 @@ public class JetFullClassNameIndex extends StringStubIndexExtension<JetClassOrOb
@NotNull @NotNull
@Override @Override
public Collection<JetClassOrObject> get(String fqName, Project project, @NotNull GlobalSearchScope scope) { public Collection<JetClassOrObject> get(String fqName, Project project, @NotNull GlobalSearchScope scope) {
return super.get(fqName, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope)); return super.get(fqName, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope, project));
} }
} }
@@ -44,6 +44,6 @@ public class JetFunctionShortNameIndex extends StringStubIndexExtension<JetNamed
@Override @Override
public Collection<JetNamedFunction> get(String s, Project project, @NotNull GlobalSearchScope scope) { public Collection<JetNamedFunction> get(String s, Project project, @NotNull GlobalSearchScope scope) {
return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope)); return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope, project));
} }
} }
@@ -44,6 +44,6 @@ public class JetPropertyShortNameIndex extends StringStubIndexExtension<JetPrope
@Override @Override
public Collection<JetProperty> get(String s, Project project, @NotNull GlobalSearchScope scope) { public Collection<JetProperty> get(String s, Project project, @NotNull GlobalSearchScope scope) {
return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope)); return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope, project));
} }
} }
@@ -17,6 +17,7 @@
package org.jetbrains.jet.plugin.stubindex; package org.jetbrains.jet.plugin.stubindex;
import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFile;
@@ -28,26 +29,28 @@ import org.jetbrains.jet.plugin.JetPluginUtil;
public class JetSourceFilterScope extends DelegatingGlobalSearchScope { public class JetSourceFilterScope extends DelegatingGlobalSearchScope {
@NotNull @NotNull
public static GlobalSearchScope kotlinSourcesAndLibraries(@NotNull GlobalSearchScope delegate) { public static GlobalSearchScope kotlinSourcesAndLibraries(@NotNull GlobalSearchScope delegate, @NotNull Project project) {
return new JetSourceFilterScope(delegate, true); return new JetSourceFilterScope(delegate, true, project);
} }
@NotNull @NotNull
public static GlobalSearchScope kotlinSources(@NotNull GlobalSearchScope delegate) { public static GlobalSearchScope kotlinSources(@NotNull GlobalSearchScope delegate, @NotNull Project project) {
return new JetSourceFilterScope(delegate, false); return new JetSourceFilterScope(delegate, false, project);
} }
private final ProjectFileIndex index; private final ProjectFileIndex index;
private final Project project;
private final boolean includeLibraries; private final boolean includeLibraries;
private JetSourceFilterScope(@NotNull GlobalSearchScope delegate, boolean includeLibraries) { private JetSourceFilterScope(@NotNull GlobalSearchScope delegate, boolean includeLibraries, @NotNull Project project) {
super(delegate); super(delegate);
this.includeLibraries = includeLibraries; this.includeLibraries = includeLibraries;
index = ProjectRootManager.getInstance(getProject()).getFileIndex(); this.index = ProjectRootManager.getInstance(project).getFileIndex();
this.project = project;
} }
@Override @Override
public boolean contains(VirtualFile file) { public boolean contains(@NotNull VirtualFile file) {
if (!super.contains(file)) { if (!super.contains(file)) {
return false; return false;
} }
@@ -56,7 +59,7 @@ public class JetSourceFilterScope extends DelegatingGlobalSearchScope {
return index.isInLibraryClasses(file); return index.isInLibraryClasses(file);
} }
if (JetPluginUtil.isKtFileInGradleProjectInWrongFolder(file, getProject())) { if (JetPluginUtil.isKtFileInGradleProjectInWrongFolder(file, project)) {
return false; return false;
} }
@@ -46,6 +46,6 @@ public class JetSuperClassIndex extends StringStubIndexExtension<JetClassOrObjec
@NotNull @NotNull
@Override @Override
public Collection<JetClassOrObject> get(String s, Project project, GlobalSearchScope scope) { public Collection<JetClassOrObject> get(String s, Project project, GlobalSearchScope scope) {
return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope)); return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope, project));
} }
} }
@@ -49,6 +49,6 @@ public class JetTopLevelFunctionsFqnNameIndex extends StringStubIndexExtension<J
@NotNull @NotNull
@Override @Override
public Collection<JetNamedFunction> get(String s, Project project, @NotNull GlobalSearchScope scope) { public Collection<JetNamedFunction> get(String s, Project project, @NotNull GlobalSearchScope scope) {
return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope)); return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope, project));
} }
} }
@@ -44,6 +44,6 @@ public class JetTopLevelNonExtensionFunctionShortNameIndex extends StringStubInd
@Override @Override
public Collection<JetNamedFunction> get(String s, Project project, @NotNull GlobalSearchScope scope) { public Collection<JetNamedFunction> get(String s, Project project, @NotNull GlobalSearchScope scope) {
return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope)); return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope, project));
} }
} }
@@ -44,6 +44,6 @@ public class JetTopLevelObjectShortNameIndex extends StringStubIndexExtension<Je
@Override @Override
public Collection<JetObjectDeclaration> get(String s, Project project, @NotNull GlobalSearchScope scope) { public Collection<JetObjectDeclaration> get(String s, Project project, @NotNull GlobalSearchScope scope) {
return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope)); return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope, project));
} }
} }
@@ -46,6 +46,6 @@ public class JetTopLevelPropertiesFqnNameIndex extends StringStubIndexExtension<
@NotNull @NotNull
@Override @Override
public Collection<JetProperty> get(String s, Project project, @NotNull GlobalSearchScope scope) { public Collection<JetProperty> get(String s, Project project, @NotNull GlobalSearchScope scope) {
return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope)); return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope, project));
} }
} }
@@ -32,6 +32,7 @@ public class PluginDeclarationProviderFactoryService : DeclarationProviderFactor
syntheticFiles: Collection<JetFile>, syntheticFiles: Collection<JetFile>,
filesScope: GlobalSearchScope filesScope: GlobalSearchScope
): DeclarationProviderFactory { ): DeclarationProviderFactory {
return PluginDeclarationProviderFactory(project, JetSourceFilterScope.kotlinSources(filesScope), storageManager, syntheticFiles) return PluginDeclarationProviderFactory(project, JetSourceFilterScope.kotlinSources(filesScope, project),
storageManager, syntheticFiles)
} }
} }