Created util function addImportScope and use it in ShadowedDeclarationsFilter
This commit is contained in:
@@ -31,7 +31,6 @@ import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
|||||||
import org.jetbrains.kotlin.resolve.calls.context.CheckArgumentTypesMode
|
import org.jetbrains.kotlin.resolve.calls.context.CheckArgumentTypesMode
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency
|
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency
|
||||||
import org.jetbrains.kotlin.resolve.scopes.ExplicitImportsScope
|
import org.jetbrains.kotlin.resolve.scopes.ExplicitImportsScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalChainedScope
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||||
import org.jetbrains.kotlin.types.TypeUtils
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
@@ -164,16 +163,14 @@ public class ShadowedDeclarationsFilter(
|
|||||||
override fun getCallType() = Call.CallType.DEFAULT
|
override fun getCallType() = Call.CallType.DEFAULT
|
||||||
}
|
}
|
||||||
|
|
||||||
var resolutionScope = bindingContext[BindingContext.LEXICAL_SCOPE, context] ?: return descriptors
|
var lexicalScope = bindingContext[BindingContext.LEXICAL_SCOPE, context] ?: return descriptors
|
||||||
|
|
||||||
if (descriptorsToImport.isNotEmpty()) {
|
if (descriptorsToImport.isNotEmpty()) {
|
||||||
resolutionScope = LexicalChainedScope(resolutionScope, resolutionScope.ownerDescriptor, false, null,
|
lexicalScope = lexicalScope.addImportScope(ExplicitImportsScope(descriptorsToImport))
|
||||||
"Scope with explicitly imported descriptors",
|
|
||||||
ExplicitImportsScope(descriptorsToImport))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val dataFlowInfo = bindingContext.getDataFlowInfo(context)
|
val dataFlowInfo = bindingContext.getDataFlowInfo(context)
|
||||||
val context = BasicCallResolutionContext.create(bindingTrace, resolutionScope, newCall, TypeUtils.NO_EXPECTED_TYPE, dataFlowInfo,
|
val context = BasicCallResolutionContext.create(bindingTrace, lexicalScope, newCall, TypeUtils.NO_EXPECTED_TYPE, dataFlowInfo,
|
||||||
ContextDependency.INDEPENDENT, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS,
|
ContextDependency.INDEPENDENT, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS,
|
||||||
CallChecker.DoNothing, false)
|
CallChecker.DoNothing, false)
|
||||||
val callResolver = resolutionFacade.frontendService<CallResolver>()
|
val callResolver = resolutionFacade.frontendService<CallResolver>()
|
||||||
|
|||||||
@@ -22,7 +22,11 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.FileScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.LexicalChainedScope
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.utils.getFileScope
|
||||||
|
|
||||||
|
|
||||||
public fun JetScope.getAllAccessibleVariables(name: Name): Collection<VariableDescriptor>
|
public fun JetScope.getAllAccessibleVariables(name: Name): Collection<VariableDescriptor>
|
||||||
@@ -42,3 +46,21 @@ public fun JetScope.getVariableFromImplicitReceivers(name: Name): VariableDescri
|
|||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun LexicalScope.addImportScope(importScope: JetScope): LexicalScope {
|
||||||
|
val fileScope = getFileScope()
|
||||||
|
val scopeWithAdditionImport =
|
||||||
|
LexicalChainedScope(fileScope, fileScope.ownerDescriptor, false, null, "Scope with addition import", importScope)
|
||||||
|
return LexicalScopeWrapper(this, scopeWithAdditionImport)
|
||||||
|
}
|
||||||
|
|
||||||
|
private class LexicalScopeWrapper(val delegate: LexicalScope, val fileScopeReplace: LexicalScope): LexicalScope by delegate {
|
||||||
|
override val parent: LexicalScope? by lazy(LazyThreadSafetyMode.NONE) {
|
||||||
|
if (delegate is FileScope) {
|
||||||
|
fileScopeReplace
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LexicalScopeWrapper(delegate.parent!!, fileScopeReplace)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user