From 784b4a8aeba88e194f30e0b411296d0dea813218 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Wed, 1 Apr 2015 19:42:11 +0300 Subject: [PATCH] Minor code changes after code review --- .../kotlin/psi/stubs/StubInterfaces.kt | 7 ----- .../jetbrains/kotlin/util/TypeIndexUtil.kt | 10 +++++-- .../kotlin/idea/stubindex/IndexUtils.kt | 26 +++++++++---------- ...etTopLevelExtensionsByReceiverTypeIndex.kt | 7 ++--- .../kotlin/idea/caches/KotlinIndicesHelper.kt | 15 +++++------ ...NotImportedExtensionFunction.dependency.kt | 6 ++--- .../NotImportedExtensionFunction.kt | 3 +-- 7 files changed, 36 insertions(+), 38 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/StubInterfaces.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/StubInterfaces.kt index 5bf2bb2c02a..c1036e338bb 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/StubInterfaces.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/StubInterfaces.kt @@ -114,10 +114,3 @@ public trait KotlinTypeProjectionStub : StubElement { public trait KotlinUserTypeStub : StubElement { public fun isAbsoluteInRootPackage(): Boolean } - -public fun StubElement<*>.getContainingFileStub(): PsiFileStub<*> { - return if (this is PsiFileStub) - this - else - getParentStub().getContainingFileStub() -} diff --git a/idea/ide-common/src/org/jetbrains/kotlin/util/TypeIndexUtil.kt b/idea/ide-common/src/org/jetbrains/kotlin/util/TypeIndexUtil.kt index f898c92d868..6c1b758a3dc 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/util/TypeIndexUtil.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/util/TypeIndexUtil.kt @@ -18,12 +18,12 @@ package org.jetbrains.kotlin.util import com.google.common.collect.HashMultimap import com.google.common.collect.Multimap -import com.google.common.collect.Multimaps import com.intellij.openapi.util.Key +import com.intellij.psi.stubs.PsiFileStub +import com.intellij.psi.stubs.StubElement import org.jetbrains.kotlin.psi.JetFile import org.jetbrains.kotlin.psi.JetTypeReference import org.jetbrains.kotlin.psi.JetUserType -import org.jetbrains.kotlin.psi.stubs.getContainingFileStub public fun JetUserType.aliasImportMap(): Multimap { // we need to access containing file via stub because getPsi() may return null when indexing and getContainingFile() will crash @@ -69,3 +69,9 @@ public fun JetUserType?.isProbablyNothing(): Boolean { return referencedName == "Nothing" || aliasImportMap()[referencedName].contains("Nothing") } +private fun StubElement<*>.getContainingFileStub(): PsiFileStub<*> { + return if (this is PsiFileStub) + this + else + getParentStub().getContainingFileStub() +} diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IndexUtils.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IndexUtils.kt index cb4bce61a7f..5dae1ea19c2 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IndexUtils.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IndexUtils.kt @@ -22,7 +22,6 @@ import com.intellij.openapi.util.Key import com.intellij.psi.stubs.IndexSink import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.stubs.KotlinCallableStubBase -import org.jetbrains.kotlin.psi.stubs.getContainingFileStub import org.jetbrains.kotlin.util.aliasImportMap fun indexTopLevelExtension(stub: KotlinCallableStubBase, sink: IndexSink) { @@ -32,7 +31,7 @@ fun indexTopLevelExtension(stub: KotlinCa } } -private fun JetTypeElement.index(declaration: TDeclaration, sink: IndexSink) { +private fun JetTypeElement.index(declaration: TDeclaration, sink: IndexSink) { fun occurrence(typeName: String) { val name = declaration.getName() ?: return sink.occurrence(JetTopLevelExtensionsByReceiverTypeIndex.INSTANCE.getKey(), @@ -43,17 +42,16 @@ private fun JetTypeElement.index(declara is JetUserType -> { var referenceName = getReferencedName() ?: return - if (declaration is JetNamedFunction) { - val typeParameter = declaration.getTypeParameters().firstOrNull { it.getName() == referenceName } - if (typeParameter != null) { - val bound = typeParameter.getExtendsBound() - if (bound != null) { - bound.getTypeElement()?.index(declaration, sink) - return - } - occurrence("Any") - return + val typeParameter = declaration.getTypeParameters().firstOrNull { it.getName() == referenceName } + if (typeParameter != null) { + val bound = typeParameter.getExtendsBound() + if (bound != null) { + bound.getTypeElement()?.index(declaration, sink) } + else { + occurrence("Any") + } + return } occurrence(referenceName) @@ -68,7 +66,9 @@ private fun JetTypeElement.index(declara occurrence(typeName) } - else -> occurrence("Any") + is JetDynamicType -> occurrence("Any") + + else -> error("Unsupported type: $this") } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/JetTopLevelExtensionsByReceiverTypeIndex.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/JetTopLevelExtensionsByReceiverTypeIndex.kt index 12425eca0ac..6799eea11fa 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/JetTopLevelExtensionsByReceiverTypeIndex.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/JetTopLevelExtensionsByReceiverTypeIndex.kt @@ -31,13 +31,14 @@ public class JetTopLevelExtensionsByReceiverTypeIndex private() : StringStubInde companion object { private val KEY = KotlinIndexUtil.createIndexKey(javaClass()) + private val SEPARATOR = '\n' public val INSTANCE: JetTopLevelExtensionsByReceiverTypeIndex = JetTopLevelExtensionsByReceiverTypeIndex() - public fun buildKey(receiverTypeName: String, callableName: String): String = receiverTypeName + "\n" + callableName + public fun buildKey(receiverTypeName: String, callableName: String): String = receiverTypeName + SEPARATOR + callableName - public fun receiverTypeNameFromKey(key: String): String = key.substringBefore('\n', "") + public fun receiverTypeNameFromKey(key: String): String = key.substringBefore(SEPARATOR, "") - public fun callableNameFromKey(key: String): String = key.substringAfter('\n', "") + public fun callableNameFromKey(key: String): String = key.substringAfter(SEPARATOR, "") } } diff --git a/idea/src/org/jetbrains/kotlin/idea/caches/KotlinIndicesHelper.kt b/idea/src/org/jetbrains/kotlin/idea/caches/KotlinIndicesHelper.kt index cb5d90a301b..f72e43480d2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/caches/KotlinIndicesHelper.kt +++ b/idea/src/org/jetbrains/kotlin/idea/caches/KotlinIndicesHelper.kt @@ -102,7 +102,7 @@ public class KotlinIndicesHelper( } private fun possibleReceiverTypeNames(receiverValues: Collection, dataFlowInfo: DataFlowInfo): Set { - val result = LinkedHashSet() + val result = HashSet() for (receiverValue in receiverValues) { for (type in SmartCastUtils.getSmartCastVariants(receiverValue, bindingContext, dataFlowInfo)) { result.addTypeNames(type) @@ -111,6 +111,12 @@ public class KotlinIndicesHelper( return result } + private fun MutableCollection.addTypeNames(type: JetType) { + val constructor = type.getConstructor() + addIfNotNull(constructor.getDeclarationDescriptor()?.getName()?.asString()) + constructor.getSupertypes().forEach { addTypeNames(it) } + } + private fun receiverValues(expression: JetSimpleNameExpression): Collection> { val receiverPair = ReferenceVariantsHelper.getExplicitReceiverData(expression) if (receiverPair != null) { @@ -125,17 +131,10 @@ public class KotlinIndicesHelper( } else { val resolutionScope = bindingContext[BindingContext.RESOLUTION_SCOPE, expression] ?: return emptyList() - return resolutionScope.getImplicitReceiversWithInstance().map { it.getValue() to CallType.NORMAL } } } - private fun MutableCollection.addTypeNames(type: JetType) { - val constructor = type.getConstructor() - addIfNotNull(constructor.getDeclarationDescriptor()?.getName()?.asString()) - constructor.getSupertypes().forEach { addTypeNames(it) } - } - /** * Check that function or property with the given qualified name can be resolved in given scope and called on given receiver */ diff --git a/idea/testData/completion/basic/multifile/NotImportedExtensionFunction/NotImportedExtensionFunction.dependency.kt b/idea/testData/completion/basic/multifile/NotImportedExtensionFunction/NotImportedExtensionFunction.dependency.kt index 1e1ee43305e..ee5560d0afd 100644 --- a/idea/testData/completion/basic/multifile/NotImportedExtensionFunction/NotImportedExtensionFunction.dependency.kt +++ b/idea/testData/completion/basic/multifile/NotImportedExtensionFunction/NotImportedExtensionFunction.dependency.kt @@ -7,11 +7,11 @@ fun String.helloWithParams(i : Int) : String { return "" } -fun String.helloFunPreventAutoInsert() { -} - fun T.helloFunGeneric() { } fun Int.helloFake() { +} + +fun dynamic.helloDynamic() { } \ No newline at end of file diff --git a/idea/testData/completion/basic/multifile/NotImportedExtensionFunction/NotImportedExtensionFunction.kt b/idea/testData/completion/basic/multifile/NotImportedExtensionFunction/NotImportedExtensionFunction.kt index 07cd20c8978..9196f28dccb 100644 --- a/idea/testData/completion/basic/multifile/NotImportedExtensionFunction/NotImportedExtensionFunction.kt +++ b/idea/testData/completion/basic/multifile/NotImportedExtensionFunction/NotImportedExtensionFunction.kt @@ -6,8 +6,7 @@ fun firstFun() { } // EXIST: helloFun -// EXIST: helloFunPreventAutoInsert // EXIST: helloWithParams // EXIST: helloFunGeneric +// EXIST: helloDynamic // ABSENT: helloFake -// NUMBER: 4 \ No newline at end of file