Kapt3: Fix '$' in function generic signatures (KT-15148)
This commit is contained in:
committed by
Yan Zhulanow
parent
d726d0de88
commit
3f8accc2bf
+4
-3
@@ -64,7 +64,7 @@ fun <T : Any> mapType(
|
||||
descriptorTypeWriter: JvmDescriptorTypeWriter<T>?,
|
||||
writeGenericType: (KotlinType, T, TypeMappingMode) -> Unit = DO_NOTHING_3
|
||||
): T {
|
||||
mapBuiltInType(kotlinType, factory)?.let { builtInType ->
|
||||
mapBuiltInType(kotlinType, factory, typeMappingConfiguration)?.let { builtInType ->
|
||||
val jvmType = factory.boxTypeIfNeeded(builtInType, mode.needPrimitiveBoxing)
|
||||
writeGenericType(kotlinType, jvmType, mode)
|
||||
return jvmType
|
||||
@@ -160,7 +160,8 @@ fun hasVoidReturnType(descriptor: CallableDescriptor): Boolean {
|
||||
|
||||
private fun <T : Any> mapBuiltInType(
|
||||
type: KotlinType,
|
||||
typeFactory: JvmTypeFactory<T>
|
||||
typeFactory: JvmTypeFactory<T>,
|
||||
typeMappingConfiguration: TypeMappingConfiguration<T>
|
||||
): T? {
|
||||
val descriptor = type.constructor.declarationDescriptor as? ClassDescriptor ?: return null
|
||||
|
||||
@@ -180,7 +181,7 @@ private fun <T : Any> mapBuiltInType(
|
||||
|
||||
val classId = JavaToKotlinClassMap.INSTANCE.mapKotlinToJava(fqName)
|
||||
if (classId != null) {
|
||||
return typeFactory.createObjectType(JvmClassName.byClassId(classId).internalName)
|
||||
return typeFactory.createObjectType(JvmClassName.byClassId(classId, typeMappingConfiguration).internalName)
|
||||
}
|
||||
|
||||
return null
|
||||
|
||||
@@ -16,10 +16,15 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.jvm;
|
||||
|
||||
import kotlin.jvm.functions.Function2;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.load.kotlin.TypeMappingConfiguration;
|
||||
import org.jetbrains.kotlin.name.ClassId;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class JvmClassName {
|
||||
@NotNull
|
||||
public static JvmClassName byInternalName(@NotNull String internalName) {
|
||||
@@ -28,8 +33,31 @@ public class JvmClassName {
|
||||
|
||||
@NotNull
|
||||
public static JvmClassName byClassId(@NotNull ClassId classId) {
|
||||
return byClassId(classId, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JvmClassName byClassId(@NotNull ClassId classId, @Nullable TypeMappingConfiguration<?> typeMappingConfiguration) {
|
||||
FqName packageFqName = classId.getPackageFqName();
|
||||
String relativeClassName = classId.getRelativeClassName().asString().replace('.', '$');
|
||||
|
||||
String[] relativeClassNameSegments = classId.getRelativeClassName().asString().split(Pattern.quote("."));
|
||||
String relativeClassName;
|
||||
|
||||
if (relativeClassNameSegments.length == 1) {
|
||||
relativeClassName = relativeClassNameSegments[0];
|
||||
}
|
||||
else if (relativeClassNameSegments.length > 1 && typeMappingConfiguration != null) {
|
||||
Function2<String, String, String> innerClassNameFactory = typeMappingConfiguration.getInnerClassNameFactory();
|
||||
relativeClassName = innerClassNameFactory.invoke(relativeClassNameSegments[0], relativeClassNameSegments[1]);
|
||||
for (int i = 2; i < relativeClassNameSegments.length; ++i) {
|
||||
relativeClassName = innerClassNameFactory.invoke(relativeClassName, relativeClassNameSegments[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Default behavior if we don't have an inner class name factory
|
||||
relativeClassName = classId.getRelativeClassName().asString().replace('.', '$');
|
||||
}
|
||||
|
||||
return packageFqName.isRoot()
|
||||
? new JvmClassName(relativeClassName)
|
||||
: new JvmClassName(packageFqName.asString().replace('.', '/') + "/" + relativeClassName);
|
||||
|
||||
Reference in New Issue
Block a user