diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/signature/BothSignatureWriter.java b/compiler/backend/src/org/jetbrains/jet/codegen/signature/BothSignatureWriter.java index f6bb057ba5a..b8e2bc6edc0 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/signature/BothSignatureWriter.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/signature/BothSignatureWriter.java @@ -152,19 +152,22 @@ public class BothSignatureWriter { state = to; } + public void writeAsmType(Type asmType, boolean nullable) { + writeAsmType(asmType, nullable, null); + } /** * Shortcut */ - public void writeAsmType(Type asmType, boolean nullable) { + public void writeAsmType(Type asmType, boolean nullable, @Nullable String kotlinTypeName) { switch (asmType.getSort()) { case Type.OBJECT: - writeClassBegin(asmType.getInternalName(), nullable, false); + writeClassBegin(asmType.getInternalName(), nullable, false, kotlinTypeName); writeClassEnd(); return; case Type.ARRAY: writeArrayType(nullable); - writeAsmType(asmType.getElementType(), false); + writeAsmType(asmType.getElementType(), false, kotlinTypeName); writeArrayEnd(); return; default: @@ -218,8 +221,12 @@ public class BothSignatureWriter { } public void writeClassBegin(String internalName, boolean nullable, boolean real) { + writeClassBegin(internalName, nullable, real, null); + } + + public void writeClassBegin(String internalName, boolean nullable, boolean real, @Nullable String kotlinTypeName) { signatureVisitor().visitClassType(internalName); - jetSignatureWriter.visitClassType(internalName, nullable, real); + jetSignatureWriter.visitClassType(kotlinTypeName == null ? internalName : kotlinTypeName, nullable, real); writeAsmType0(Type.getObjectType(internalName)); } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java b/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java index 1e4c61148fb..8720b44a3f1 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java @@ -262,7 +262,7 @@ public class JetTypeMapper extends BindingTraceAware { } Type asmType = Type.getObjectType("error/NonExistentClass"); if (signatureVisitor != null) { - writeSimpleType(signatureVisitor, asmType, true); + signatureVisitor.writeAsmType(asmType, true); } checkValidType(asmType); return asmType; @@ -302,7 +302,7 @@ public class JetTypeMapper extends BindingTraceAware { } boolean forceReal = KotlinToJavaTypesMap.getInstance().isForceReal(name); - writeGenericType(jetType, signatureVisitor, asmType, forceReal); + writeGenericType(signatureVisitor, asmType, jetType, forceReal); checkValidType(asmType); return asmType; @@ -339,9 +339,10 @@ public class JetTypeMapper extends BindingTraceAware { parentDeclarationElement != null ? parentDeclarationElement.getText() : "null"); } - private void writeGenericType(JetType jetType, BothSignatureWriter signatureVisitor, Type asmType, boolean forceReal) { + private void writeGenericType(BothSignatureWriter signatureVisitor, Type asmType, JetType jetType, boolean forceReal) { if (signatureVisitor != null) { - signatureVisitor.writeClassBegin(asmType.getInternalName(), jetType.isNullable(), forceReal); + String kotlinTypeName = getKotlinTypeNameForSignature(jetType, asmType); + signatureVisitor.writeClassBegin(asmType.getInternalName(), jetType.isNullable(), forceReal, kotlinTypeName); for (TypeProjection proj : jetType.getArguments()) { // TODO: +- signatureVisitor.writeTypeArgument(proj.getProjectionKind()); @@ -355,18 +356,28 @@ public class JetTypeMapper extends BindingTraceAware { private Type mapKnownAsmType(JetType jetType, Type asmType, @Nullable BothSignatureWriter signatureVisitor) { if (signatureVisitor != null) { if (jetType.getArguments().isEmpty()) { - writeSimpleType(signatureVisitor, asmType, jetType.isNullable()); + String kotlinTypeName = getKotlinTypeNameForSignature(jetType, asmType); + signatureVisitor.writeAsmType(asmType, jetType.isNullable(), kotlinTypeName); } else { - writeGenericType(jetType, signatureVisitor, asmType, false); + writeGenericType(signatureVisitor, asmType, jetType, false); } } checkValidType(asmType); return asmType; } - private static void writeSimpleType(BothSignatureWriter visitor, Type asmType, boolean nullable) { - visitor.writeAsmType(asmType, nullable); + @Nullable + private static String getKotlinTypeNameForSignature(@NotNull JetType jetType, @NotNull Type asmType) { + ClassifierDescriptor descriptor = jetType.getConstructor().getDeclarationDescriptor(); + if (descriptor == null) return null; + if (asmType.getSort() != Type.OBJECT) return null; + + JvmClassName jvmClassName = JvmClassName.byType(asmType); + if (JavaToKotlinClassMap.getInstance().mapPlatformClass(jvmClassName.getFqName()).size() > 1) { + return JvmClassName.byClassDescriptor(descriptor).getInternalName(); + } + return null; } private void checkValidType(@NotNull Type type) {