JVM: Generate generic signatures for delegate fields
This commit is contained in:
committed by
Alexander Udalov
parent
20ea77d55d
commit
34fb636904
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.codegen;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.backend.common.CodegenUtil;
|
import org.jetbrains.kotlin.backend.common.CodegenUtil;
|
||||||
|
import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter;
|
||||||
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper;
|
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper;
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||||
@@ -49,11 +50,17 @@ public class DelegationFieldsInfo {
|
|||||||
public final Type type;
|
public final Type type;
|
||||||
public final String name;
|
public final String name;
|
||||||
public final boolean generateField;
|
public final boolean generateField;
|
||||||
|
public final String genericSignature;
|
||||||
|
|
||||||
private Field(Type type, String name, boolean generateField) {
|
private Field(Type type, String name, boolean generateField, String genericSignature) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.generateField = generateField;
|
this.generateField = generateField;
|
||||||
|
this.genericSignature = genericSignature;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Field(Type type, String name, boolean generateField) {
|
||||||
|
this(type, name, generateField, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -75,8 +82,8 @@ public class DelegationFieldsInfo {
|
|||||||
new DelegationFieldsInfo.Field(typeMapper.mapType(propertyDescriptor), propertyDescriptor.getName().asString(), false));
|
new DelegationFieldsInfo.Field(typeMapper.mapType(propertyDescriptor), propertyDescriptor.getName().asString(), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addField(KtDelegatedSuperTypeEntry specifier, Type type, String name) {
|
private void addField(KtDelegatedSuperTypeEntry specifier, Type type, String name, String genericSignature) {
|
||||||
fields.put(specifier, new DelegationFieldsInfo.Field(type, name, true));
|
fields.put(specifier, new DelegationFieldsInfo.Field(type, name, true, genericSignature));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -97,13 +104,15 @@ public class DelegationFieldsInfo {
|
|||||||
else {
|
else {
|
||||||
KotlinType expressionType = bindingContext.getType(expression);
|
KotlinType expressionType = bindingContext.getType(expression);
|
||||||
ClassDescriptor superClass = JvmCodegenUtil.getSuperClass(specifier, state, bindingContext);
|
ClassDescriptor superClass = JvmCodegenUtil.getSuperClass(specifier, state, bindingContext);
|
||||||
|
BothSignatureWriter sw = new BothSignatureWriter(BothSignatureWriter.Mode.TYPE);
|
||||||
Type asmType =
|
Type asmType =
|
||||||
expressionType != null ? typeMapper.mapType(expressionType) :
|
expressionType != null ? typeMapper.mapType(expressionType, sw) :
|
||||||
superClass != null ? typeMapper.mapType(superClass) : null;
|
superClass != null ? typeMapper.mapType(superClass.getDefaultType(), sw) : null;
|
||||||
|
|
||||||
if (asmType == null) continue;
|
if (asmType == null) continue;
|
||||||
|
|
||||||
result.addField((KtDelegatedSuperTypeEntry) specifier, asmType, DELEGATE_SUPER_FIELD_PREFIX + n);
|
String genericSignature = sw.makeJavaGenericSignature();
|
||||||
|
result.addField((KtDelegatedSuperTypeEntry) specifier, asmType, DELEGATE_SUPER_FIELD_PREFIX + n, genericSignature);
|
||||||
}
|
}
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1176,7 +1176,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
if (!fieldInfo.generateField) return;
|
if (!fieldInfo.generateField) return;
|
||||||
|
|
||||||
v.newField(JvmDeclarationOrigin.NO_ORIGIN, ACC_PRIVATE | ACC_FINAL | ACC_SYNTHETIC,
|
v.newField(JvmDeclarationOrigin.NO_ORIGIN, ACC_PRIVATE | ACC_FINAL | ACC_SYNTHETIC,
|
||||||
fieldInfo.name, fieldInfo.type.getDescriptor(), /*TODO*/null, null);
|
fieldInfo.name, fieldInfo.type.getDescriptor(), fieldInfo.genericSignature, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateDelegates(
|
private void generateDelegates(
|
||||||
|
|||||||
+2
-2
@@ -17,7 +17,7 @@ public abstract class<<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/lang/Objec
|
|||||||
public <null> method getSize(): int
|
public <null> method getSize(): int
|
||||||
public <null> method isEmpty(): boolean
|
public <null> method isEmpty(): boolean
|
||||||
public bridge final <null> method size(): int
|
public bridge final <null> method size(): int
|
||||||
private synthetic final field <null> $$delegate_0: java.util.HashMap
|
private synthetic final field <Ljava/util/HashMap<TK;TV;>;> $$delegate_0: java.util.HashMap
|
||||||
}
|
}
|
||||||
|
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
@@ -39,5 +39,5 @@ public final class<<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/lang/Object;L
|
|||||||
public <null> method getSize(): int
|
public <null> method getSize(): int
|
||||||
public <null> method isEmpty(): boolean
|
public <null> method isEmpty(): boolean
|
||||||
public bridge final <null> method size(): int
|
public bridge final <null> method size(): int
|
||||||
private synthetic final field <null> $$delegate_0: java.util.HashMap
|
private synthetic final field <Ljava/util/HashMap<TK;TV;>;> $$delegate_0: java.util.HashMap
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -22,7 +22,7 @@ public abstract class<Ljava/lang/Object;Ljava/util/Map<Ljava/lang/String;Ljava/l
|
|||||||
public @org.jetbrains.annotations.Nullable <null> method remove(@org.jetbrains.annotations.NotNull p0: java.lang.String): java.lang.String
|
public @org.jetbrains.annotations.Nullable <null> method remove(@org.jetbrains.annotations.NotNull p0: java.lang.String): java.lang.String
|
||||||
public bridge final <null> method remove(p0: java.lang.Object): java.lang.Object
|
public bridge final <null> method remove(p0: java.lang.Object): java.lang.Object
|
||||||
public bridge final <null> method size(): int
|
public bridge final <null> method size(): int
|
||||||
private synthetic final field <null> $$delegate_0: java.util.HashMap
|
private synthetic final field <Ljava/util/HashMap<Ljava/lang/String;Ljava/lang/String;>;> $$delegate_0: java.util.HashMap
|
||||||
}
|
}
|
||||||
|
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
@@ -49,5 +49,5 @@ public final class<Ljava/lang/Object;Ljava/util/Map<Ljava/lang/String;Ljava/lang
|
|||||||
public @org.jetbrains.annotations.Nullable <null> method remove(@org.jetbrains.annotations.NotNull p0: java.lang.String): java.lang.String
|
public @org.jetbrains.annotations.Nullable <null> method remove(@org.jetbrains.annotations.NotNull p0: java.lang.String): java.lang.String
|
||||||
public bridge final <null> method remove(p0: java.lang.Object): java.lang.Object
|
public bridge final <null> method remove(p0: java.lang.Object): java.lang.Object
|
||||||
public bridge final <null> method size(): int
|
public bridge final <null> method size(): int
|
||||||
private synthetic final field <null> $$delegate_0: java.util.HashMap
|
private synthetic final field <Ljava/util/HashMap<Ljava/lang/String;Ljava/lang/String;>;> $$delegate_0: java.util.HashMap
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+2
-2
@@ -21,7 +21,7 @@ public abstract class<<V:Ljava/lang/Object;>Ljava/lang/Object;Ljava/util/Map<Lja
|
|||||||
public <null> method isEmpty(): boolean
|
public <null> method isEmpty(): boolean
|
||||||
public synthetic bridge <null> method put(p0: java.lang.Object, p1: java.lang.Object): java.lang.Object
|
public synthetic bridge <null> method put(p0: java.lang.Object, p1: java.lang.Object): java.lang.Object
|
||||||
public bridge final <null> method size(): int
|
public bridge final <null> method size(): int
|
||||||
private synthetic final field <null> $$delegate_0: java.util.HashMap
|
private synthetic final field <Ljava/util/HashMap<Ljava/lang/String;TV;>;> $$delegate_0: java.util.HashMap
|
||||||
}
|
}
|
||||||
|
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
@@ -47,5 +47,5 @@ public final class<<V:Ljava/lang/Object;>Ljava/lang/Object;Ljava/util/Map<Ljava/
|
|||||||
public <null> method isEmpty(): boolean
|
public <null> method isEmpty(): boolean
|
||||||
public synthetic bridge <null> method put(p0: java.lang.Object, p1: java.lang.Object): java.lang.Object
|
public synthetic bridge <null> method put(p0: java.lang.Object, p1: java.lang.Object): java.lang.Object
|
||||||
public bridge final <null> method size(): int
|
public bridge final <null> method size(): int
|
||||||
private synthetic final field <null> $$delegate_0: java.util.HashMap
|
private synthetic final field <Ljava/util/HashMap<Ljava/lang/String;TV;>;> $$delegate_0: java.util.HashMap
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user