Refactoring: make parameters of getFunctionTypeForSamType not null
This commit is contained in:
+4
-16
@@ -58,19 +58,7 @@ public class SingleAbstractMethodUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static SimpleType getFunctionTypeForSamInterface(
|
public static KotlinType getFunctionTypeForSamType(@NotNull KotlinType samType, @NotNull SamConversionResolver samResolver) {
|
||||||
@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(), samResolver);
|
SimpleType lower = getFunctionTypeForSamType(((FlexibleType) unwrappedType).getLowerBound(), samResolver);
|
||||||
@@ -86,13 +74,13 @@ public class SingleAbstractMethodUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static SimpleType getFunctionTypeForSamType(@NotNull SimpleType samType, @Nullable SamConversionResolver samResolver) {
|
private static SimpleType getFunctionTypeForSamType(@NotNull SimpleType samType, @NotNull 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 = getFunctionTypeForSamInterface((JavaClassDescriptor) classifier, samResolver);
|
SimpleType functionTypeDefault = samResolver.resolveFunctionTypeIfSamInterface((JavaClassDescriptor) classifier);
|
||||||
|
|
||||||
if (functionTypeDefault != null) {
|
if (functionTypeDefault != null) {
|
||||||
SimpleType noProjectionsSamType = SingleAbstractMethodUtilsKt.nonProjectionParametrization(samType);
|
SimpleType noProjectionsSamType = SingleAbstractMethodUtilsKt.nonProjectionParametrization(samType);
|
||||||
@@ -236,7 +224,7 @@ public class SingleAbstractMethodUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSamType(@NotNull KotlinType type) {
|
public static boolean isSamType(@NotNull KotlinType type) {
|
||||||
return getFunctionTypeForSamType(type, null) != null;
|
return getFunctionTypeForSamType(type, SamConversionResolver.JavaBasedSamConversionResolver.INSTANCE) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSamAdapterNecessary(@NotNull FunctionDescriptor fun) {
|
public static boolean isSamAdapterNecessary(@NotNull FunctionDescriptor fun) {
|
||||||
|
|||||||
+6
-1
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.kotlin.load.java.components
|
package org.jetbrains.kotlin.load.java.components
|
||||||
|
|
||||||
import org.jetbrains.kotlin.container.DefaultImplementation
|
import org.jetbrains.kotlin.container.DefaultImplementation
|
||||||
import org.jetbrains.kotlin.container.PlatformExtensionsClashResolver
|
|
||||||
import org.jetbrains.kotlin.container.PlatformSpecificExtension
|
import org.jetbrains.kotlin.container.PlatformSpecificExtension
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
|
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
|
||||||
import org.jetbrains.kotlin.types.SimpleType
|
import org.jetbrains.kotlin.types.SimpleType
|
||||||
@@ -28,5 +27,11 @@ interface SamConversionResolver : PlatformSpecificExtension<SamConversionResolve
|
|||||||
override fun resolveFunctionTypeIfSamInterface(classDescriptor: JavaClassDescriptor): SimpleType? = null
|
override fun resolveFunctionTypeIfSamInterface(classDescriptor: JavaClassDescriptor): SimpleType? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object JavaBasedSamConversionResolver : SamConversionResolver {
|
||||||
|
override fun resolveFunctionTypeIfSamInterface(classDescriptor: JavaClassDescriptor): SimpleType? {
|
||||||
|
return classDescriptor.defaultFunctionTypeForSamInterface
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun resolveFunctionTypeIfSamInterface(classDescriptor: JavaClassDescriptor): SimpleType?
|
fun resolveFunctionTypeIfSamInterface(classDescriptor: JavaClassDescriptor): SimpleType?
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user