LightClasses: Searching indexes excluding library sources

This commit is contained in:
Andrey Breslav
2012-12-19 17:12:26 +04:00
parent f29383faab
commit 8d0f8a0035
2 changed files with 22 additions and 16 deletions
@@ -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<JetClassOrObject> 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<JetFile> 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<JetClassOrObject> 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<FqName> getSubPackages(@NotNull FqName fqn, @NotNull GlobalSearchScope scope) {
Collection<JetFile> files = JetAllPackagesIndex.getInstance().get(fqn.getFqName(), project, scope);
Collection<JetFile> files = JetAllPackagesIndex.getInstance().get(fqn.getFqName(), project, kotlinSources(scope));
Set<FqName> result = Sets.newHashSet();
for (JetFile file : files) {
@@ -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));
}
}