Minor simplification in CompletionSession
This commit is contained in:
+2
-2
@@ -82,7 +82,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
return CompletionKind.NAMED_ARGUMENTS_ONLY
|
return CompletionKind.NAMED_ARGUMENTS_ONLY
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reference == null) {
|
if (nameExpression == null) {
|
||||||
val parameter = position.getParent() as? JetParameter
|
val parameter = position.getParent() as? JetParameter
|
||||||
return if (parameter != null && position == parameter.getNameIdentifier())
|
return if (parameter != null && position == parameter.getNameIdentifier())
|
||||||
CompletionKind.PARAMETER_NAME
|
CompletionKind.PARAMETER_NAME
|
||||||
@@ -107,7 +107,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
val typeReference = position.getStrictParentOfType<JetTypeReference>()
|
val typeReference = position.getStrictParentOfType<JetTypeReference>()
|
||||||
if (typeReference != null) {
|
if (typeReference != null) {
|
||||||
val firstPartReference = PsiTreeUtil.findChildOfType(typeReference, javaClass<JetSimpleNameExpression>())
|
val firstPartReference = PsiTreeUtil.findChildOfType(typeReference, javaClass<JetSimpleNameExpression>())
|
||||||
if (firstPartReference == reference.expression) {
|
if (firstPartReference == nameExpression) {
|
||||||
return CompletionKind.TYPES
|
return CompletionKind.TYPES
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-17
@@ -80,23 +80,23 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
|
|||||||
protected val moduleDescriptor: ModuleDescriptor = resolutionFacade.findModuleDescriptor(file)
|
protected val moduleDescriptor: ModuleDescriptor = resolutionFacade.findModuleDescriptor(file)
|
||||||
protected val project: Project = position.getProject()
|
protected val project: Project = position.getProject()
|
||||||
|
|
||||||
protected val reference: JetSimpleNameReference?
|
protected val nameExpression: JetSimpleNameExpression?
|
||||||
protected val expression: JetExpression?
|
protected val expression: JetExpression?
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val reference = position.getParent()?.getReferences()?.firstIsInstanceOrNull<JetSimpleNameReference>()
|
val reference = position.getParent()?.getReferences()?.firstIsInstanceOrNull<JetSimpleNameReference>()
|
||||||
if (reference != null) {
|
if (reference != null) {
|
||||||
if (reference.expression is JetLabelReferenceExpression) {
|
if (reference.expression is JetLabelReferenceExpression) {
|
||||||
|
this.nameExpression = null
|
||||||
this.expression = reference.expression.getParent().getParent() as? JetExpressionWithLabel
|
this.expression = reference.expression.getParent().getParent() as? JetExpressionWithLabel
|
||||||
this.reference = null
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.expression = reference.expression
|
this.nameExpression = reference.expression
|
||||||
this.reference = reference
|
this.expression = nameExpression
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.reference = null
|
this.nameExpression = null
|
||||||
this.expression = 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 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 {
|
protected val lookupElementFactory: LookupElementFactory = run {
|
||||||
if (receiversData != null) {
|
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 TypeParameterDescriptor && !isTypeParameterVisible(descriptor)) return false
|
||||||
|
|
||||||
if (descriptor is DeclarationDescriptorWithVisibility) {
|
if (descriptor is DeclarationDescriptorWithVisibility) {
|
||||||
val visible = descriptor.isVisible(inDescriptor, bindingContext, reference?.expression)
|
val visible = descriptor.isVisible(inDescriptor, bindingContext, nameExpression)
|
||||||
if (visible) return true
|
if (visible) return true
|
||||||
if (!configuration.completeNonAccessibleDeclarations) return false
|
if (!configuration.completeNonAccessibleDeclarations) return false
|
||||||
return DescriptorToSourceUtilsIde.getAnyDeclaration(project, descriptor) !is PsiCompiledElement
|
return DescriptorToSourceUtilsIde.getAnyDeclaration(project, descriptor) !is PsiCompiledElement
|
||||||
@@ -211,9 +211,12 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
|
|||||||
|
|
||||||
protected val referenceVariants: Collection<DeclarationDescriptor> by Delegates.lazy {
|
protected val referenceVariants: Collection<DeclarationDescriptor> by Delegates.lazy {
|
||||||
if (descriptorKindFilter != null) {
|
if (descriptorKindFilter != null) {
|
||||||
val expression = reference!!.expression
|
referenceVariantsHelper.getReferenceVariants(
|
||||||
referenceVariantsHelper.getReferenceVariants(expression, descriptorKindFilter!!, prefixMatcher.asNameFilter(), filterOutJavaGettersAndSetters = configuration.filterOutJavaGettersAndSetters)
|
nameExpression!!,
|
||||||
.excludeNonInitializedVariable(expression)
|
descriptorKindFilter!!,
|
||||||
|
prefixMatcher.asNameFilter(),
|
||||||
|
filterOutJavaGettersAndSetters = configuration.filterOutJavaGettersAndSetters
|
||||||
|
).excludeNonInitializedVariable(nameExpression)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
emptyList()
|
emptyList()
|
||||||
@@ -234,7 +237,7 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected fun getRuntimeReceiverTypeReferenceVariants(): Collection<DeclarationDescriptor> {
|
protected fun getRuntimeReceiverTypeReferenceVariants(): Collection<DeclarationDescriptor> {
|
||||||
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 ->
|
return descriptors.filter { descriptor ->
|
||||||
referenceVariants.none { comparePossiblyOverridingDescriptors(project, it, descriptor) }
|
referenceVariants.none { comparePossiblyOverridingDescriptors(project, it, descriptor) }
|
||||||
}
|
}
|
||||||
@@ -249,17 +252,17 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected fun getTopLevelCallables(): Collection<DeclarationDescriptor> {
|
protected fun getTopLevelCallables(): Collection<DeclarationDescriptor> {
|
||||||
val descriptors = indicesHelper.getTopLevelCallables({ prefixMatcher.prefixMatches(it) })
|
return indicesHelper.getTopLevelCallables({ prefixMatcher.prefixMatches(it) })
|
||||||
return filterShadowedNonImported(descriptors, reference!!)
|
.filterShadowedNonImported()
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun getTopLevelExtensions(): Collection<CallableDescriptor> {
|
protected fun getTopLevelExtensions(): Collection<CallableDescriptor> {
|
||||||
val descriptors = indicesHelper.getCallableTopLevelExtensions({ prefixMatcher.prefixMatches(it) }, reference!!.expression, bindingContext)
|
return indicesHelper.getCallableTopLevelExtensions({ prefixMatcher.prefixMatches(it) }, nameExpression!!, bindingContext)
|
||||||
return filterShadowedNonImported(descriptors, reference)
|
.filterShadowedNonImported()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun filterShadowedNonImported(descriptors: Collection<CallableDescriptor>, reference: JetSimpleNameReference): Collection<CallableDescriptor> {
|
private fun Collection<CallableDescriptor>.filterShadowedNonImported(): Collection<CallableDescriptor> {
|
||||||
return ShadowedDeclarationsFilter(bindingContext, moduleDescriptor, project).filterNonImported(descriptors, referenceVariants, reference.expression)
|
return ShadowedDeclarationsFilter(bindingContext, moduleDescriptor, project).filterNonImported(this, referenceVariants, nameExpression!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun addAllClasses(kindFilter: (ClassKind) -> Boolean) {
|
protected fun addAllClasses(kindFilter: (ClassKind) -> Boolean) {
|
||||||
|
|||||||
+3
-3
@@ -57,7 +57,7 @@ class SmartCompletionSession(configuration: CompletionSessionConfiguration, para
|
|||||||
if (result != null) {
|
if (result != null) {
|
||||||
collector.addElements(result.additionalItems)
|
collector.addElements(result.additionalItems)
|
||||||
|
|
||||||
if (reference != null) {
|
if (nameExpression != null) {
|
||||||
val filter = result.declarationFilter
|
val filter = result.declarationFilter
|
||||||
if (filter != null) {
|
if (filter != null) {
|
||||||
referenceVariants.forEach { collector.addElements(filter(it)) }
|
referenceVariants.forEach { collector.addElements(filter(it)) }
|
||||||
@@ -86,8 +86,8 @@ class SmartCompletionSession(configuration: CompletionSessionConfiguration, para
|
|||||||
|
|
||||||
// special completion for outside parenthesis lambda argument
|
// special completion for outside parenthesis lambda argument
|
||||||
private fun addFunctionLiteralArgumentCompletions() {
|
private fun addFunctionLiteralArgumentCompletions() {
|
||||||
if (reference != null) {
|
if (nameExpression != null) {
|
||||||
val receiverData = ReferenceVariantsHelper.getExplicitReceiverData(reference.expression)
|
val receiverData = ReferenceVariantsHelper.getExplicitReceiverData(nameExpression)
|
||||||
if (receiverData != null && receiverData.second == CallType.INFIX) {
|
if (receiverData != null && receiverData.second == CallType.INFIX) {
|
||||||
val call = receiverData.first.getCall(bindingContext)
|
val call = receiverData.first.getCall(bindingContext)
|
||||||
if (call != null && call.getFunctionLiteralArguments().isEmpty()) {
|
if (call != null && call.getFunctionLiteralArguments().isEmpty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user