Pass SamConversionResolver explicitly cause it should be call site module-local

This commit is contained in:
Yan Zhulanow
2017-08-09 16:47:28 +03:00
committed by Pavel V. Talanov
parent f0f6a252a5
commit 6f180416b1
8 changed files with 69 additions and 41 deletions
@@ -18,16 +18,18 @@ package org.jetbrains.kotlin.synthetic
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.load.java.components.SamConversionResolver
import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes
import org.jetbrains.kotlin.storage.StorageManager
class JavaSyntheticScopes(
storageManager: StorageManager,
lookupTracker: LookupTracker,
languageVersionSettings: LanguageVersionSettings
languageVersionSettings: LanguageVersionSettings,
samConventionResolver: SamConversionResolver
): SyntheticScopes {
override val scopes = listOf(
JavaSyntheticPropertiesScope(storageManager, lookupTracker),
SamAdapterFunctionsScope(storageManager, languageVersionSettings)
SamAdapterFunctionsScope(storageManager, languageVersionSettings, samConventionResolver)
)
}
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptorImpl
import org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.load.java.components.SamConversionResolver
import org.jetbrains.kotlin.load.java.descriptors.JavaClassConstructorDescriptor
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
@@ -49,7 +50,8 @@ interface SamAdapterExtensionFunctionDescriptor : FunctionDescriptor, SyntheticM
class SamAdapterFunctionsScope(
storageManager: StorageManager,
private val languageVersionSettings: LanguageVersionSettings
private val languageVersionSettings: LanguageVersionSettings,
private val samResolver: SamConversionResolver
) : SyntheticScope {
private val extensionForFunction = storageManager.createMemoizedFunctionWithNullableValues<FunctionDescriptor, FunctionDescriptor> { function ->
extensionForFunctionNotCached(function)
@@ -57,17 +59,17 @@ class SamAdapterFunctionsScope(
private val samAdapterForStaticFunction =
storageManager.createMemoizedFunction<JavaMethodDescriptor, SamAdapterDescriptor<JavaMethodDescriptor>> { function ->
SingleAbstractMethodUtils.createSamAdapterFunction(function)
SingleAbstractMethodUtils.createSamAdapterFunction(function, samResolver)
}
private val samConstructorForClassifier =
storageManager.createMemoizedFunction<JavaClassDescriptor, SamConstructorDescriptor> { classifier ->
SingleAbstractMethodUtils.createSamConstructorFunction(classifier.containingDeclaration, classifier)
SingleAbstractMethodUtils.createSamConstructorFunction(classifier.containingDeclaration, classifier, samResolver)
}
private val samConstructorForJavaConstructor =
storageManager.createMemoizedFunction<JavaClassConstructorDescriptor, ClassConstructorDescriptor> { constructor ->
SingleAbstractMethodUtils.createSamAdapterConstructor(constructor) as ClassConstructorDescriptor
SingleAbstractMethodUtils.createSamAdapterConstructor(constructor, samResolver) as ClassConstructorDescriptor
}
private val samConstructorForTypeAliasConstructor =
@@ -82,7 +84,7 @@ class SamAdapterFunctionsScope(
if (!SingleAbstractMethodUtils.isSamAdapterNecessary(function)) return null
if (function.returnType == null) return null
if (function.isHiddenInResolution(languageVersionSettings)) return null
return MyFunctionDescriptor.create(function)
return MyFunctionDescriptor.create(function, samResolver)
}
override fun getSyntheticMemberFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
@@ -199,15 +201,16 @@ class SamAdapterFunctionsScope(
return getTypeAliasSamConstructor(classifier)
}
if (classifier !is LazyJavaClassDescriptor || classifier.functionTypeForSamInterface == null) return null
if (classifier !is LazyJavaClassDescriptor || classifier.defaultFunctionTypeForSamInterface == null) return null
return samConstructorForClassifier(classifier)
}
private fun getTypeAliasSamConstructor(classifier: TypeAliasDescriptor): SamConstructorDescriptor? {
val classDescriptor = classifier.classDescriptor ?: return null
if (classDescriptor !is LazyJavaClassDescriptor || classDescriptor.functionTypeForSamInterface == null) return null
if (classDescriptor !is LazyJavaClassDescriptor || classDescriptor.defaultFunctionTypeForSamInterface == null) return null
return SingleAbstractMethodUtils.createTypeAliasSamConstructorFunction(classifier, samConstructorForClassifier(classDescriptor))
return SingleAbstractMethodUtils.createTypeAliasSamConstructorFunction(
classifier, samConstructorForClassifier(classDescriptor), samResolver)
}
private class MyFunctionDescriptor(
@@ -227,7 +230,7 @@ class SamAdapterFunctionsScope(
}
companion object {
fun create(sourceFunction: FunctionDescriptor): MyFunctionDescriptor {
fun create(sourceFunction: FunctionDescriptor, samResolver: SamConversionResolver): MyFunctionDescriptor {
val descriptor = MyFunctionDescriptor(sourceFunction.containingDeclaration,
null,
sourceFunction.annotations,
@@ -243,7 +246,8 @@ class SamAdapterFunctionsScope(
val typeSubstitutor = DescriptorSubstitutor.substituteTypeParameters(sourceTypeParams, TypeSubstitution.EMPTY, descriptor, typeParameters)
val returnType = typeSubstitutor.safeSubstitute(sourceFunction.returnType!!, Variance.INVARIANT)
val valueParameters = SingleAbstractMethodUtils.createValueParametersForSamAdapter(sourceFunction, descriptor, typeSubstitutor)
val valueParameters = SingleAbstractMethodUtils.createValueParametersForSamAdapter(
sourceFunction, descriptor, typeSubstitutor, samResolver)
val visibility = syntheticVisibility(sourceFunction, isUsedForExtension = false)