Kapt3: Fix '$' in function generic signatures (KT-15148)
This commit is contained in:
committed by
Yan Zhulanow
parent
d726d0de88
commit
3f8accc2bf
@@ -311,7 +311,7 @@ public class KotlinTypeMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static String getPackageMemberOwnerInternalName(@NotNull DeserializedCallableMemberDescriptor descriptor, boolean publicFacade) {
|
private String getPackageMemberOwnerInternalName(@NotNull DeserializedCallableMemberDescriptor descriptor, boolean publicFacade) {
|
||||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||||
assert containingDeclaration instanceof PackageFragmentDescriptor : "Not a top-level member: " + descriptor;
|
assert containingDeclaration instanceof PackageFragmentDescriptor : "Not a top-level member: " + descriptor;
|
||||||
|
|
||||||
@@ -322,7 +322,7 @@ public class KotlinTypeMapper {
|
|||||||
|
|
||||||
ClassId ownerClassId = publicFacade ? containingClasses.getFacadeClassId()
|
ClassId ownerClassId = publicFacade ? containingClasses.getFacadeClassId()
|
||||||
: containingClasses.getImplClassId();
|
: containingClasses.getImplClassId();
|
||||||
return JvmClassName.byClassId(ownerClassId).getInternalName();
|
return JvmClassName.byClassId(ownerClassId, typeMappingConfiguration).getInternalName();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final ClassId FAKE_CLASS_ID_FOR_BUILTINS = ClassId.topLevel(new FqName("kotlin.KotlinPackage"));
|
private static final ClassId FAKE_CLASS_ID_FOR_BUILTINS = ClassId.topLevel(new FqName("kotlin.KotlinPackage"));
|
||||||
|
|||||||
+4
-3
@@ -64,7 +64,7 @@ fun <T : Any> mapType(
|
|||||||
descriptorTypeWriter: JvmDescriptorTypeWriter<T>?,
|
descriptorTypeWriter: JvmDescriptorTypeWriter<T>?,
|
||||||
writeGenericType: (KotlinType, T, TypeMappingMode) -> Unit = DO_NOTHING_3
|
writeGenericType: (KotlinType, T, TypeMappingMode) -> Unit = DO_NOTHING_3
|
||||||
): T {
|
): T {
|
||||||
mapBuiltInType(kotlinType, factory)?.let { builtInType ->
|
mapBuiltInType(kotlinType, factory, typeMappingConfiguration)?.let { builtInType ->
|
||||||
val jvmType = factory.boxTypeIfNeeded(builtInType, mode.needPrimitiveBoxing)
|
val jvmType = factory.boxTypeIfNeeded(builtInType, mode.needPrimitiveBoxing)
|
||||||
writeGenericType(kotlinType, jvmType, mode)
|
writeGenericType(kotlinType, jvmType, mode)
|
||||||
return jvmType
|
return jvmType
|
||||||
@@ -160,7 +160,8 @@ fun hasVoidReturnType(descriptor: CallableDescriptor): Boolean {
|
|||||||
|
|
||||||
private fun <T : Any> mapBuiltInType(
|
private fun <T : Any> mapBuiltInType(
|
||||||
type: KotlinType,
|
type: KotlinType,
|
||||||
typeFactory: JvmTypeFactory<T>
|
typeFactory: JvmTypeFactory<T>,
|
||||||
|
typeMappingConfiguration: TypeMappingConfiguration<T>
|
||||||
): T? {
|
): T? {
|
||||||
val descriptor = type.constructor.declarationDescriptor as? ClassDescriptor ?: return null
|
val descriptor = type.constructor.declarationDescriptor as? ClassDescriptor ?: return null
|
||||||
|
|
||||||
@@ -180,7 +181,7 @@ private fun <T : Any> mapBuiltInType(
|
|||||||
|
|
||||||
val classId = JavaToKotlinClassMap.INSTANCE.mapKotlinToJava(fqName)
|
val classId = JavaToKotlinClassMap.INSTANCE.mapKotlinToJava(fqName)
|
||||||
if (classId != null) {
|
if (classId != null) {
|
||||||
return typeFactory.createObjectType(JvmClassName.byClassId(classId).internalName)
|
return typeFactory.createObjectType(JvmClassName.byClassId(classId, typeMappingConfiguration).internalName)
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
return null
|
||||||
|
|||||||
@@ -16,10 +16,15 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.jvm;
|
package org.jetbrains.kotlin.resolve.jvm;
|
||||||
|
|
||||||
|
import kotlin.jvm.functions.Function2;
|
||||||
import org.jetbrains.annotations.NotNull;
|
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.ClassId;
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class JvmClassName {
|
public class JvmClassName {
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JvmClassName byInternalName(@NotNull String internalName) {
|
public static JvmClassName byInternalName(@NotNull String internalName) {
|
||||||
@@ -28,8 +33,31 @@ public class JvmClassName {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JvmClassName byClassId(@NotNull ClassId classId) {
|
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();
|
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()
|
return packageFqName.isRoot()
|
||||||
? new JvmClassName(relativeClassName)
|
? new JvmClassName(relativeClassName)
|
||||||
: new JvmClassName(packageFqName.asString().replace('.', '/') + "/" + relativeClassName);
|
: new JvmClassName(packageFqName.asString().replace('.', '/') + "/" + relativeClassName);
|
||||||
|
|||||||
+6
@@ -138,6 +138,12 @@ public class ClassFileToSourceStubConverterTestGenerated extends AbstractClassFi
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("mapEntry.kt")
|
||||||
|
public void testMapEntry() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("plugins/kapt3/testData/converter/mapEntry.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("methodPropertySignatureClash.kt")
|
@TestMetadata("methodPropertySignatureClash.kt")
|
||||||
public void testMethodPropertySignatureClash() throws Exception {
|
public void testMethodPropertySignatureClash() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("plugins/kapt3/testData/converter/methodPropertySignatureClash.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("plugins/kapt3/testData/converter/methodPropertySignatureClash.kt");
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
interface EntryHolder {
|
||||||
|
fun entry(p: Map.Entry<CharSequence, Map.Entry<String, Int>>): Map.Entry<String, Any>
|
||||||
|
val entryProperty: Map.Entry<String, Any>
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
public abstract interface EntryHolder {
|
||||||
|
|
||||||
|
public abstract java.util.Map.Entry<java.lang.String, java.lang.Object> entry(java.util.Map.Entry<? extends java.lang.CharSequence, ? extends java.util.Map.Entry<java.lang.String, java.lang.Integer>> p);
|
||||||
|
|
||||||
|
public abstract java.util.Map.Entry<java.lang.String, java.lang.Object> getEntryProperty();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user