diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IdeStubIndexService.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IdeStubIndexService.java index 15aa8b34f4a..166aac6b7db 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IdeStubIndexService.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IdeStubIndexService.java @@ -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(); diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTypeAliasShortNameIndex.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTypeAliasShortNameIndex.java new file mode 100644 index 00000000000..d8bab0dd05f --- /dev/null +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTypeAliasShortNameIndex.java @@ -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 { + private static final StubIndexKey KEY = KotlinIndexUtil.createIndexKey(KotlinTypeAliasShortNameIndex.class); + + private static final KotlinTypeAliasShortNameIndex ourInstance = new KotlinTypeAliasShortNameIndex(); + + public static KotlinTypeAliasShortNameIndex getInstance() { + return ourInstance; + } + + private KotlinTypeAliasShortNameIndex() {} + + @NotNull + @Override + public StubIndexKey getKey() { + return KEY; + } + + @NotNull + @Override + public Collection get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) { + return StubIndex.getElements(KEY, s, project, scope, KtTypeAlias.class); + } +} diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 2c0abe2b501..d63993bca6e 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -593,6 +593,7 @@ + diff --git a/idea/src/org/jetbrains/kotlin/idea/goto/gotoContributors.kt b/idea/src/org/jetbrains/kotlin/idea/goto/gotoContributors.kt index c525dad2c0a..e5bca7cf6f1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/goto/gotoContributors.kt +++ b/idea/src/org/jetbrains/kotlin/idea/goto/gotoContributors.kt @@ -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 { - 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 { - 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() } diff --git a/idea/testData/navigation/gotoClass/typealias.kt b/idea/testData/navigation/gotoClass/typealias.kt new file mode 100644 index 00000000000..2a38b3662e1 --- /dev/null +++ b/idea/testData/navigation/gotoClass/typealias.kt @@ -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 diff --git a/idea/testData/navigation/gotoSuper/TypeAliasInSuperType.test b/idea/testData/navigation/gotoSuper/TypeAliasInSuperType.test new file mode 100644 index 00000000000..e1121d1da6b --- /dev/null +++ b/idea/testData/navigation/gotoSuper/TypeAliasInSuperType.test @@ -0,0 +1,8 @@ +// FILE: before.kt +interface Some +typealias S = Some +class SomeClass: S +// FILE: after.kt +interface Some +typealias S = Some +class SomeClass: S \ No newline at end of file diff --git a/idea/testData/navigation/gotoSymbol/typealias.kt b/idea/testData/navigation/gotoSymbol/typealias.kt new file mode 100644 index 00000000000..db41b921c8a --- /dev/null +++ b/idea/testData/navigation/gotoSymbol/typealias.kt @@ -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 diff --git a/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoSuperTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoSuperTestGenerated.java index 3537e111834..5bf121ab471 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoSuperTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoSuperTestGenerated.java @@ -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); + } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/navigation/KotlinGotoTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/navigation/KotlinGotoTestGenerated.java index 10b5ba0bdce..d102754e9a0 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/navigation/KotlinGotoTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/navigation/KotlinGotoTestGenerated.java @@ -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); + } } }