Refactoring: generify and remove duplicated code

This commit is contained in:
Mikhail Zarechenskiy
2020-01-27 10:40:09 +03:00
parent 4e3c27c4ec
commit 0530f9ed1c
8 changed files with 108 additions and 102 deletions
@@ -312,7 +312,10 @@ private fun KotlinResolutionCandidate.getExpectedTypeWithSAMConversion(
!callComponents.languageVersionSettings.supportsFeature(LanguageFeature.ProhibitVarargAsArrayAfterSamArgument)
if (generatingAdditionalSamCandidateIsEnabled) return null
if (!callComponents.samConversionOracle.shouldRunSamConversionForFunction(resolvedCall.candidateDescriptor)) return null
val samConversionOracle = callComponents.samConversionOracle
if (!callComponents.languageVersionSettings.supportsFeature(LanguageFeature.SamConversionForKotlinFunctions)) {
if (!samConversionOracle.shouldRunSamConversionForFunction(resolvedCall.candidateDescriptor)) return null
}
val argumentIsFunctional = when (argument) {
is SimpleKotlinCallArgument -> argument.receiver.stableType.isFunctionType
@@ -323,13 +326,12 @@ private fun KotlinResolutionCandidate.getExpectedTypeWithSAMConversion(
val originalExpectedType = argument.getExpectedType(candidateParameter.original, callComponents.languageVersionSettings)
if (!callComponents.samConversionOracle.isPossibleSamType(originalExpectedType)) return null
val convertedTypeByOriginal =
callComponents.samConversionResolver.getFunctionTypeForPossibleSamType(originalExpectedType) ?: return null
callComponents.samConversionResolver.getFunctionTypeForPossibleSamType(originalExpectedType, samConversionOracle) ?: return null
val candidateExpectedType = argument.getExpectedType(candidateParameter, callComponents.languageVersionSettings)
val convertedTypeByCandidate = callComponents.samConversionResolver.getFunctionTypeForPossibleSamType(candidateExpectedType)
val convertedTypeByCandidate =
callComponents.samConversionResolver.getFunctionTypeForPossibleSamType(candidateExpectedType, samConversionOracle)
assert(candidateExpectedType.constructor == originalExpectedType.constructor && convertedTypeByCandidate != null) {
"If original type is SAM type, then candidate should have same type constructor and corresponding function type\n" +