write kotlin signature for ambiguous mapped types e.g. jet.List/MutableList for java.util.List
This commit is contained in:
@@ -152,19 +152,22 @@ public class BothSignatureWriter {
|
|||||||
state = to;
|
state = to;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void writeAsmType(Type asmType, boolean nullable) {
|
||||||
|
writeAsmType(asmType, nullable, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shortcut
|
* Shortcut
|
||||||
*/
|
*/
|
||||||
public void writeAsmType(Type asmType, boolean nullable) {
|
public void writeAsmType(Type asmType, boolean nullable, @Nullable String kotlinTypeName) {
|
||||||
switch (asmType.getSort()) {
|
switch (asmType.getSort()) {
|
||||||
case Type.OBJECT:
|
case Type.OBJECT:
|
||||||
writeClassBegin(asmType.getInternalName(), nullable, false);
|
writeClassBegin(asmType.getInternalName(), nullable, false, kotlinTypeName);
|
||||||
writeClassEnd();
|
writeClassEnd();
|
||||||
return;
|
return;
|
||||||
case Type.ARRAY:
|
case Type.ARRAY:
|
||||||
writeArrayType(nullable);
|
writeArrayType(nullable);
|
||||||
writeAsmType(asmType.getElementType(), false);
|
writeAsmType(asmType.getElementType(), false, kotlinTypeName);
|
||||||
writeArrayEnd();
|
writeArrayEnd();
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
@@ -218,8 +221,12 @@ public class BothSignatureWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writeClassBegin(String internalName, boolean nullable, boolean real) {
|
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);
|
signatureVisitor().visitClassType(internalName);
|
||||||
jetSignatureWriter.visitClassType(internalName, nullable, real);
|
jetSignatureWriter.visitClassType(kotlinTypeName == null ? internalName : kotlinTypeName, nullable, real);
|
||||||
writeAsmType0(Type.getObjectType(internalName));
|
writeAsmType0(Type.getObjectType(internalName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -262,7 +262,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
}
|
}
|
||||||
Type asmType = Type.getObjectType("error/NonExistentClass");
|
Type asmType = Type.getObjectType("error/NonExistentClass");
|
||||||
if (signatureVisitor != null) {
|
if (signatureVisitor != null) {
|
||||||
writeSimpleType(signatureVisitor, asmType, true);
|
signatureVisitor.writeAsmType(asmType, true);
|
||||||
}
|
}
|
||||||
checkValidType(asmType);
|
checkValidType(asmType);
|
||||||
return asmType;
|
return asmType;
|
||||||
@@ -302,7 +302,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
}
|
}
|
||||||
boolean forceReal = KotlinToJavaTypesMap.getInstance().isForceReal(name);
|
boolean forceReal = KotlinToJavaTypesMap.getInstance().isForceReal(name);
|
||||||
|
|
||||||
writeGenericType(jetType, signatureVisitor, asmType, forceReal);
|
writeGenericType(signatureVisitor, asmType, jetType, forceReal);
|
||||||
|
|
||||||
checkValidType(asmType);
|
checkValidType(asmType);
|
||||||
return asmType;
|
return asmType;
|
||||||
@@ -339,9 +339,10 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
parentDeclarationElement != null ? parentDeclarationElement.getText() : "null");
|
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) {
|
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()) {
|
for (TypeProjection proj : jetType.getArguments()) {
|
||||||
// TODO: +-
|
// TODO: +-
|
||||||
signatureVisitor.writeTypeArgument(proj.getProjectionKind());
|
signatureVisitor.writeTypeArgument(proj.getProjectionKind());
|
||||||
@@ -355,18 +356,28 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
private Type mapKnownAsmType(JetType jetType, Type asmType, @Nullable BothSignatureWriter signatureVisitor) {
|
private Type mapKnownAsmType(JetType jetType, Type asmType, @Nullable BothSignatureWriter signatureVisitor) {
|
||||||
if (signatureVisitor != null) {
|
if (signatureVisitor != null) {
|
||||||
if (jetType.getArguments().isEmpty()) {
|
if (jetType.getArguments().isEmpty()) {
|
||||||
writeSimpleType(signatureVisitor, asmType, jetType.isNullable());
|
String kotlinTypeName = getKotlinTypeNameForSignature(jetType, asmType);
|
||||||
|
signatureVisitor.writeAsmType(asmType, jetType.isNullable(), kotlinTypeName);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
writeGenericType(jetType, signatureVisitor, asmType, false);
|
writeGenericType(signatureVisitor, asmType, jetType, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
checkValidType(asmType);
|
checkValidType(asmType);
|
||||||
return asmType;
|
return asmType;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeSimpleType(BothSignatureWriter visitor, Type asmType, boolean nullable) {
|
@Nullable
|
||||||
visitor.writeAsmType(asmType, 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) {
|
private void checkValidType(@NotNull Type type) {
|
||||||
|
|||||||
Reference in New Issue
Block a user