write kotlin signature for ambiguous mapped types e.g. jet.List/MutableList for java.util.List

This commit is contained in:
Svetlana Isakova
2012-09-18 18:36:42 +04:00
parent bfa6cc2f0a
commit d721287db6
2 changed files with 30 additions and 12 deletions
@@ -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));
}
@@ -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) {