Resolve type alias SAM constructors in synthetic scope

This commit is contained in:
Mikhail Zarechenskiy
2017-05-04 03:11:40 +03:00
parent 7541a3754d
commit e821b25288
10 changed files with 43 additions and 130 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,13 @@
package org.jetbrains.kotlin.resolve.calls.tower
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithVisibility
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.resolve.scopes.SyntheticConstructorsProvider
import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo
import org.jetbrains.kotlin.types.KotlinType
@@ -35,8 +36,6 @@ interface ImplicitScopeTower {
val syntheticScopes: SyntheticScopes
val syntheticConstructorsProvider: SyntheticConstructorsProvider
val location: LookupLocation
val isDebuggerContext: Boolean
@@ -163,7 +163,6 @@ internal class QualifierScopeTowerLevel(scopeTower: ImplicitScopeTower, val qual
override fun getFunctions(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?) = qualifier.staticScope
.getContributedFunctionsAndConstructors(name,
location,
scopeTower.syntheticConstructorsProvider,
scopeTower.syntheticScopes,
qualifier.staticScope).map {
createCandidateDescriptor(it, dispatchReceiver = null)
@@ -191,7 +190,6 @@ internal open class ScopeBasedTowerLevel protected constructor(
override fun getFunctions(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver>
= resolutionScope.getContributedFunctionsAndConstructors(name,
location,
scopeTower.syntheticConstructorsProvider,
scopeTower.syntheticScopes,
resolutionScope).map {
createCandidateDescriptor(it, dispatchReceiver = null)
@@ -271,30 +269,25 @@ private fun KotlinType?.getInnerConstructors(name: Name, location: LookupLocatio
private fun ResolutionScope.getContributedFunctionsAndConstructors(
name: Name,
location: LookupLocation,
syntheticConstructorsProvider: SyntheticConstructorsProvider,
syntheticScopes: SyntheticScopes,
scope: ResolutionScope
): Collection<FunctionDescriptor> {
val result = ArrayList<FunctionDescriptor>(getContributedFunctions(name, location))
val classifier = getContributedClassifier(name, location)
if (classifier != null) {
classifier.getCallableConstructors().filterTo(result) { it.dispatchReceiverParameter == null }
syntheticConstructorsProvider.getSyntheticConstructors(classifier, location).filterTo(result) { it.dispatchReceiverParameter == null }
val callableConstructors = when (classifier) {
is TypeAliasDescriptor -> if (classifier.canHaveCallableConstructors) classifier.constructors else emptyList()
is ClassDescriptor -> if (classifier.canHaveCallableConstructors) classifier.constructors else emptyList()
else -> emptyList()
}
callableConstructors.filterTo(result) { it.dispatchReceiverParameter == null }
result.addAll(syntheticScopes.collectSyntheticStaticFunctions(scope, name, location))
return result.toList()
}
private fun ClassifierDescriptor.getCallableConstructors(): Collection<FunctionDescriptor> =
when (this) {
is TypeAliasDescriptor -> if (canHaveCallableConstructors) constructors else emptyList()
is ClassDescriptor -> if (canHaveCallableConstructors) constructors else emptyList()
else -> emptyList()
}
private fun ResolutionScope.getContributedObjectVariables(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
val objectDescriptor = getFakeDescriptorForObject(getContributedClassifier(name, location))