KT-11588 Type aliases

Type alias stubs indexing (required for index-based declaration providers)
This commit is contained in:
Dmitry Petrov
2016-05-18 17:19:47 +03:00
parent 8bf87a9a4f
commit a2ec580119
17 changed files with 257 additions and 8 deletions
@@ -142,6 +142,19 @@ public class IdeStubIndexService extends StubIndexService {
}
}
@Override
public void indexTypeAlias(KotlinTypeAliasStub stub, IndexSink sink) {
// TODO short name index for type aliases?
if (stub.isTopLevel()) {
FqName fqName = stub.getFqName();
if (fqName != null) {
sink.occurrence(KotlinTopLevelTypeAliasFqNameIndex.getInstance().getKey(), fqName.asString());
sink.occurrence(KotlinTopLevelTypeAliasByPackageIndex.getInstance().getKey(), fqName.parent().asString());
}
}
}
@Override
public void indexProperty(KotlinPropertyStub stub, IndexSink sink) {
String name = stub.getName();
@@ -0,0 +1,41 @@
/*
* 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.kotlin.psi.KtTypeAlias
class KotlinTopLevelTypeAliasByPackageIndex : StringStubIndexExtension<KtTypeAlias>() {
override fun getKey(): StubIndexKey<String, KtTypeAlias> = KEY
override fun get(s: String, project: Project, scope: GlobalSearchScope): Collection<KtTypeAlias> =
StubIndex.getElements<String, KtTypeAlias>(
KEY, s, project,
KotlinSourceFilterScope.sourcesAndLibraries(scope, project),
KtTypeAlias::class.java)
companion object {
val KEY = KotlinIndexUtil.createIndexKey(KotlinTopLevelTypeAliasByPackageIndex::class.java)
val INSTANCE = KotlinTopLevelTypeAliasByPackageIndex()
@JvmStatic fun getInstance() = INSTANCE
}
}
@@ -0,0 +1,42 @@
/*
* 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.kotlin.psi.KtTypeAlias
class KotlinTopLevelTypeAliasFqNameIndex : StringStubIndexExtension<KtTypeAlias>() {
override fun getKey(): StubIndexKey<String, KtTypeAlias> = KEY
override fun get(s: String, project: Project, scope: GlobalSearchScope): Collection<KtTypeAlias> =
StubIndex.getElements<String, KtTypeAlias>(
KEY, s, project,
KotlinSourceFilterScope.sourcesAndLibraries(scope, project),
KtTypeAlias::class.java)
companion object {
val KEY = KotlinIndexUtil.createIndexKey(KotlinTopLevelTypeAliasFqNameIndex::class.java)
val INSTANCE = KotlinTopLevelTypeAliasFqNameIndex()
@JvmStatic fun getInstance() = INSTANCE
}
}
@@ -46,6 +46,7 @@ class StubBasedPackageMemberDeclarationProvider(
if (kindFilter.acceptsKinds(DescriptorKindFilter.CLASSIFIERS_MASK)) {
addFromIndex(KotlinTopLevelClassByPackageIndex.getInstance())
addFromIndex(KotlinTopLevelTypeAliasByPackageIndex.getInstance())
}
if (kindFilter.acceptsKinds(DescriptorKindFilter.FUNCTIONS_MASK)) {
@@ -82,11 +83,12 @@ class StubBasedPackageMemberDeclarationProvider(
}
override fun getPackageFiles(): Collection<KtFile> {
return PackageIndexUtil.findFilesWithExactPackage(fqName, searchScope, project)
return PackageIndexUtil.findFilesWithExactPackage(fqName, searchScope, project)
}
override fun getTypeAliasDeclarations(name: Name): Collection<KtTypeAlias> =
emptyList() // TODO stub index for type aliases
override fun getTypeAliasDeclarations(name: Name): Collection<KtTypeAlias> {
return KotlinTopLevelTypeAliasFqNameIndex.getInstance().get(childName(name), project, searchScope)
}
private fun childName(name: Name): String {
return fqName.child(ResolveSessionUtils.safeNameForLazyResolve(name)).asString()