diff --git a/idea/src/org/jetbrains/jet/plugin/caches/JetShortNamesCache.kt b/idea/src/org/jetbrains/jet/plugin/caches/JetShortNamesCache.kt index cb77e54114f..467357b969f 100644 --- a/idea/src/org/jetbrains/jet/plugin/caches/JetShortNamesCache.kt +++ b/idea/src/org/jetbrains/jet/plugin/caches/JetShortNamesCache.kt @@ -201,7 +201,6 @@ public class JetShortNamesCache(private val project: Project) : PsiShortNamesCac public fun getJetTopLevelCallables(nameFilter: (String) -> Boolean, context: JetExpression /*TODO: to be dropped*/, resolveSession: ResolveSessionForBodies, scope: GlobalSearchScope): Collection { val result = ArrayList() - val sourceNames = JetTopLevelFunctionsFqnNameIndex.getInstance().getAllKeys(project).stream() + JetTopLevelPropertiesFqnNameIndex.getInstance().getAllKeys(project).stream() val allFqNames = sourceNames.map { FqName(it) } + JetFromJavaDescriptorHelper.getTopLevelCallableFqNames(project, scope, false).stream() @@ -213,7 +212,6 @@ public class JetShortNamesCache(private val project: Project) : PsiShortNamesCac return result } - // TODO: Make it work for properties public fun getJetCallableExtensions(nameFilter: (String) -> Boolean, expression: JetSimpleNameExpression, resolveSession: ResolveSessionForBodies, @@ -227,39 +225,14 @@ public class JetShortNamesCache(private val project: Project) : PsiShortNamesCac return listOf() } - val functionFQNs = extensionFunctionsFromSourceFqNames(nameFilter, scope) - - JetFromJavaDescriptorHelper.getTopLevelCallableFqNames(project, scope, true) - .filterTo(functionFQNs) { nameFilter(it.shortName().asString()) } + val sourceNames = JetTopLevelFunctionsFqnNameIndex.getInstance().getAllKeys(project).stream() + JetTopLevelPropertiesFqnNameIndex.getInstance().getAllKeys(project).stream() + val allFqNames = sourceNames.map { FqName(it) } + JetFromJavaDescriptorHelper.getTopLevelCallableFqNames(project, scope, true).stream() // Iterate through the function with attempt to resolve found functions - return functionFQNs.flatMap { ExpressionTypingUtils.canFindSuitableCall(it, receiverExpression, expressionType, jetScope, resolveSession.getModuleDescriptor()) } - } - - private fun extensionFunctionsFromSourceFqNames(nameFilter: (String) -> Boolean, scope: GlobalSearchScope): HashSet { - val extensionFunctionNames = HashSet(JetTopLevelExtensionFunctionShortNameIndex.getInstance().getAllKeys(project)) - - val functionFQNs = HashSet() - - // Collect all possible extension function qualified names - for (name in extensionFunctionNames) { - if (nameFilter(name)) { - val extensionFunctions = getJetExtensionFunctionsByName(name, scope) - - for (extensionFunction in extensionFunctions) { - if (extensionFunction is JetNamedFunction) { - functionFQNs.add(extensionFunction.getFqName()!!) - } - else if (extensionFunction is PsiMethod) { - val functionFQN = JetFromJavaDescriptorHelper.getJetTopLevelDeclarationFQN(extensionFunction) - if (functionFQN != null) { - functionFQNs.add(functionFQN) - } - } - } - } - } - return functionFQNs + return allFqNames + .filter { nameFilter(it.shortName().asString()) } + .toList() + .flatMap { ExpressionTypingUtils.canFindSuitableCall(it, receiverExpression, expressionType, jetScope, resolveSession.getModuleDescriptor()) } } public fun getJetClassesDescriptors(acceptedShortNameCondition: (String) -> Boolean, analyzer: KotlinCodeAnalyzer, scope: GlobalSearchScope): Collection { diff --git a/idea/testData/completion/basic/custom/TopLevelNonImportedExtProp.kt b/idea/testData/completion/basic/custom/TopLevelNonImportedExtProp.kt new file mode 100644 index 00000000000..679e10550e1 --- /dev/null +++ b/idea/testData/completion/basic/custom/TopLevelNonImportedExtProp.kt @@ -0,0 +1,8 @@ +package testing + +fun someFun() { + "".hello +} + +// EXIST: helloProp1, helloProp2 +// ABSENT: helloProp3, helloProp4 diff --git a/idea/testData/completion/basic/custom/TopLevelNonImportedExtPropSrc/source.kt b/idea/testData/completion/basic/custom/TopLevelNonImportedExtPropSrc/source.kt new file mode 100644 index 00000000000..e942f6acb9b --- /dev/null +++ b/idea/testData/completion/basic/custom/TopLevelNonImportedExtPropSrc/source.kt @@ -0,0 +1,6 @@ +package abc + +public val String.helloProp1: Int get() = 1 +public val String.helloProp2: Int get() = 2 +public val Int.helloProp3: Int get() = 3 +public val helloProp4: Int = 4 \ No newline at end of file diff --git a/idea/testData/completion/basic/multifile/NotImportedExtensionProperty/NotImportedExtensionProperty.dependency.kt b/idea/testData/completion/basic/multifile/NotImportedExtensionProperty/NotImportedExtensionProperty.dependency.kt new file mode 100644 index 00000000000..21c09f7f633 --- /dev/null +++ b/idea/testData/completion/basic/multifile/NotImportedExtensionProperty/NotImportedExtensionProperty.dependency.kt @@ -0,0 +1,6 @@ +package abc + +val String.helloProp1: Int get() = 1 +val String.helloProp2: Int get() = 2 +val Int.helloProp3: Int get() = 3 +val helloProp4: Int = 4 \ No newline at end of file diff --git a/idea/testData/completion/basic/multifile/NotImportedExtensionProperty/NotImportedExtensionProperty.kt b/idea/testData/completion/basic/multifile/NotImportedExtensionProperty/NotImportedExtensionProperty.kt new file mode 100644 index 00000000000..28f4a15b587 --- /dev/null +++ b/idea/testData/completion/basic/multifile/NotImportedExtensionProperty/NotImportedExtensionProperty.kt @@ -0,0 +1,12 @@ +package first + +fun firstFun() { + val a = "" + a.hello +} + +// EXIST: helloProp1 +// EXIST: helloProp2 +// ABSENT: helloProp3 +// ABSENT: helloProp4 +// NUMBER: 2 \ No newline at end of file