Indexing all packages, including ones declared implicitly
This commit is contained in:
@@ -204,6 +204,7 @@
|
||||
|
||||
<stubElementTypeHolder class="org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes"/>
|
||||
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetPackageDeclarationIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetAllPackagesIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetClassByPackageIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetShortClassNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetFullClassNameIndex"/>
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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;
|
||||
|
||||
/**
|
||||
* Contains all packages, i.e. if a file declares
|
||||
* package a.b.c
|
||||
*
|
||||
* Three packages "a", "a.b" and "a.b.c" will be registered in this index
|
||||
*/
|
||||
public class JetAllPackagesIndex extends StringStubIndexExtension<JetFile> {
|
||||
private static final StubIndexKey<String, JetFile> KEY = KotlinIndexUtil.createIndexKey(JetAllPackagesIndex.class);
|
||||
|
||||
private static final JetAllPackagesIndex ourInstance = new JetAllPackagesIndex();
|
||||
|
||||
public static JetAllPackagesIndex getInstance() {
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
private JetAllPackagesIndex() {}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public StubIndexKey<String, JetFile> getKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<JetFile> get(final String fqName, final Project project, @NotNull final GlobalSearchScope scope) {
|
||||
return super.get(fqName, project, new JetSourceFilterScope(scope));
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,12 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Explicitly declared packages, i.e. if a file declares
|
||||
* package a.b.c
|
||||
*
|
||||
* Only "a.b.c" will be registered, not "a" nor "a.b"
|
||||
*/
|
||||
public class JetPackageDeclarationIndex extends StringStubIndexExtension<JetFile> {
|
||||
private static final StubIndexKey<String, JetFile> KEY = KotlinIndexUtil.createIndexKey(JetPackageDeclarationIndex.class);
|
||||
|
||||
|
||||
@@ -27,7 +27,17 @@ public class StubIndexServiceImpl implements StubIndexService {
|
||||
@Override
|
||||
public void indexFile(PsiJetFileStub stub, IndexSink sink) {
|
||||
String packageName = stub.getPackageName();
|
||||
sink.occurrence(JetPackageDeclarationIndex.getInstance().getKey(), packageName == null ? "" : packageName);
|
||||
FqName fqName = new FqName(packageName == null ? "" : packageName);
|
||||
|
||||
sink.occurrence(JetPackageDeclarationIndex.getInstance().getKey(), fqName.getFqName());
|
||||
|
||||
while (true) {
|
||||
sink.occurrence(JetAllPackagesIndex.getInstance().getKey(), fqName.getFqName());
|
||||
if (fqName.isRoot()) {
|
||||
return;
|
||||
}
|
||||
fqName = fqName.parent();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user