FIC: Add synthetic constructors for fun interfaces aka explicit FIC
This commit is contained in:
+4
-4
@@ -17,18 +17,18 @@
|
||||
package org.jetbrains.kotlin.load.java.sam
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude
|
||||
|
||||
interface SamConstructorDescriptor : SimpleFunctionDescriptor, SyntheticMemberDescriptor<JavaClassDescriptor>
|
||||
interface SamConstructorDescriptor : SimpleFunctionDescriptor, SyntheticMemberDescriptor<ClassDescriptor>
|
||||
|
||||
class SamConstructorDescriptorImpl(
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
private val samInterface: JavaClassDescriptor
|
||||
private val samInterface: ClassDescriptor
|
||||
) : SimpleFunctionDescriptorImpl(
|
||||
containingDeclaration,
|
||||
null,
|
||||
@@ -37,7 +37,7 @@ class SamConstructorDescriptorImpl(
|
||||
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
||||
samInterface.source
|
||||
), SamConstructorDescriptor {
|
||||
override val baseDescriptorForSynthetic: JavaClassDescriptor
|
||||
override val baseDescriptorForSynthetic: ClassDescriptor
|
||||
get() = samInterface
|
||||
}
|
||||
|
||||
|
||||
+2
-6
@@ -16,12 +16,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.java.sam
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithNavigationSubstitute
|
||||
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
|
||||
|
||||
interface SamTypeAliasConstructorDescriptor : SamConstructorDescriptor, DeclarationDescriptorWithNavigationSubstitute {
|
||||
val typeAliasDescriptor: TypeAliasDescriptor
|
||||
@@ -41,6 +37,6 @@ class SamTypeAliasConstructorDescriptorImpl(
|
||||
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
||||
typeAliasDescriptor.source
|
||||
), SamTypeAliasConstructorDescriptor {
|
||||
override val baseDescriptorForSynthetic: JavaClassDescriptor
|
||||
override val baseDescriptorForSynthetic: ClassDescriptor
|
||||
get() = samInterfaceConstructorDescriptor.baseDescriptorForSynthetic
|
||||
}
|
||||
|
||||
+13
-3
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.resolve.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;
|
||||
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaClassDescriptor;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.name.SpecialNames;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
@@ -167,7 +168,7 @@ public class SingleAbstractMethodUtils {
|
||||
@NotNull
|
||||
public static SamConstructorDescriptor createSamConstructorFunction(
|
||||
@NotNull DeclarationDescriptor owner,
|
||||
@NotNull JavaClassDescriptor samInterface,
|
||||
@NotNull ClassDescriptor samInterface,
|
||||
@NotNull SamConversionResolver samResolver
|
||||
) {
|
||||
assert getSingleAbstractMethodOrNull(samInterface) != null : samInterface;
|
||||
@@ -182,7 +183,7 @@ public class SingleAbstractMethodUtils {
|
||||
}
|
||||
|
||||
private static void initializeSamConstructorDescriptor(
|
||||
@NotNull JavaClassDescriptor samInterface,
|
||||
@NotNull ClassDescriptor samInterface,
|
||||
@NotNull SimpleFunctionDescriptorImpl samConstructor,
|
||||
@NotNull List<TypeParameterDescriptor> samTypeParameters,
|
||||
@NotNull KotlinType unsubstitutedSamType,
|
||||
@@ -224,7 +225,7 @@ public class SingleAbstractMethodUtils {
|
||||
) {
|
||||
SamTypeAliasConstructorDescriptorImpl result = new SamTypeAliasConstructorDescriptorImpl(typeAliasDescriptor, underlyingSamConstructor);
|
||||
|
||||
JavaClassDescriptor samInterface = underlyingSamConstructor.getBaseDescriptorForSynthetic();
|
||||
ClassDescriptor samInterface = underlyingSamConstructor.getBaseDescriptorForSynthetic();
|
||||
List<TypeParameterDescriptor> samTypeParameters = typeAliasDescriptor.getTypeConstructor().getParameters();
|
||||
SimpleType unsubstitutedSamType = typeAliasDescriptor.getExpandedType();
|
||||
initializeSamConstructorDescriptor(samInterface, result, samTypeParameters, unsubstitutedSamType, samResolver);
|
||||
@@ -232,6 +233,15 @@ public class SingleAbstractMethodUtils {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isSamClassDescriptor(@NotNull ClassDescriptor descriptor) {
|
||||
if (descriptor.isFun()) return true;
|
||||
if (descriptor instanceof LazyJavaClassDescriptor &&
|
||||
((LazyJavaClassDescriptor) descriptor).getDefaultFunctionTypeForSamInterface() != null
|
||||
) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isSamType(@NotNull KotlinType type) {
|
||||
ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
|
||||
if (descriptor instanceof ClassDescriptor && ((ClassDescriptor) descriptor).isFun()) return true;
|
||||
|
||||
+5
-4
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.resolve.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
|
||||
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaClassDescriptor
|
||||
import org.jetbrains.kotlin.load.java.sam.SamAdapterDescriptor
|
||||
import org.jetbrains.kotlin.load.java.sam.SamConstructorDescriptor
|
||||
import org.jetbrains.kotlin.load.java.sam.SingleAbstractMethodUtils
|
||||
@@ -73,7 +72,7 @@ class SamAdapterFunctionsScope(
|
||||
}
|
||||
|
||||
private val samConstructorForClassifier =
|
||||
storageManager.createMemoizedFunction<JavaClassDescriptor, SamConstructorDescriptor> { classifier ->
|
||||
storageManager.createMemoizedFunction<ClassDescriptor, SamConstructorDescriptor> { classifier ->
|
||||
SingleAbstractMethodUtils.createSamConstructorFunction(classifier.containingDeclaration, classifier, samResolver)
|
||||
}
|
||||
|
||||
@@ -259,13 +258,15 @@ class SamAdapterFunctionsScope(
|
||||
return getTypeAliasSamConstructor(classifier)
|
||||
}
|
||||
|
||||
if (classifier !is LazyJavaClassDescriptor || classifier.defaultFunctionTypeForSamInterface == null) return null
|
||||
if (classifier !is ClassDescriptor) return null
|
||||
if (!SingleAbstractMethodUtils.isSamClassDescriptor(classifier)) return null
|
||||
|
||||
return samConstructorForClassifier(classifier)
|
||||
}
|
||||
|
||||
private fun getTypeAliasSamConstructor(classifier: TypeAliasDescriptor): SamConstructorDescriptor? {
|
||||
val classDescriptor = classifier.classDescriptor ?: return null
|
||||
if (classDescriptor !is LazyJavaClassDescriptor || classDescriptor.defaultFunctionTypeForSamInterface == null) return null
|
||||
if (!SingleAbstractMethodUtils.isSamClassDescriptor(classDescriptor)) return null
|
||||
|
||||
return SingleAbstractMethodUtils.createTypeAliasSamConstructorFunction(
|
||||
classifier, samConstructorForClassifier(classDescriptor), samResolver)
|
||||
|
||||
Reference in New Issue
Block a user