"Go to class / symbol / super" & type aliases

This commit is contained in:
Dmitry Petrov
2016-06-16 09:04:13 +03:00
parent 0033cf85c4
commit c8a5ccb1d0
9 changed files with 142 additions and 11 deletions
@@ -144,7 +144,10 @@ public class IdeStubIndexService extends StubIndexService {
@Override
public void indexTypeAlias(KotlinTypeAliasStub stub, IndexSink sink) {
// TODO short name index for type aliases?
String name = stub.getName();
if (name != null) {
sink.occurrence(KotlinTypeAliasShortNameIndex.getInstance().getKey(), name);
}
if (stub.isTopLevel()) {
FqName fqName = stub.getFqName();
@@ -0,0 +1,52 @@
/*
* Copyright 2010-2016 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.kotlin.idea.stubindex;
import com.intellij.openapi.project.Project;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.stubs.StringStubIndexExtension;
import com.intellij.psi.stubs.StubIndex;
import com.intellij.psi.stubs.StubIndexKey;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.psi.KtProperty;
import org.jetbrains.kotlin.psi.KtTypeAlias;
import java.util.Collection;
public class KotlinTypeAliasShortNameIndex extends StringStubIndexExtension<KtTypeAlias> {
private static final StubIndexKey<String, KtTypeAlias> KEY = KotlinIndexUtil.createIndexKey(KotlinTypeAliasShortNameIndex.class);
private static final KotlinTypeAliasShortNameIndex ourInstance = new KotlinTypeAliasShortNameIndex();
public static KotlinTypeAliasShortNameIndex getInstance() {
return ourInstance;
}
private KotlinTypeAliasShortNameIndex() {}
@NotNull
@Override
public StubIndexKey<String, KtTypeAlias> getKey() {
return KEY;
}
@NotNull
@Override
public Collection<KtTypeAlias> get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) {
return StubIndex.getElements(KEY, s, project, scope, KtTypeAlias.class);
}
}
+1
View File
@@ -593,6 +593,7 @@
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFullClassNameIndex"/>
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinPropertyShortNameIndex"/>
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFunctionShortNameIndex"/>
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinTypeAliasShortNameIndex"/>
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinSuperClassIndex"/>
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinTopLevelFunctionFqnNameIndex"/>
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinTopLevelPropertyFqnNameIndex"/>
@@ -25,10 +25,7 @@ import com.intellij.psi.search.DelegatingGlobalSearchScope
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.stubs.StubIndex
import org.jetbrains.kotlin.idea.decompiler.builtIns.KotlinBuiltInFileType
import org.jetbrains.kotlin.idea.stubindex.KotlinClassShortNameIndex
import org.jetbrains.kotlin.idea.stubindex.KotlinFunctionShortNameIndex
import org.jetbrains.kotlin.idea.stubindex.KotlinPropertyShortNameIndex
import org.jetbrains.kotlin.idea.stubindex.KotlinSourceFilterScope
import org.jetbrains.kotlin.idea.stubindex.*
import org.jetbrains.kotlin.psi.KtEnumEntry
import org.jetbrains.kotlin.psi.KtNamedDeclaration
import java.util.*
@@ -42,16 +39,20 @@ class KotlinGotoClassContributor : GotoClassContributor {
override fun getQualifiedNameSeparator() = "."
override fun getNames(project: Project, includeNonProjectItems: Boolean): Array<String> {
return KotlinClassShortNameIndex.getInstance().getAllKeys(project).toTypedArray()
val classes = KotlinClassShortNameIndex.getInstance().getAllKeys(project)
val typeAliases = KotlinTypeAliasShortNameIndex.getInstance().getAllKeys(project)
return (classes + typeAliases).toTypedArray()
}
override fun getItemsByName(name: String, pattern: String, project: Project, includeNonProjectItems: Boolean): Array<NavigationItem> {
val scope = if (includeNonProjectItems) GlobalSearchScope.allScope(project) else GlobalSearchScope.projectScope(project)
val classesOrObjects = KotlinClassShortNameIndex.getInstance().get(name, project, KotlinSourceFilterScope.projectSourceAndClassFiles(scope, project))
val globalScope = if (includeNonProjectItems) GlobalSearchScope.allScope(project) else GlobalSearchScope.projectScope(project)
val scope = KotlinSourceFilterScope.projectSourceAndClassFiles(globalScope, project)
val classesOrObjects = KotlinClassShortNameIndex.getInstance().get(name, project, scope)
val typeAliases = KotlinTypeAliasShortNameIndex.getInstance().get(name, project, scope)
if (classesOrObjects.isEmpty()) return NavigationItem.EMPTY_NAVIGATION_ITEM_ARRAY
if (classesOrObjects.isEmpty() && typeAliases.isEmpty()) return NavigationItem.EMPTY_NAVIGATION_ITEM_ARRAY
return classesOrObjects.filter { it != null && it !is KtEnumEntry }.toTypedArray()
return (classesOrObjects + typeAliases).filter { it != null && it !is KtEnumEntry }.toTypedArray()
}
}
@@ -65,7 +66,8 @@ class KotlinGotoSymbolContributor : ChooseByNameContributor {
return listOf(
KotlinFunctionShortNameIndex.getInstance(),
KotlinPropertyShortNameIndex.getInstance(),
KotlinClassShortNameIndex.getInstance()
KotlinClassShortNameIndex.getInstance(),
KotlinTypeAliasShortNameIndex.getInstance()
).flatMap {
StubIndex.getInstance().getAllKeys(it.key, project)
}.toTypedArray()
@@ -79,6 +81,7 @@ class KotlinGotoSymbolContributor : ChooseByNameContributor {
result += KotlinFunctionShortNameIndex.getInstance().get(name, project, noLibrarySourceScope)
result += KotlinPropertyShortNameIndex.getInstance().get(name, project, noLibrarySourceScope)
result += KotlinClassShortNameIndex.getInstance().get(name, project, BuiltInClassesScope(noLibrarySourceScope))
result += KotlinTypeAliasShortNameIndex.getInstance().get(name, project, noLibrarySourceScope)
return result.toTypedArray()
}
+23
View File
@@ -0,0 +1,23 @@
typealias TestGlobal = Any
fun some() {
typealias TestInFun = Any
}
interface SomeTrait {
typealias TestInTrait = Any
}
class Some() {
typealias TestInClass = Any
companion object {
typealias TestInClassObject = Any
}
}
// SEARCH_TEXT: Test
// REF: typealias TestGlobal = Any
// REF: typealias TestInClass = Any
// REF: typealias TestInClassObject = Any
// REF: typealias TestInTrait = Any
@@ -0,0 +1,8 @@
// FILE: before.kt
interface Some
typealias S = Some
class <caret>SomeClass: S
// FILE: after.kt
interface <caret>Some
typealias S = Some
class SomeClass: S
+23
View File
@@ -0,0 +1,23 @@
typealias testGlobal = Any
fun some() {
typealias testInFun = Any
}
interface SomeTrait {
typealias testInTrait = Any
}
class Some() {
typealias testInClass = Any
companion object {
typealias testInClassObject = Any
}
}
// SEARCH_TEXT: test
// REF: typealias testGlobal = Any
// REF: typealias testInClass = Any
// REF: typealias testInClassObject = Any
// REF: typealias testInTrait = Any
@@ -106,4 +106,10 @@ public class GotoSuperTestGenerated extends AbstractGotoSuperTest {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/gotoSuper/TraitSimple.test");
doTest(fileName);
}
@TestMetadata("TypeAliasInSuperType.test")
public void testTypeAliasInSuperType() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/gotoSuper/TypeAliasInSuperType.test");
doTest(fileName);
}
}
@@ -96,6 +96,12 @@ public class KotlinGotoTestGenerated extends AbstractKotlinGotoTest {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/gotoClass/traitWithFunImplement.kt");
doClassTest(fileName);
}
@TestMetadata("typealias.kt")
public void testTypealias() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/gotoClass/typealias.kt");
doClassTest(fileName);
}
}
@TestMetadata("idea/testData/navigation/gotoSymbol")
@@ -153,5 +159,11 @@ public class KotlinGotoTestGenerated extends AbstractKotlinGotoTest {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/gotoSymbol/stdLibJoinToString.kt");
doSymbolTest(fileName);
}
@TestMetadata("typealias.kt")
public void testTypealias() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/gotoSymbol/typealias.kt");
doSymbolTest(fileName);
}
}
}