Introduce JetExactPackagesIndex

Use it to implement PackageIndexUtil#findFilesWithExactPackage()
This commit is contained in:
Pavel V. Talanov
2014-08-19 21:07:41 +04:00
parent 3418d15590
commit 007ea9e10a
4 changed files with 56 additions and 10 deletions
@@ -0,0 +1,51 @@
/*
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.plugin.stubindex;
import com.intellij.openapi.project.Project;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.stubs.StringStubIndexExtension;
import com.intellij.psi.stubs.StubIndexKey;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetFile;
import java.util.Collection;
public class JetExactPackagesIndex extends StringStubIndexExtension<JetFile> {
private static final StubIndexKey<String, JetFile> KEY = KotlinIndexUtil.createIndexKey(JetExactPackagesIndex.class);
private static final JetExactPackagesIndex ourInstance = new JetExactPackagesIndex();
@NotNull
public static JetExactPackagesIndex getInstance() {
return ourInstance;
}
private JetExactPackagesIndex() {}
@NotNull
@Override
public StubIndexKey<String, JetFile> getKey() {
return KEY;
}
@NotNull
@Override
public Collection<JetFile> get(@NotNull String fqName, @NotNull Project project, @NotNull GlobalSearchScope scope) {
return super.get(fqName, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope, project));
}
}
@@ -18,12 +18,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;
import org.jetbrains.jet.lang.resolve.name.FqName;
@@ -60,17 +58,11 @@ public final class PackageIndexUtil {
@NotNull
public static Collection<JetFile> findFilesWithExactPackage(
@NotNull final FqName packageFqName,
@NotNull FqName packageFqName,
@NotNull GlobalSearchScope searchScope,
@NotNull Project project
) {
Collection<JetFile> files = JetAllPackagesIndex.getInstance().get(packageFqName.asString(), project, searchScope);
return ContainerUtil.filter(files, new Condition<JetFile>() {
@Override
public boolean value(JetFile file) {
return packageFqName.equals(file.getPackageFqName());
}
});
return JetExactPackagesIndex.getInstance().get(packageFqName.asString(), project, searchScope);
}
public static boolean packageExists(
@@ -31,6 +31,8 @@ public class StubIndexServiceImpl implements StubIndexService {
public void indexFile(PsiJetFileStub stub, IndexSink sink) {
FqName packageFqName = stub.getPackageFqName();
sink.occurrence(JetExactPackagesIndex.getInstance().getKey(), packageFqName.asString());
while (true) {
sink.occurrence(JetAllPackagesIndex.getInstance().getKey(), packageFqName.asString());
if (packageFqName.isRoot()) {
+1
View File
@@ -359,6 +359,7 @@
<stubElementTypeHolder class="org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetAllPackagesIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetExactPackagesIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetClassByPackageIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetClassShortNameIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetFullClassNameIndex"/>