From f8564558412b1bd6df0708ee111c56230f2e3fea Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Mon, 5 Feb 2018 02:41:17 +0300 Subject: [PATCH] Introduce stateless methods to map types without predefined mapping --- .../codegen/state/KotlinTypeMapper.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java index 866f3a5d662..800372b54ff 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java @@ -113,6 +113,31 @@ public class KotlinTypeMapper { } }; + private static final TypeMappingConfiguration staticTypeMappingConfiguration = new TypeMappingConfiguration() { + @NotNull + @Override + public KotlinType commonSupertype(@NotNull Collection types) { + return CommonSupertypes.commonSupertype(types); + } + + @Nullable + @Override + public Type getPredefinedTypeForClass(@NotNull ClassDescriptor classDescriptor) { + return null; + } + + @Nullable + @Override + public String getPredefinedInternalNameForClass(@NotNull ClassDescriptor classDescriptor) { + return null; + } + + @Override + public void processErrorType(@NotNull KotlinType kotlinType, @NotNull ClassDescriptor descriptor) { + throw new IllegalStateException(generateErrorMessageForErrorType(kotlinType, descriptor)); + } + }; + public KotlinTypeMapper( @NotNull BindingContext bindingContext, @NotNull ClassBuilderMode classBuilderMode, @@ -446,6 +471,20 @@ public class KotlinTypeMapper { ); } + public static Type mapInlineClassTypeAsDeclaration(@NotNull KotlinType kotlinType) { + return mapInlineClassType(kotlinType, TypeMappingMode.CLASS_DECLARATION); + } + + public static Type mapInlineClassType( + @NotNull KotlinType kotlinType, + @NotNull TypeMappingMode mode + ) { + return TypeSignatureMappingKt.mapType( + kotlinType, AsmTypeFactory.INSTANCE, mode, staticTypeMappingConfiguration, null, + (ktType, asmType, typeMappingMode) -> Unit.INSTANCE + ); + } + @NotNull public Type mapDefaultImpls(@NotNull ClassDescriptor descriptor) { return Type.getObjectType(mapType(descriptor).getInternalName() + JvmAbi.DEFAULT_IMPLS_SUFFIX);