Index classes by containing package

This commit is contained in:
Andrey Breslav
2012-12-18 21:01:45 +04:00
parent f166ae43bf
commit 91a1a1420d
3 changed files with 60 additions and 0 deletions
+1
View File
@@ -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.JetClassByPackageIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetShortClassNameIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetFullClassNameIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetShortFunctionNameIndex"/>
@@ -0,0 +1,49 @@
/*
* Copyright 2010-2013 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.JetClassOrObject;
import java.util.Collection;
public class JetClassByPackageIndex extends StringStubIndexExtension<JetClassOrObject> {
private static final StubIndexKey<String, JetClassOrObject> KEY = KotlinIndexUtil.createIndexKey(JetClassByPackageIndex.class);
private static final JetClassByPackageIndex ourInstance = new JetClassByPackageIndex();
public static JetClassByPackageIndex getInstance() {
return ourInstance;
}
private JetClassByPackageIndex() {}
@NotNull
@Override
public StubIndexKey<String, JetClassOrObject> getKey() {
return KEY;
}
@Override
public Collection<JetClassOrObject> get(final String fqName, final Project project, @NotNull final GlobalSearchScope scope) {
return super.get(fqName, project, new JetSourceFilterScope(scope));
}
}
@@ -17,6 +17,7 @@
package org.jetbrains.jet.plugin.stubindex;
import com.intellij.psi.stubs.IndexSink;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.jet.lang.psi.stubs.*;
import org.jetbrains.jet.lang.psi.stubs.elements.StubIndexService;
import org.jetbrains.jet.lang.resolve.name.FqName;
@@ -44,6 +45,15 @@ public class StubIndexServiceImpl implements StubIndexService {
for (String superName : stub.getSuperNames()) {
sink.occurrence(JetSuperClassIndex.getInstance().getKey(), superName);
}
StubElement parentStub = stub.getParentStub();
if (parentStub instanceof PsiJetFileStub) {
PsiJetFileStub jetFileStub = (PsiJetFileStub) parentStub;
String packageName = jetFileStub.getPackageName();
if (packageName != null) {
sink.occurrence(JetClassByPackageIndex.getInstance().getKey(), packageName);
}
}
}
@Override