Introduce PackageIndexUtil#packageExists()

Use it in IDELightClassGenerationSupport and PluginDeclarationProviderFactory
This commit is contained in:
Pavel V. Talanov
2014-08-19 15:22:33 +04:00
parent 77416aba5f
commit 3b78e3eb99
3 changed files with 25 additions and 7 deletions
@@ -179,7 +179,7 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport
@Override
public boolean packageExists(@NotNull FqName fqName, @NotNull GlobalSearchScope scope) {
return !JetAllPackagesIndex.getInstance().get(fqName.asString(), project, kotlinSources(scope, project)).isEmpty();
return PackageIndexUtil.packageExists(fqName, kotlinSources(scope, project), project);
}
@NotNull
@@ -19,7 +19,10 @@ package org.jetbrains.jet.plugin.stubindex;
import com.google.common.collect.Sets;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Ref;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.stubs.StubIndex;
import com.intellij.util.Processor;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetFile;
@@ -70,6 +73,24 @@ public final class PackageIndexUtil {
});
}
public static boolean packageExists(
@NotNull FqName packageFqName,
@NotNull GlobalSearchScope searchScope,
@NotNull Project project
) {
final Ref<Boolean> result = new Ref<Boolean>(false);
StubIndex.getInstance().processElements(
JetAllPackagesIndex.getInstance().getKey(), packageFqName.asString(), project, searchScope, JetFile.class,
new Processor<JetFile>() {
@Override
public boolean process(JetFile file) {
result.set(true);
return false;
}
});
return result.get();
}
private PackageIndexUtil() {
}
}
@@ -22,8 +22,8 @@ import org.jetbrains.jet.lang.psi.JetFile
import org.jetbrains.jet.lang.resolve.lazy.data.JetClassLikeInfo
import org.jetbrains.jet.lang.resolve.lazy.declarations.*
import org.jetbrains.jet.lang.resolve.name.FqName
import org.jetbrains.jet.plugin.stubindex.JetAllPackagesIndex
import org.jetbrains.jet.storage.StorageManager
import org.jetbrains.jet.plugin.stubindex.PackageIndexUtil
public class PluginDeclarationProviderFactory(
private val project: Project,
@@ -49,11 +49,8 @@ public class PluginDeclarationProviderFactory(
}
private fun getStubBasedPackageMemberDeclarationProvider(name: FqName): PackageMemberDeclarationProvider? {
//TODO: better check
val files = JetAllPackagesIndex.getInstance().get(name.asString(), project, indexedFilesScope)
if (files.isEmpty()) {
return null
}
if (!PackageIndexUtil.packageExists(name, indexedFilesScope, project)) return null
return StubBasedPackageMemberDeclarationProvider(name, project, indexedFilesScope)
}
}