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
@@ -50,7 +50,7 @@ public class SamType {
@NotNull @NotNull
public KotlinType getKotlinFunctionType() { public KotlinType getKotlinFunctionType() {
//noinspection ConstantConditions //noinspection ConstantConditions
return getJavaClassDescriptor().getFunctionTypeForSamInterface(); return getJavaClassDescriptor().getDefaultFunctionTypeForSamInterface();
} }
@NotNull @NotNull
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl; import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl;
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl; import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl;
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl; import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl;
import org.jetbrains.kotlin.load.java.components.SamConversionResolver;
import org.jetbrains.kotlin.load.java.descriptors.JavaClassConstructorDescriptor; import org.jetbrains.kotlin.load.java.descriptors.JavaClassConstructorDescriptor;
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor; import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor;
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor; import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor;
@@ -57,29 +58,41 @@ public class SingleAbstractMethodUtils {
} }
@Nullable @Nullable
public static KotlinType getFunctionTypeForSamType(@NotNull KotlinType samType) { public static SimpleType getFunctionTypeForSamInterface(
@NotNull JavaClassDescriptor clazz,
@Nullable SamConversionResolver samResolver
) {
if (samResolver == null) {
return clazz.getDefaultFunctionTypeForSamInterface();
}
return samResolver.resolveFunctionTypeIfSamInterface(clazz);
}
@Nullable
public static KotlinType getFunctionTypeForSamType(@NotNull KotlinType samType, @Nullable SamConversionResolver samResolver) {
UnwrappedType unwrappedType = samType.unwrap(); UnwrappedType unwrappedType = samType.unwrap();
if (unwrappedType instanceof FlexibleType) { if (unwrappedType instanceof FlexibleType) {
SimpleType lower = getFunctionTypeForSamType(((FlexibleType) unwrappedType).getLowerBound()); SimpleType lower = getFunctionTypeForSamType(((FlexibleType) unwrappedType).getLowerBound(), samResolver);
SimpleType upper = getFunctionTypeForSamType(((FlexibleType) unwrappedType).getUpperBound()); SimpleType upper = getFunctionTypeForSamType(((FlexibleType) unwrappedType).getUpperBound(), samResolver);
assert (lower == null) == (upper == null) : "Illegal flexible type: " + unwrappedType; assert (lower == null) == (upper == null) : "Illegal flexible type: " + unwrappedType;
if (upper == null) return null; if (upper == null) return null;
return KotlinTypeFactory.flexibleType(lower, upper); return KotlinTypeFactory.flexibleType(lower, upper);
} }
else { else {
return getFunctionTypeForSamType((SimpleType) unwrappedType); return getFunctionTypeForSamType((SimpleType) unwrappedType, samResolver);
} }
} }
@Nullable @Nullable
private static SimpleType getFunctionTypeForSamType(@NotNull SimpleType samType) { private static SimpleType getFunctionTypeForSamType(@NotNull SimpleType samType, @Nullable SamConversionResolver samResolver) {
// e.g. samType == Comparator<String>? // e.g. samType == Comparator<String>?
ClassifierDescriptor classifier = samType.getConstructor().getDeclarationDescriptor(); ClassifierDescriptor classifier = samType.getConstructor().getDeclarationDescriptor();
if (classifier instanceof JavaClassDescriptor) { if (classifier instanceof JavaClassDescriptor) {
// Function2<T, T, Int> // Function2<T, T, Int>
SimpleType functionTypeDefault = ((JavaClassDescriptor) classifier).getFunctionTypeForSamInterface(); SimpleType functionTypeDefault = getFunctionTypeForSamInterface((JavaClassDescriptor) classifier, samResolver);
if (functionTypeDefault != null) { if (functionTypeDefault != null) {
SimpleType noProjectionsSamType = SingleAbstractMethodUtilsKt.nonProjectionParametrization(samType); SimpleType noProjectionsSamType = SingleAbstractMethodUtilsKt.nonProjectionParametrization(samType);
@@ -157,7 +170,8 @@ public class SingleAbstractMethodUtils {
@NotNull @NotNull
public static SamConstructorDescriptor createSamConstructorFunction( public static SamConstructorDescriptor createSamConstructorFunction(
@NotNull DeclarationDescriptor owner, @NotNull DeclarationDescriptor owner,
@NotNull JavaClassDescriptor samInterface @NotNull JavaClassDescriptor samInterface,
@NotNull SamConversionResolver samResolver
) { ) {
assert getSingleAbstractMethodOrNull(samInterface) != null : samInterface; assert getSingleAbstractMethodOrNull(samInterface) != null : samInterface;
@@ -165,7 +179,7 @@ public class SingleAbstractMethodUtils {
List<TypeParameterDescriptor> samTypeParameters = samInterface.getTypeConstructor().getParameters(); List<TypeParameterDescriptor> samTypeParameters = samInterface.getTypeConstructor().getParameters();
SimpleType unsubstitutedSamType = samInterface.getDefaultType(); SimpleType unsubstitutedSamType = samInterface.getDefaultType();
initializeSamConstructorDescriptor(samInterface, result, samTypeParameters, unsubstitutedSamType); initializeSamConstructorDescriptor(samInterface, result, samTypeParameters, unsubstitutedSamType, samResolver);
return result; return result;
} }
@@ -174,11 +188,12 @@ public class SingleAbstractMethodUtils {
@NotNull JavaClassDescriptor samInterface, @NotNull JavaClassDescriptor samInterface,
@NotNull SimpleFunctionDescriptorImpl samConstructor, @NotNull SimpleFunctionDescriptorImpl samConstructor,
@NotNull List<TypeParameterDescriptor> samTypeParameters, @NotNull List<TypeParameterDescriptor> samTypeParameters,
@NotNull KotlinType unsubstitutedSamType @NotNull KotlinType unsubstitutedSamType,
@NotNull SamConversionResolver samResolver
) { ) {
TypeParameters typeParameters = recreateAndInitializeTypeParameters(samTypeParameters, samConstructor); TypeParameters typeParameters = recreateAndInitializeTypeParameters(samTypeParameters, samConstructor);
KotlinType parameterTypeUnsubstituted = getFunctionTypeForSamType(unsubstitutedSamType); KotlinType parameterTypeUnsubstituted = getFunctionTypeForSamType(unsubstitutedSamType, samResolver);
assert parameterTypeUnsubstituted != null : "couldn't get function type for SAM type " + unsubstitutedSamType; assert parameterTypeUnsubstituted != null : "couldn't get function type for SAM type " + unsubstitutedSamType;
KotlinType parameterType = typeParameters.substitutor.substitute(parameterTypeUnsubstituted, Variance.IN_VARIANCE); KotlinType parameterType = typeParameters.substitutor.substitute(parameterTypeUnsubstituted, Variance.IN_VARIANCE);
assert parameterType != null : "couldn't substitute type: " + parameterTypeUnsubstituted + assert parameterType != null : "couldn't substitute type: " + parameterTypeUnsubstituted +
@@ -207,20 +222,21 @@ public class SingleAbstractMethodUtils {
public static SamConstructorDescriptor createTypeAliasSamConstructorFunction( public static SamConstructorDescriptor createTypeAliasSamConstructorFunction(
@NotNull TypeAliasDescriptor typeAliasDescriptor, @NotNull TypeAliasDescriptor typeAliasDescriptor,
@NotNull SamConstructorDescriptor underlyingSamConstructor @NotNull SamConstructorDescriptor underlyingSamConstructor,
@NotNull SamConversionResolver samResolver
) { ) {
SamTypeAliasConstructorDescriptorImpl result = new SamTypeAliasConstructorDescriptorImpl(typeAliasDescriptor, underlyingSamConstructor); SamTypeAliasConstructorDescriptorImpl result = new SamTypeAliasConstructorDescriptorImpl(typeAliasDescriptor, underlyingSamConstructor);
JavaClassDescriptor samInterface = underlyingSamConstructor.getBaseDescriptorForSynthetic(); JavaClassDescriptor samInterface = underlyingSamConstructor.getBaseDescriptorForSynthetic();
List<TypeParameterDescriptor> samTypeParameters = typeAliasDescriptor.getTypeConstructor().getParameters(); List<TypeParameterDescriptor> samTypeParameters = typeAliasDescriptor.getTypeConstructor().getParameters();
SimpleType unsubstitutedSamType = typeAliasDescriptor.getExpandedType(); SimpleType unsubstitutedSamType = typeAliasDescriptor.getExpandedType();
initializeSamConstructorDescriptor(samInterface, result, samTypeParameters, unsubstitutedSamType); initializeSamConstructorDescriptor(samInterface, result, samTypeParameters, unsubstitutedSamType, samResolver);
return result; return result;
} }
public static boolean isSamType(@NotNull KotlinType type) { public static boolean isSamType(@NotNull KotlinType type) {
return getFunctionTypeForSamType(type) != null; return getFunctionTypeForSamType(type, null) != null;
} }
public static boolean isSamAdapterNecessary(@NotNull FunctionDescriptor fun) { public static boolean isSamAdapterNecessary(@NotNull FunctionDescriptor fun) {
@@ -233,7 +249,10 @@ public class SingleAbstractMethodUtils {
} }
@NotNull @NotNull
public static SamAdapterDescriptor<JavaMethodDescriptor> createSamAdapterFunction(@NotNull JavaMethodDescriptor original) { public static SamAdapterDescriptor<JavaMethodDescriptor> createSamAdapterFunction(
@NotNull JavaMethodDescriptor original,
@NotNull SamConversionResolver samResolver
) {
SamAdapterFunctionDescriptor result = new SamAdapterFunctionDescriptor(original); SamAdapterFunctionDescriptor result = new SamAdapterFunctionDescriptor(original);
return initSamAdapter(original, result, new FunctionInitializer() { return initSamAdapter(original, result, new FunctionInitializer() {
@Override @Override
@@ -252,11 +271,14 @@ public class SingleAbstractMethodUtils {
original.getVisibility() original.getVisibility()
); );
} }
}); }, samResolver);
} }
@NotNull @NotNull
public static SamAdapterDescriptor<JavaClassConstructorDescriptor> createSamAdapterConstructor(@NotNull JavaClassConstructorDescriptor original) { public static SamAdapterDescriptor<JavaClassConstructorDescriptor> createSamAdapterConstructor(
@NotNull JavaClassConstructorDescriptor original,
@NotNull SamConversionResolver samResolver
) {
SamAdapterClassConstructorDescriptor result = new SamAdapterClassConstructorDescriptor(original); SamAdapterClassConstructorDescriptor result = new SamAdapterClassConstructorDescriptor(original);
return initSamAdapter(original, result, new FunctionInitializer() { return initSamAdapter(original, result, new FunctionInitializer() {
@Override @Override
@@ -268,14 +290,15 @@ public class SingleAbstractMethodUtils {
result.initialize(valueParameters, original.getVisibility()); result.initialize(valueParameters, original.getVisibility());
result.setReturnType(returnType); result.setReturnType(returnType);
} }
}); }, samResolver);
} }
@NotNull @NotNull
private static <F extends FunctionDescriptor> SamAdapterDescriptor<F> initSamAdapter( private static <F extends FunctionDescriptor> SamAdapterDescriptor<F> initSamAdapter(
@NotNull F original, @NotNull F original,
@NotNull SamAdapterDescriptor<F> adapter, @NotNull SamAdapterDescriptor<F> adapter,
@NotNull FunctionInitializer initializer @NotNull FunctionInitializer initializer,
@NotNull SamConversionResolver samResolver
) { ) {
TypeParameters typeParameters = recreateAndInitializeTypeParameters(original.getTypeParameters(), adapter); TypeParameters typeParameters = recreateAndInitializeTypeParameters(original.getTypeParameters(), adapter);
@@ -288,7 +311,7 @@ public class SingleAbstractMethodUtils {
", substitutor = " + substitutor; ", substitutor = " + substitutor;
List<ValueParameterDescriptor> valueParameters = createValueParametersForSamAdapter(original, adapter, substitutor); List<ValueParameterDescriptor> valueParameters = createValueParametersForSamAdapter(original, adapter, substitutor, samResolver);
initializer.initialize(typeParameters.descriptors, valueParameters, returnType); initializer.initialize(typeParameters.descriptors, valueParameters, returnType);
@@ -298,13 +321,14 @@ public class SingleAbstractMethodUtils {
public static List<ValueParameterDescriptor> createValueParametersForSamAdapter( public static List<ValueParameterDescriptor> createValueParametersForSamAdapter(
@NotNull FunctionDescriptor original, @NotNull FunctionDescriptor original,
@NotNull FunctionDescriptor samAdapter, @NotNull FunctionDescriptor samAdapter,
@NotNull TypeSubstitutor substitutor @NotNull TypeSubstitutor substitutor,
@NotNull SamConversionResolver samResolver
) { ) {
List<ValueParameterDescriptor> originalValueParameters = original.getValueParameters(); List<ValueParameterDescriptor> originalValueParameters = original.getValueParameters();
List<ValueParameterDescriptor> valueParameters = new ArrayList<>(originalValueParameters.size()); List<ValueParameterDescriptor> valueParameters = new ArrayList<>(originalValueParameters.size());
for (ValueParameterDescriptor originalParam : originalValueParameters) { for (ValueParameterDescriptor originalParam : originalValueParameters) {
KotlinType originalType = originalParam.getType(); KotlinType originalType = originalParam.getType();
KotlinType functionType = getFunctionTypeForSamType(originalType); KotlinType functionType = getFunctionTypeForSamType(originalType, samResolver);
KotlinType newTypeUnsubstituted = functionType != null ? functionType : originalType; KotlinType newTypeUnsubstituted = functionType != null ? functionType : originalType;
KotlinType newType = substitutor.substitute(newTypeUnsubstituted, Variance.IN_VARIANCE); KotlinType newType = substitutor.substitute(newTypeUnsubstituted, Variance.IN_VARIANCE);
assert newType != null : "couldn't substitute type: " + newTypeUnsubstituted + ", substitutor = " + substitutor; assert newType != null : "couldn't substitute type: " + newTypeUnsubstituted + ", substitutor = " + substitutor;
@@ -18,16 +18,18 @@ package org.jetbrains.kotlin.synthetic
import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.incremental.components.LookupTracker 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.resolve.scopes.SyntheticScopes
import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.storage.StorageManager
class JavaSyntheticScopes( class JavaSyntheticScopes(
storageManager: StorageManager, storageManager: StorageManager,
lookupTracker: LookupTracker, lookupTracker: LookupTracker,
languageVersionSettings: LanguageVersionSettings languageVersionSettings: LanguageVersionSettings,
samConventionResolver: SamConversionResolver
): SyntheticScopes { ): SyntheticScopes {
override val scopes = listOf( override val scopes = listOf(
JavaSyntheticPropertiesScope(storageManager, lookupTracker), 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.impl.TypeAliasConstructorDescriptorImpl
import org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor import org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor
import org.jetbrains.kotlin.incremental.components.LookupLocation 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.JavaClassConstructorDescriptor
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
@@ -49,7 +50,8 @@ interface SamAdapterExtensionFunctionDescriptor : FunctionDescriptor, SyntheticM
class SamAdapterFunctionsScope( class SamAdapterFunctionsScope(
storageManager: StorageManager, storageManager: StorageManager,
private val languageVersionSettings: LanguageVersionSettings private val languageVersionSettings: LanguageVersionSettings,
private val samResolver: SamConversionResolver
) : SyntheticScope { ) : SyntheticScope {
private val extensionForFunction = storageManager.createMemoizedFunctionWithNullableValues<FunctionDescriptor, FunctionDescriptor> { function -> private val extensionForFunction = storageManager.createMemoizedFunctionWithNullableValues<FunctionDescriptor, FunctionDescriptor> { function ->
extensionForFunctionNotCached(function) extensionForFunctionNotCached(function)
@@ -57,17 +59,17 @@ class SamAdapterFunctionsScope(
private val samAdapterForStaticFunction = private val samAdapterForStaticFunction =
storageManager.createMemoizedFunction<JavaMethodDescriptor, SamAdapterDescriptor<JavaMethodDescriptor>> { function -> storageManager.createMemoizedFunction<JavaMethodDescriptor, SamAdapterDescriptor<JavaMethodDescriptor>> { function ->
SingleAbstractMethodUtils.createSamAdapterFunction(function) SingleAbstractMethodUtils.createSamAdapterFunction(function, samResolver)
} }
private val samConstructorForClassifier = private val samConstructorForClassifier =
storageManager.createMemoizedFunction<JavaClassDescriptor, SamConstructorDescriptor> { classifier -> storageManager.createMemoizedFunction<JavaClassDescriptor, SamConstructorDescriptor> { classifier ->
SingleAbstractMethodUtils.createSamConstructorFunction(classifier.containingDeclaration, classifier) SingleAbstractMethodUtils.createSamConstructorFunction(classifier.containingDeclaration, classifier, samResolver)
} }
private val samConstructorForJavaConstructor = private val samConstructorForJavaConstructor =
storageManager.createMemoizedFunction<JavaClassConstructorDescriptor, ClassConstructorDescriptor> { constructor -> storageManager.createMemoizedFunction<JavaClassConstructorDescriptor, ClassConstructorDescriptor> { constructor ->
SingleAbstractMethodUtils.createSamAdapterConstructor(constructor) as ClassConstructorDescriptor SingleAbstractMethodUtils.createSamAdapterConstructor(constructor, samResolver) as ClassConstructorDescriptor
} }
private val samConstructorForTypeAliasConstructor = private val samConstructorForTypeAliasConstructor =
@@ -82,7 +84,7 @@ class SamAdapterFunctionsScope(
if (!SingleAbstractMethodUtils.isSamAdapterNecessary(function)) return null if (!SingleAbstractMethodUtils.isSamAdapterNecessary(function)) return null
if (function.returnType == null) return null if (function.returnType == null) return null
if (function.isHiddenInResolution(languageVersionSettings)) 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> { override fun getSyntheticMemberFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
@@ -199,15 +201,16 @@ class SamAdapterFunctionsScope(
return getTypeAliasSamConstructor(classifier) return getTypeAliasSamConstructor(classifier)
} }
if (classifier !is LazyJavaClassDescriptor || classifier.functionTypeForSamInterface == null) return null if (classifier !is LazyJavaClassDescriptor || classifier.defaultFunctionTypeForSamInterface == null) return null
return samConstructorForClassifier(classifier) return samConstructorForClassifier(classifier)
} }
private fun getTypeAliasSamConstructor(classifier: TypeAliasDescriptor): SamConstructorDescriptor? { private fun getTypeAliasSamConstructor(classifier: TypeAliasDescriptor): SamConstructorDescriptor? {
val classDescriptor = classifier.classDescriptor ?: return null 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( private class MyFunctionDescriptor(
@@ -227,7 +230,7 @@ class SamAdapterFunctionsScope(
} }
companion object { companion object {
fun create(sourceFunction: FunctionDescriptor): MyFunctionDescriptor { fun create(sourceFunction: FunctionDescriptor, samResolver: SamConversionResolver): MyFunctionDescriptor {
val descriptor = MyFunctionDescriptor(sourceFunction.containingDeclaration, val descriptor = MyFunctionDescriptor(sourceFunction.containingDeclaration,
null, null,
sourceFunction.annotations, sourceFunction.annotations,
@@ -243,7 +246,8 @@ class SamAdapterFunctionsScope(
val typeSubstitutor = DescriptorSubstitutor.substituteTypeParameters(sourceTypeParams, TypeSubstitution.EMPTY, descriptor, typeParameters) val typeSubstitutor = DescriptorSubstitutor.substituteTypeParameters(sourceTypeParams, TypeSubstitution.EMPTY, descriptor, typeParameters)
val returnType = typeSubstitutor.safeSubstitute(sourceFunction.returnType!!, Variance.INVARIANT) 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) val visibility = syntheticVisibility(sourceFunction, isUsedForExtension = false)
@@ -21,8 +21,9 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor;
import org.jetbrains.kotlin.types.SimpleType; import org.jetbrains.kotlin.types.SimpleType;
public interface JavaClassDescriptor extends ClassDescriptor { public interface JavaClassDescriptor extends ClassDescriptor {
// Use SingleAbstractMethodUtils.getFunctionTypeForSamInterface() where possible. This is only a fallback
@Nullable @Nullable
SimpleType getFunctionTypeForSamInterface(); SimpleType getDefaultFunctionTypeForSamInterface();
/** /**
* May return false even in case when the class is not SAM interface, but returns true only if it's definitely not a SAM. * May return false even in case when the class is not SAM interface, but returns true only if it's definitely not a SAM.
@@ -135,7 +135,7 @@ class LazyJavaClassDescriptor(
override fun getDeclaredTypeParameters() = declaredParameters() override fun getDeclaredTypeParameters() = declaredParameters()
override fun getFunctionTypeForSamInterface(): SimpleType? = c.components.samConversionResolver.resolveFunctionTypeIfSamInterface(this) override fun getDefaultFunctionTypeForSamInterface(): SimpleType? = c.components.samConversionResolver.resolveFunctionTypeIfSamInterface(this)
override fun isDefinitelyNotSamInterface(): Boolean { override fun isDefinitelyNotSamInterface(): Boolean {
if (kind != ClassKind.INTERFACE) return true if (kind != ClassKind.INTERFACE) return true
@@ -232,10 +232,7 @@ class RedundantSamConstructorInspection : AbstractKotlinInspection() {
val samAdapterOriginalFunction = SamCodegenUtil.getOriginalIfSamAdapter(samAdapter)?.original val samAdapterOriginalFunction = SamCodegenUtil.getOriginalIfSamAdapter(samAdapter)?.original
if (samAdapterOriginalFunction != originalFunction) return false if (samAdapterOriginalFunction != originalFunction) return false
val parametersWithSamTypeCount = originalFunction.valueParameters.count { val parametersWithSamTypeCount = originalFunction.valueParameters.count { SingleAbstractMethodUtils.isSamType(it.type) }
SingleAbstractMethodUtils.getFunctionTypeForSamType(it.type) != null
}
return parametersWithSamTypeCount == samConstructorsCount return parametersWithSamTypeCount == samConstructorsCount
} }
@@ -399,7 +399,7 @@ class KotlinChangeSignatureUsageProcessor : ChangeSignatureUsageProcessor {
if (method.containingClass == null) return if (method.containingClass == null) return
val containingDescriptor = method.getJavaMethodDescriptor()?.containingDeclaration as? JavaClassDescriptor ?: return val containingDescriptor = method.getJavaMethodDescriptor()?.containingDeclaration as? JavaClassDescriptor ?: return
if (containingDescriptor.functionTypeForSamInterface == null) return if (containingDescriptor.defaultFunctionTypeForSamInterface == null) return
val samClass = method.containingClass ?: return val samClass = method.containingClass ?: return
for (ref in ReferencesSearch.search(samClass)) { for (ref in ReferencesSearch.search(samClass)) {