Completion for evaluate expression: add only imports from code fragment to scope when analyzing it

This commit is contained in:
Natalia Ukhorskaya
2015-10-08 17:05:22 +03:00
parent 7e2c2ef678
commit ccbb015606
4 changed files with 41 additions and 32 deletions
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.resolve.calls.context.ContextDependency
import org.jetbrains.kotlin.resolve.scopes.ExplicitImportsScope
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.resolve.scopes.utils.addImportScope
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.util.descriptorsEqualWithSubstitution
import java.util.*
@@ -22,11 +22,7 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.VariableDescriptor
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
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.LexicalChainedScope
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.utils.getFileScope
public fun JetScope.getAllAccessibleVariables(name: Name): Collection<VariableDescriptor>
@@ -45,22 +41,4 @@ public fun JetScope.getVariableFromImplicitReceivers(name: Name): VariableDescri
it.type.memberScope.getProperties(name, NoLookupLocation.FROM_IDE).singleOrNull()?.let { return it }
}
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)
}
}
}