From 8d0f8a0035751619f4415bfd5039492397d67b9c Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Wed, 19 Dec 2012 17:12:26 +0400 Subject: [PATCH] LightClasses: Searching indexes excluding library sources --- .../IDELightClassGenerationSupport.java | 17 +++++++-------- .../stubindex/JetSourceFilterScope.java | 21 ++++++++++++------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/caches/resolve/IDELightClassGenerationSupport.java b/idea/src/org/jetbrains/jet/plugin/caches/resolve/IDELightClassGenerationSupport.java index f2324f2784b..38c4633e1ec 100644 --- a/idea/src/org/jetbrains/jet/plugin/caches/resolve/IDELightClassGenerationSupport.java +++ b/idea/src/org/jetbrains/jet/plugin/caches/resolve/IDELightClassGenerationSupport.java @@ -26,15 +26,14 @@ import org.jetbrains.jet.lang.psi.JetClassOrObject; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetPsiUtil; import org.jetbrains.jet.lang.resolve.name.FqName; -import org.jetbrains.jet.plugin.stubindex.JetAllPackagesIndex; -import org.jetbrains.jet.plugin.stubindex.JetClassByPackageIndex; -import org.jetbrains.jet.plugin.stubindex.JetFullClassNameIndex; -import org.jetbrains.jet.plugin.stubindex.JetPackageDeclarationIndex; +import org.jetbrains.jet.plugin.stubindex.*; import org.jetbrains.jet.util.QualifiedNamesUtil; import java.util.Collection; import java.util.Set; +import static org.jetbrains.jet.plugin.stubindex.JetSourceFilterScope.kotlinSources; + public class IDELightClassGenerationSupport extends LightClassGenerationSupport { private final Project project; @@ -54,13 +53,13 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport @NotNull @Override public Collection findClassOrObjectDeclarations(@NotNull FqName fqName, @NotNull GlobalSearchScope searchScope) { - return JetFullClassNameIndex.getInstance().get(fqName.getFqName(), project, searchScope); + return JetFullClassNameIndex.getInstance().get(fqName.getFqName(), project, kotlinSources(searchScope)); } @NotNull @Override public Collection findFilesForPackage(@NotNull FqName fqName, @NotNull GlobalSearchScope searchScope) { - return JetPackageDeclarationIndex.getInstance().get(fqName.getFqName(), project, searchScope); + return JetPackageDeclarationIndex.getInstance().get(fqName.getFqName(), project, kotlinSources(searchScope)); } @NotNull @@ -68,20 +67,20 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport public Collection findClassOrObjectDeclarationsInPackage( @NotNull FqName packageFqName, @NotNull GlobalSearchScope searchScope ) { - return JetClassByPackageIndex.getInstance().get(packageFqName.getFqName(), project, searchScope); + return JetClassByPackageIndex.getInstance().get(packageFqName.getFqName(), project, kotlinSources(searchScope)); } @Override public boolean packageExists( @NotNull FqName fqName, @NotNull GlobalSearchScope scope ) { - return !JetAllPackagesIndex.getInstance().get(fqName.getFqName(), project, scope).isEmpty(); + return !JetAllPackagesIndex.getInstance().get(fqName.getFqName(), project, kotlinSources(scope)).isEmpty(); } @NotNull @Override public Collection getSubPackages(@NotNull FqName fqn, @NotNull GlobalSearchScope scope) { - Collection files = JetAllPackagesIndex.getInstance().get(fqn.getFqName(), project, scope); + Collection files = JetAllPackagesIndex.getInstance().get(fqn.getFqName(), project, kotlinSources(scope)); Set result = Sets.newHashSet(); for (JetFile file : files) { diff --git a/idea/src/org/jetbrains/jet/plugin/stubindex/JetSourceFilterScope.java b/idea/src/org/jetbrains/jet/plugin/stubindex/JetSourceFilterScope.java index 964c426e63d..47d9b195369 100644 --- a/idea/src/org/jetbrains/jet/plugin/stubindex/JetSourceFilterScope.java +++ b/idea/src/org/jetbrains/jet/plugin/stubindex/JetSourceFilterScope.java @@ -27,14 +27,20 @@ import org.jetbrains.jet.plugin.JetFileType; public class JetSourceFilterScope extends DelegatingGlobalSearchScope { public static JetSourceFilterScope kotlinSourcesAndLibraries(@NotNull GlobalSearchScope delegate) { - return new JetSourceFilterScope(delegate); + return new JetSourceFilterScope(delegate, true); } - private final ProjectFileIndex myIndex; + public static JetSourceFilterScope kotlinSources(@NotNull GlobalSearchScope delegate) { + return new JetSourceFilterScope(delegate, false); + } - private JetSourceFilterScope(@NotNull GlobalSearchScope delegate) { + private final ProjectFileIndex index; + private final boolean includeLibraries; + + private JetSourceFilterScope(@NotNull GlobalSearchScope delegate, boolean includeLibraries) { super(delegate); - myIndex = ProjectRootManager.getInstance(getProject()).getFileIndex(); + this.includeLibraries = includeLibraries; + index = ProjectRootManager.getInstance(getProject()).getFileIndex(); } @Override @@ -43,10 +49,11 @@ public class JetSourceFilterScope extends DelegatingGlobalSearchScope { return false; } - if (StdFileTypes.CLASS == file.getFileType()) { - return myIndex.isInLibraryClasses(file); + if (includeLibraries && StdFileTypes.CLASS == file.getFileType()) { + return index.isInLibraryClasses(file); } - return file.getFileType().equals(JetFileType.INSTANCE) && (myIndex.isInSourceContent(file) || myIndex.isInLibrarySource(file)); + return file.getFileType().equals(JetFileType.INSTANCE) && + (index.isInSourceContent(file) || includeLibraries && index.isInLibrarySource(file)); } }