Introduce stateless methods to map types without predefined mapping

This commit is contained in:
Mikhail Zarechenskiy
2018-02-05 02:41:17 +03:00
parent 1cdad65b9b
commit f856455841
@@ -113,6 +113,31 @@ public class KotlinTypeMapper {
}
};
private static final TypeMappingConfiguration<Type> staticTypeMappingConfiguration = new TypeMappingConfiguration<Type>() {
@NotNull
@Override
public KotlinType commonSupertype(@NotNull Collection<KotlinType> 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);