From 2ddaa15036d6cdc2bc0dfb024fc4fc13dfcb064d Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Sat, 24 Oct 2015 15:28:41 +0300 Subject: [PATCH] Removed more usages of asKtScope() --- .../callableBuilder/CallableBuilder.kt | 24 ++++++++----------- .../callableBuilder/typeUtils.kt | 5 ++-- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt index 01b4926c303..2da089cfdec 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt @@ -66,7 +66,8 @@ import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.scopes.* -import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope +import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier +import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeProjectionImpl import org.jetbrains.kotlin.types.Variance @@ -84,7 +85,7 @@ private val ATTRIBUTE_FUNCTION_NAME = "FUNCTION_NAME" /** * Represents a single choice for a type (e.g. parameter type or return type). */ -class TypeCandidate(val theType: KotlinType, scope: KtScope? = null) { +class TypeCandidate(val theType: KotlinType, scope: LexicalScope? = null) { public val typeParameters: Array var renderedType: String? = null private set @@ -161,7 +162,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { fun computeTypeCandidates( typeInfo: TypeInfo, substitutions: List, - scope: KtScope): List { + scope: LexicalScope): List { if (!typeInfo.substitutionsAllowed) return computeTypeCandidates(typeInfo) return typeCandidates.getOrPut(typeInfo) { val types = typeInfo.getPossibleTypes(this).asReversed() @@ -336,13 +337,13 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { mandatoryTypeParametersAsCandidates.forEach { it.render(typeParameterNameMap, fakeFunction) } } - private fun getDeclarationScope(): KtScope { + private fun getDeclarationScope(): LexicalScope { if (config.isExtension || receiverClassDescriptor == null) { - return currentFileModule.getPackage(config.currentFile.getPackageFqName()).memberScope + return currentFileModule.getPackage(config.currentFile.packageFqName).memberScope.memberScopeAsImportingScope() } if (receiverClassDescriptor is ClassDescriptorWithResolutionScopes) { - return receiverClassDescriptor.getScopeForMemberDeclarationResolution().asKtScope() + return receiverClassDescriptor.scopeForMemberDeclarationResolution } assert (receiverClassDescriptor is JavaClassDescriptor) { "Unexpected receiver class: $receiverClassDescriptor" } @@ -364,12 +365,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { .map { TypeProjectionImpl(it.getDefaultType()) } val memberScope = receiverClassDescriptor.getMemberScope(projections) - return ChainedScope( - receiverClassDescriptor, - "Classifier resolution scope: ${receiverClassDescriptor.getName()}", - typeParamScope, - memberScope - ) + return typeParamScope.memberScopeAsImportingScope(memberScope.memberScopeAsImportingScope()) } private fun collectSubstitutionsForReceiverTypeParameters( @@ -394,7 +390,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { } } - private fun createFakeFunctionDescriptor(scope: KtScope, typeParameterCount: Int): FunctionDescriptor { + private fun createFakeFunctionDescriptor(scope: LexicalScope, typeParameterCount: Int): FunctionDescriptor { val fakeFunction = SimpleFunctionDescriptorImpl.create( MutablePackageFragmentDescriptor(currentFileModule, FqName("fake")), Annotations.EMPTY, @@ -616,7 +612,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { else classBody.addAfter(declaration, classBody.lBrace!!) as KtNamedDeclaration } - private fun getTypeParameterRenames(scope: KtScope): Map { + private fun getTypeParameterRenames(scope: LexicalScope): Map { val allTypeParametersNotInScope = LinkedHashSet() mandatoryTypeParametersAsCandidates.asSequence() diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt index 1445c86e166..b7d195394cd 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt @@ -34,7 +34,8 @@ import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsStatement import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass -import org.jetbrains.kotlin.resolve.scopes.KtScope +import org.jetbrains.kotlin.resolve.scopes.LexicalScope +import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.checker.KotlinTypeChecker import org.jetbrains.kotlin.types.typeUtil.makeNotNullable @@ -79,7 +80,7 @@ private fun KotlinType.render(typeParameterNameMap: Map) = render(typeParameterNameMap, false) internal fun KotlinType.renderLong(typeParameterNameMap: Map) = render(typeParameterNameMap, true) -internal fun getTypeParameterNamesNotInScope(typeParameters: Collection, scope: KtScope): List { +internal fun getTypeParameterNamesNotInScope(typeParameters: Collection, scope: LexicalScope): List { return typeParameters.filter { typeParameter -> val classifier = scope.getClassifier(typeParameter.name, NoLookupLocation.FROM_IDE) classifier == null || classifier != typeParameter