Rework JetSourceFilterScope

JetSourceFilterScope doesn't have to check file type
Avoid redundant wrapping in JetSourceFilterScope (this may improve performance in case of frequent queries to indices)

We can safely use kotlinSourcesAndLibraries scope in declaration provider given we have correct scope in the first place
This allows for resolving kotlin js libraries (which are kotlin files in classes root) whithout additional hacks (i.e. IDEAConfig)
This commit is contained in:
Pavel V. Talanov
2014-07-11 18:50:13 +04:00
parent db5303c019
commit e3e83fdee5
2 changed files with 13 additions and 11 deletions
@@ -16,7 +16,6 @@
package org.jetbrains.jet.plugin.stubindex;
import com.intellij.ide.highlighter.JavaClassFileType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.roots.ProjectRootManager;
@@ -24,17 +23,22 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.DelegatingGlobalSearchScope;
import com.intellij.psi.search.GlobalSearchScope;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.plugin.JetFileType;
import org.jetbrains.jet.plugin.configuration.JetModuleTypeManager;
public class JetSourceFilterScope extends DelegatingGlobalSearchScope {
@NotNull
public static GlobalSearchScope kotlinSourcesAndLibraries(@NotNull GlobalSearchScope delegate, @NotNull Project project) {
if (delegate instanceof JetSourceFilterScope) {
return delegate;
}
return new JetSourceFilterScope(delegate, true, project);
}
@NotNull
public static GlobalSearchScope kotlinSources(@NotNull GlobalSearchScope delegate, @NotNull Project project) {
if (delegate instanceof JetSourceFilterScope) {
delegate = ((JetSourceFilterScope) delegate).myBaseScope;
}
return new JetSourceFilterScope(delegate, false, project);
}
@@ -44,9 +48,9 @@ public class JetSourceFilterScope extends DelegatingGlobalSearchScope {
private JetSourceFilterScope(@NotNull GlobalSearchScope delegate, boolean includeLibraries, @NotNull Project project) {
super(delegate);
this.includeLibraries = includeLibraries;
this.index = ProjectRootManager.getInstance(project).getFileIndex();
this.project = project;
this.includeLibraries = includeLibraries;
}
@Override
@@ -55,15 +59,12 @@ public class JetSourceFilterScope extends DelegatingGlobalSearchScope {
return false;
}
if (includeLibraries && JavaClassFileType.INSTANCE == file.getFileType()) {
return index.isInLibraryClasses(file);
if (index.isInSourceContent(file)) {
return !JetModuleTypeManager.getInstance().isKtFileInGradleProjectInWrongFolder(file, project);
}
if (JetModuleTypeManager.getInstance().isKtFileInGradleProjectInWrongFolder(file, getProject())) {
return false;
}
if (!includeLibraries) return false;
return file.getFileType().equals(JetFileType.INSTANCE) &&
(index.isInSourceContent(file) || includeLibraries && index.isInLibrarySource(file));
return index.isInLibraryClasses(file) || index.isInLibrarySource(file);
}
}
@@ -32,7 +32,8 @@ public class PluginDeclarationProviderFactoryService : DeclarationProviderFactor
syntheticFiles: Collection<JetFile>,
filesScope: GlobalSearchScope
): DeclarationProviderFactory {
return PluginDeclarationProviderFactory(project, JetSourceFilterScope.kotlinSources(filesScope, project),
//NOTE: we include libraries here to support analyzing JavaScript libraries which are kotlin sources in classes root
return PluginDeclarationProviderFactory(project, JetSourceFilterScope.kotlinSourcesAndLibraries(filesScope, project),
storageManager, syntheticFiles)
}
}