diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/resolve/StubBasedPackageMemberDeclarationProvider.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/resolve/StubBasedPackageMemberDeclarationProvider.kt index dbc79cb212f..e06dd654c2e 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/resolve/StubBasedPackageMemberDeclarationProvider.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/resolve/StubBasedPackageMemberDeclarationProvider.kt @@ -19,8 +19,10 @@ package org.jetbrains.kotlin.idea.stubindex.resolve import com.intellij.openapi.project.Project import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.stubs.StringStubIndexExtension +import com.intellij.util.indexing.FileBasedIndex import org.jetbrains.kotlin.idea.stubindex.* import org.jetbrains.kotlin.idea.util.application.runReadAction +import org.jetbrains.kotlin.idea.vfilefinder.KotlinPackageSourcesMemberNamesIndex import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* @@ -61,9 +63,12 @@ class StubBasedPackageMemberDeclarationProvider( return result } - private val declarationNames_ by lazy(LazyThreadSafetyMode.PUBLICATION) { - getDeclarations(DescriptorKindFilter.ALL, { true }) - .mapTo(mutableSetOf()) { ResolveSessionUtils.safeNameForLazyResolve(it as KtNamedDeclaration) } + private val declarationNames_: Set by lazy(LazyThreadSafetyMode.PUBLICATION) { + FileBasedIndex.getInstance() + .getValues(KotlinPackageSourcesMemberNamesIndex.KEY, fqName.asString(), searchScope) + .flatMapTo(hashSetOf()) { + it.map { stringName -> ResolveSessionUtils.safeNameForLazyResolve(Name.identifier(stringName)) } + } } override fun getDeclarationNames() = declarationNames_ diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/KotlinPackageSourcesMemberNamesIndex.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/KotlinPackageSourcesMemberNamesIndex.kt new file mode 100644 index 00000000000..338062c85de --- /dev/null +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/KotlinPackageSourcesMemberNamesIndex.kt @@ -0,0 +1,71 @@ +/* + * Copyright 2010-2017 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.vfilefinder + +import com.intellij.util.indexing.* +import com.intellij.util.io.DataExternalizer +import com.intellij.util.io.EnumeratorStringDescriptor +import org.jetbrains.kotlin.idea.KotlinFileType +import org.jetbrains.kotlin.psi.KtDeclaration +import org.jetbrains.kotlin.psi.KtFile +import java.io.DataInput +import java.io.DataOutput + +object KotlinPackageSourcesMemberNamesIndex : FileBasedIndexExtension>() { + val KEY: ID> = ID.create(KotlinPackageSourcesMemberNamesIndex::class.java.canonicalName) + + private val KEY_DESCRIPTOR = EnumeratorStringDescriptor() + + override fun getName() = KEY + + override fun dependsOnFileContent() = true + + override fun getKeyDescriptor() = KEY_DESCRIPTOR + + override fun getValueExternalizer() = StringSetExternalizer + + override fun getInputFilter(): FileBasedIndex.InputFilter = + FileBasedIndex.InputFilter { file -> file.extension == KotlinFileType.EXTENSION } + + override fun getVersion(): Int = 1 + + override fun getIndexer(): DataIndexer, FileContent> = + DataIndexer { inputData -> + val ktFile = inputData.psiFile as KtFile + val packageName = ktFile.packageDirective?.fqName?.asString() ?: "" + + mapOf(packageName to ktFile.declarations.mapNotNullTo(hashSetOf(), KtDeclaration::getName)) + } +} + +object StringSetExternalizer : DataExternalizer> { + private val ELEMENTS_SERIALIZER = EnumeratorStringDescriptor() + + override fun read(input: DataInput): Set { + val size = input.readInt() + return hashSetOf().apply { + repeat(size) { + add(ELEMENTS_SERIALIZER.read(input)) + } + } + } + + override fun save(output: DataOutput, value: Collection) { + output.writeInt(value.size) + value.toSet().forEach { ELEMENTS_SERIALIZER.save(output, it) } + } +} diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 3601721af63..712ebd8a16d 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -748,6 +748,7 @@ + diff --git a/idea/src/org/jetbrains/kotlin/idea/versions/KotlinUpdatePluginComponent.kt b/idea/src/org/jetbrains/kotlin/idea/versions/KotlinUpdatePluginComponent.kt index ce9bf0e29cd..ca0cb6f680d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/versions/KotlinUpdatePluginComponent.kt +++ b/idea/src/org/jetbrains/kotlin/idea/versions/KotlinUpdatePluginComponent.kt @@ -58,6 +58,7 @@ class KotlinUpdatePluginComponent : ApplicationComponent { fileBasedIndex.requestRebuild(KotlinMetadataFileIndex.KEY) fileBasedIndex.requestRebuild(KotlinMetadataFilePackageIndex.KEY) fileBasedIndex.requestRebuild(KotlinModuleMappingIndex.KEY) + fileBasedIndex.requestRebuild(KotlinPackageSourcesMemberNamesIndex.KEY) PropertiesComponent.getInstance()?.setValue(INSTALLED_KOTLIN_VERSION, KotlinPluginUtil.getPluginVersion()) }