diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt index ce541503e30..7193af5162b 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt @@ -82,7 +82,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration, return CompletionKind.NAMED_ARGUMENTS_ONLY } - if (reference == null) { + if (nameExpression == null) { val parameter = position.getParent() as? JetParameter return if (parameter != null && position == parameter.getNameIdentifier()) CompletionKind.PARAMETER_NAME @@ -107,7 +107,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration, val typeReference = position.getStrictParentOfType() if (typeReference != null) { val firstPartReference = PsiTreeUtil.findChildOfType(typeReference, javaClass()) - if (firstPartReference == reference.expression) { + if (firstPartReference == nameExpression) { return CompletionKind.TYPES } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt index c4b6fe976a6..4fdddaf071b 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt @@ -80,23 +80,23 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC protected val moduleDescriptor: ModuleDescriptor = resolutionFacade.findModuleDescriptor(file) protected val project: Project = position.getProject() - protected val reference: JetSimpleNameReference? + protected val nameExpression: JetSimpleNameExpression? protected val expression: JetExpression? init { val reference = position.getParent()?.getReferences()?.firstIsInstanceOrNull() if (reference != null) { if (reference.expression is JetLabelReferenceExpression) { + this.nameExpression = null this.expression = reference.expression.getParent().getParent() as? JetExpressionWithLabel - this.reference = null } else { - this.expression = reference.expression - this.reference = reference + this.nameExpression = reference.expression + this.expression = nameExpression } } else { - this.reference = null + this.nameExpression = null this.expression = null } } @@ -131,7 +131,7 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC protected val referenceVariantsHelper: ReferenceVariantsHelper = ReferenceVariantsHelper(bindingContext, moduleDescriptor, project, isVisibleFilter) - protected val receiversData: ReferenceVariantsHelper.ReceiversData? = reference?.let { referenceVariantsHelper.getReferenceVariantsReceivers(it.expression) } + protected val receiversData: ReferenceVariantsHelper.ReceiversData? = nameExpression?.let { referenceVariantsHelper.getReferenceVariantsReceivers(it) } protected val lookupElementFactory: LookupElementFactory = run { if (receiversData != null) { @@ -175,7 +175,7 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC if (descriptor is TypeParameterDescriptor && !isTypeParameterVisible(descriptor)) return false if (descriptor is DeclarationDescriptorWithVisibility) { - val visible = descriptor.isVisible(inDescriptor, bindingContext, reference?.expression) + val visible = descriptor.isVisible(inDescriptor, bindingContext, nameExpression) if (visible) return true if (!configuration.completeNonAccessibleDeclarations) return false return DescriptorToSourceUtilsIde.getAnyDeclaration(project, descriptor) !is PsiCompiledElement @@ -211,9 +211,12 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC protected val referenceVariants: Collection by Delegates.lazy { if (descriptorKindFilter != null) { - val expression = reference!!.expression - referenceVariantsHelper.getReferenceVariants(expression, descriptorKindFilter!!, prefixMatcher.asNameFilter(), filterOutJavaGettersAndSetters = configuration.filterOutJavaGettersAndSetters) - .excludeNonInitializedVariable(expression) + referenceVariantsHelper.getReferenceVariants( + nameExpression!!, + descriptorKindFilter!!, + prefixMatcher.asNameFilter(), + filterOutJavaGettersAndSetters = configuration.filterOutJavaGettersAndSetters + ).excludeNonInitializedVariable(nameExpression) } else { emptyList() @@ -234,7 +237,7 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC } protected fun getRuntimeReceiverTypeReferenceVariants(): Collection { - val descriptors = referenceVariantsHelper.getReferenceVariants(reference!!.expression, descriptorKindFilter!!, prefixMatcher.asNameFilter(), useRuntimeReceiverType = true) + val descriptors = referenceVariantsHelper.getReferenceVariants(nameExpression!!, descriptorKindFilter!!, prefixMatcher.asNameFilter(), useRuntimeReceiverType = true) return descriptors.filter { descriptor -> referenceVariants.none { comparePossiblyOverridingDescriptors(project, it, descriptor) } } @@ -249,17 +252,17 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC } protected fun getTopLevelCallables(): Collection { - val descriptors = indicesHelper.getTopLevelCallables({ prefixMatcher.prefixMatches(it) }) - return filterShadowedNonImported(descriptors, reference!!) + return indicesHelper.getTopLevelCallables({ prefixMatcher.prefixMatches(it) }) + .filterShadowedNonImported() } protected fun getTopLevelExtensions(): Collection { - val descriptors = indicesHelper.getCallableTopLevelExtensions({ prefixMatcher.prefixMatches(it) }, reference!!.expression, bindingContext) - return filterShadowedNonImported(descriptors, reference) + return indicesHelper.getCallableTopLevelExtensions({ prefixMatcher.prefixMatches(it) }, nameExpression!!, bindingContext) + .filterShadowedNonImported() } - private fun filterShadowedNonImported(descriptors: Collection, reference: JetSimpleNameReference): Collection { - return ShadowedDeclarationsFilter(bindingContext, moduleDescriptor, project).filterNonImported(descriptors, referenceVariants, reference.expression) + private fun Collection.filterShadowedNonImported(): Collection { + return ShadowedDeclarationsFilter(bindingContext, moduleDescriptor, project).filterNonImported(this, referenceVariants, nameExpression!!) } protected fun addAllClasses(kindFilter: (ClassKind) -> Boolean) { diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/SmartCompletionSession.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/SmartCompletionSession.kt index fd370e8ee82..38f42d0e95e 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/SmartCompletionSession.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/SmartCompletionSession.kt @@ -57,7 +57,7 @@ class SmartCompletionSession(configuration: CompletionSessionConfiguration, para if (result != null) { collector.addElements(result.additionalItems) - if (reference != null) { + if (nameExpression != null) { val filter = result.declarationFilter if (filter != null) { referenceVariants.forEach { collector.addElements(filter(it)) } @@ -86,8 +86,8 @@ class SmartCompletionSession(configuration: CompletionSessionConfiguration, para // special completion for outside parenthesis lambda argument private fun addFunctionLiteralArgumentCompletions() { - if (reference != null) { - val receiverData = ReferenceVariantsHelper.getExplicitReceiverData(reference.expression) + if (nameExpression != null) { + val receiverData = ReferenceVariantsHelper.getExplicitReceiverData(nameExpression) if (receiverData != null && receiverData.second == CallType.INFIX) { val call = receiverData.first.getCall(bindingContext) if (call != null && call.getFunctionLiteralArguments().isEmpty()) {