Convert JvmSerializerExtension to Kotlin
This commit is contained in:
+173
-206
@@ -3,311 +3,278 @@
|
|||||||
* that can be found in the license/LICENSE.txt file.
|
* that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.codegen.serialization;
|
package org.jetbrains.kotlin.codegen.serialization
|
||||||
|
|
||||||
import com.intellij.openapi.util.Pair;
|
import com.intellij.openapi.util.Pair
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.kotlin.codegen.ClassBuilderMode
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.kotlin.codegen.*
|
||||||
import org.jetbrains.kotlin.codegen.ClassBuilderMode;
|
import org.jetbrains.kotlin.codegen.binding.CodegenBinding
|
||||||
import org.jetbrains.kotlin.codegen.FakeDescriptorsForReferencesKt;
|
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||||
import org.jetbrains.kotlin.codegen.binding.CodegenBinding;
|
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
|
||||||
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
import org.jetbrains.kotlin.config.LanguageFeature
|
||||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper;
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.config.LanguageFeature;
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.*;
|
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor;
|
import org.jetbrains.kotlin.load.java.lazy.types.RawTypeImpl
|
||||||
import org.jetbrains.kotlin.load.java.JvmAbi;
|
import org.jetbrains.kotlin.load.kotlin.*
|
||||||
import org.jetbrains.kotlin.load.java.lazy.types.RawTypeImpl;
|
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||||
import org.jetbrains.kotlin.load.kotlin.TypeSignatureMappingKt;
|
import org.jetbrains.kotlin.metadata.jvm.JvmProtoBuf
|
||||||
import org.jetbrains.kotlin.metadata.ProtoBuf;
|
import org.jetbrains.kotlin.metadata.jvm.deserialization.ClassMapperLite
|
||||||
import org.jetbrains.kotlin.metadata.jvm.JvmProtoBuf;
|
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmProtoBufUtil
|
||||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.ClassMapperLite;
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmProtoBufUtil;
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.ClassId;
|
import org.jetbrains.kotlin.protobuf.GeneratedMessageLite
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.protobuf.GeneratedMessageLite;
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
import org.jetbrains.kotlin.resolve.descriptorUtil.*
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
import org.jetbrains.kotlin.serialization.AnnotationSerializer
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
import org.jetbrains.kotlin.serialization.DescriptorSerializer
|
||||||
import org.jetbrains.kotlin.serialization.AnnotationSerializer;
|
import org.jetbrains.kotlin.serialization.SerializerExtension
|
||||||
import org.jetbrains.kotlin.serialization.DescriptorSerializer;
|
import org.jetbrains.kotlin.types.FlexibleType
|
||||||
import org.jetbrains.kotlin.serialization.SerializerExtension;
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.FlexibleType;
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
import org.jetbrains.kotlin.types.KotlinType;
|
import org.jetbrains.org.objectweb.asm.commons.Method
|
||||||
import org.jetbrains.org.objectweb.asm.Type;
|
|
||||||
import org.jetbrains.org.objectweb.asm.commons.Method;
|
|
||||||
|
|
||||||
import java.util.List;
|
import org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings.*
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings.*;
|
class JvmSerializerExtension(private val bindings: JvmSerializationBindings, state: GenerationState) : SerializerExtension() {
|
||||||
|
private val codegenBinding: BindingContext
|
||||||
|
private val typeMapper: KotlinTypeMapper
|
||||||
|
override val stringTable: JvmCodegenStringTable
|
||||||
|
private val annotationSerializer: AnnotationSerializer
|
||||||
|
private val useTypeTable: Boolean
|
||||||
|
private val moduleName: String
|
||||||
|
private val classBuilderMode: ClassBuilderMode
|
||||||
|
private val isReleaseCoroutines: Boolean
|
||||||
|
|
||||||
public class JvmSerializerExtension extends SerializerExtension {
|
init {
|
||||||
private final JvmSerializationBindings bindings;
|
this.codegenBinding = state.bindingContext
|
||||||
private final BindingContext codegenBinding;
|
this.typeMapper = state.typeMapper
|
||||||
private final KotlinTypeMapper typeMapper;
|
this.stringTable = JvmCodegenStringTable(typeMapper)
|
||||||
private final JvmCodegenStringTable stringTable;
|
this.annotationSerializer = AnnotationSerializer(stringTable)
|
||||||
private final AnnotationSerializer annotationSerializer;
|
this.useTypeTable = state.useTypeTableInSerializer
|
||||||
private final boolean useTypeTable;
|
this.moduleName = state.moduleName
|
||||||
private final String moduleName;
|
this.classBuilderMode = state.classBuilderMode
|
||||||
private final ClassBuilderMode classBuilderMode;
|
this.isReleaseCoroutines = state.languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines)
|
||||||
private final boolean isReleaseCoroutines;
|
|
||||||
|
|
||||||
public JvmSerializerExtension(@NotNull JvmSerializationBindings bindings, @NotNull GenerationState state) {
|
|
||||||
this.bindings = bindings;
|
|
||||||
this.codegenBinding = state.getBindingContext();
|
|
||||||
this.typeMapper = state.getTypeMapper();
|
|
||||||
this.stringTable = new JvmCodegenStringTable(typeMapper);
|
|
||||||
this.annotationSerializer = new AnnotationSerializer(stringTable);
|
|
||||||
this.useTypeTable = state.getUseTypeTableInSerializer();
|
|
||||||
this.moduleName = state.getModuleName();
|
|
||||||
this.classBuilderMode = state.getClassBuilderMode();
|
|
||||||
this.isReleaseCoroutines = state.getLanguageVersionSettings().supportsFeature(LanguageFeature.ReleaseCoroutines);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
override fun shouldUseTypeTable(): Boolean {
|
||||||
@Override
|
return useTypeTable
|
||||||
public JvmCodegenStringTable getStringTable() {
|
|
||||||
return stringTable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun serializeClass(descriptor: ClassDescriptor, proto: ProtoBuf.Class.Builder) {
|
||||||
public boolean shouldUseTypeTable() {
|
if (moduleName != JvmAbi.DEFAULT_MODULE_NAME) {
|
||||||
return useTypeTable;
|
proto.setExtension(JvmProtoBuf.classModuleName, stringTable.getStringIndex(moduleName))
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void serializeClass(@NotNull ClassDescriptor descriptor, @NotNull ProtoBuf.Class.Builder proto) {
|
|
||||||
if (!moduleName.equals(JvmAbi.DEFAULT_MODULE_NAME)) {
|
|
||||||
proto.setExtension(JvmProtoBuf.classModuleName, stringTable.getStringIndex(moduleName));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Type containerAsmType =
|
val containerAsmType =
|
||||||
DescriptorUtils.isInterface(descriptor) ? typeMapper.mapDefaultImpls(descriptor) : typeMapper.mapClass(descriptor);
|
if (DescriptorUtils.isInterface(descriptor)) typeMapper.mapDefaultImpls(descriptor) else typeMapper.mapClass(descriptor)
|
||||||
writeLocalProperties(proto, containerAsmType, JvmProtoBuf.classLocalVariable);
|
writeLocalProperties<Class, Builder>(proto, containerAsmType, JvmProtoBuf.classLocalVariable)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun serializePackage(packageFqName: FqName, proto: ProtoBuf.Package.Builder) {
|
||||||
public void serializePackage(@NotNull FqName packageFqName, @NotNull ProtoBuf.Package.Builder proto) {
|
if (moduleName != JvmAbi.DEFAULT_MODULE_NAME) {
|
||||||
if (!moduleName.equals(JvmAbi.DEFAULT_MODULE_NAME)) {
|
proto.setExtension(JvmProtoBuf.packageModuleName, stringTable.getStringIndex(moduleName))
|
||||||
proto.setExtension(JvmProtoBuf.packageModuleName, stringTable.getStringIndex(moduleName));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void serializeJvmPackage(@NotNull ProtoBuf.Package.Builder proto, @NotNull Type partAsmType) {
|
fun serializeJvmPackage(proto: ProtoBuf.Package.Builder, partAsmType: Type) {
|
||||||
writeLocalProperties(proto, partAsmType, JvmProtoBuf.packageLocalVariable);
|
writeLocalProperties<Package, Builder>(proto, partAsmType, JvmProtoBuf.packageLocalVariable)
|
||||||
}
|
}
|
||||||
|
|
||||||
private <MessageType extends GeneratedMessageLite.ExtendableMessage<MessageType>,
|
private fun <MessageType : GeneratedMessageLite.ExtendableMessage<MessageType>, BuilderType : GeneratedMessageLite.ExtendableBuilder<MessageType, BuilderType>> writeLocalProperties(
|
||||||
BuilderType extends GeneratedMessageLite.ExtendableBuilder<MessageType, BuilderType>> void writeLocalProperties(
|
proto: BuilderType,
|
||||||
@NotNull BuilderType proto,
|
classAsmType: Type,
|
||||||
@NotNull Type classAsmType,
|
extension: GeneratedMessageLite.GeneratedExtension<MessageType, List<ProtoBuf.Property>>
|
||||||
@NotNull GeneratedMessageLite.GeneratedExtension<MessageType, List<ProtoBuf.Property>> extension
|
|
||||||
) {
|
) {
|
||||||
List<LocalVariableDescriptor> localVariables = CodegenBinding.getLocalDelegatedProperties(codegenBinding, classAsmType);
|
val localVariables = CodegenBinding.getLocalDelegatedProperties(codegenBinding, classAsmType) ?: return
|
||||||
if (localVariables == null) return;
|
|
||||||
|
|
||||||
for (LocalVariableDescriptor localVariable : localVariables) {
|
for (localVariable in localVariables) {
|
||||||
PropertyDescriptor propertyDescriptor = FakeDescriptorsForReferencesKt.createFreeFakeLocalPropertyDescriptor(localVariable);
|
val propertyDescriptor = createFreeFakeLocalPropertyDescriptor(localVariable)
|
||||||
DescriptorSerializer serializer = DescriptorSerializer.createForLambda(this);
|
val serializer = DescriptorSerializer.createForLambda(this)
|
||||||
proto.addExtension(extension, serializer.propertyProto(propertyDescriptor).build());
|
proto.addExtension<Property>(extension, serializer.propertyProto(propertyDescriptor).build())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun serializeFlexibleType(
|
||||||
public void serializeFlexibleType(
|
flexibleType: FlexibleType,
|
||||||
@NotNull FlexibleType flexibleType,
|
lowerProto: ProtoBuf.Type.Builder,
|
||||||
@NotNull ProtoBuf.Type.Builder lowerProto,
|
upperProto: ProtoBuf.Type.Builder
|
||||||
@NotNull ProtoBuf.Type.Builder upperProto
|
|
||||||
) {
|
) {
|
||||||
lowerProto.setFlexibleTypeCapabilitiesId(getStringTable().getStringIndex(JvmProtoBufUtil.PLATFORM_TYPE_ID));
|
lowerProto.flexibleTypeCapabilitiesId = stringTable.getStringIndex(JvmProtoBufUtil.PLATFORM_TYPE_ID)
|
||||||
|
|
||||||
if (flexibleType instanceof RawTypeImpl) {
|
if (flexibleType is RawTypeImpl) {
|
||||||
lowerProto.setExtension(JvmProtoBuf.isRaw, true);
|
lowerProto.setExtension(JvmProtoBuf.isRaw, true)
|
||||||
|
|
||||||
// we write this Extension for compatibility with old compiler
|
// we write this Extension for compatibility with old compiler
|
||||||
upperProto.setExtension(JvmProtoBuf.isRaw, true);
|
upperProto.setExtension(JvmProtoBuf.isRaw, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun serializeType(type: KotlinType, proto: ProtoBuf.Type.Builder) {
|
||||||
public void serializeType(@NotNull KotlinType type, @NotNull ProtoBuf.Type.Builder proto) {
|
|
||||||
// TODO: don't store type annotations in our binary metadata on Java 8, use *TypeAnnotations attributes instead
|
// TODO: don't store type annotations in our binary metadata on Java 8, use *TypeAnnotations attributes instead
|
||||||
for (AnnotationDescriptor annotation : DescriptorUtilsKt.getNonSourceAnnotations(type)) {
|
for (annotation in type.nonSourceAnnotations) {
|
||||||
proto.addExtension(JvmProtoBuf.typeAnnotation, annotationSerializer.serializeAnnotation(annotation));
|
proto.addExtension<Annotation>(JvmProtoBuf.typeAnnotation, annotationSerializer.serializeAnnotation(annotation))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun serializeTypeParameter(typeParameter: TypeParameterDescriptor, proto: ProtoBuf.TypeParameter.Builder) {
|
||||||
public void serializeTypeParameter(@NotNull TypeParameterDescriptor typeParameter, @NotNull ProtoBuf.TypeParameter.Builder proto) {
|
for (annotation in typeParameter.nonSourceAnnotations) {
|
||||||
for (AnnotationDescriptor annotation : DescriptorUtilsKt.getNonSourceAnnotations(typeParameter)) {
|
proto.addExtension<Annotation>(JvmProtoBuf.typeParameterAnnotation, annotationSerializer.serializeAnnotation(annotation))
|
||||||
proto.addExtension(JvmProtoBuf.typeParameterAnnotation, annotationSerializer.serializeAnnotation(annotation));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun serializeConstructor(descriptor: ConstructorDescriptor, proto: ProtoBuf.Constructor.Builder) {
|
||||||
public void serializeConstructor(@NotNull ConstructorDescriptor descriptor, @NotNull ProtoBuf.Constructor.Builder proto) {
|
val method = bindings.get(METHOD_FOR_FUNCTION, descriptor)
|
||||||
Method method = bindings.get(METHOD_FOR_FUNCTION, descriptor);
|
|
||||||
if (method != null) {
|
if (method != null) {
|
||||||
JvmProtoBuf.JvmMethodSignature signature = new SignatureSerializer().methodSignature(descriptor, method);
|
val signature = SignatureSerializer().methodSignature(descriptor, method)
|
||||||
if (signature != null) {
|
if (signature != null) {
|
||||||
proto.setExtension(JvmProtoBuf.constructorSignature, signature);
|
proto.setExtension<JvmMethodSignature>(JvmProtoBuf.constructorSignature, signature)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun serializeFunction(descriptor: FunctionDescriptor, proto: ProtoBuf.Function.Builder) {
|
||||||
public void serializeFunction(@NotNull FunctionDescriptor descriptor, @NotNull ProtoBuf.Function.Builder proto) {
|
val method = bindings.get(METHOD_FOR_FUNCTION, descriptor)
|
||||||
Method method = bindings.get(METHOD_FOR_FUNCTION, descriptor);
|
|
||||||
if (method != null) {
|
if (method != null) {
|
||||||
JvmProtoBuf.JvmMethodSignature signature = new SignatureSerializer().methodSignature(descriptor, method);
|
val signature = SignatureSerializer().methodSignature(descriptor, method)
|
||||||
if (signature != null) {
|
if (signature != null) {
|
||||||
proto.setExtension(JvmProtoBuf.methodSignature, signature);
|
proto.setExtension<JvmMethodSignature>(JvmProtoBuf.methodSignature, signature)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun serializeProperty(descriptor: PropertyDescriptor, proto: ProtoBuf.Property.Builder) {
|
||||||
public void serializeProperty(@NotNull PropertyDescriptor descriptor, @NotNull ProtoBuf.Property.Builder proto) {
|
val signatureSerializer = SignatureSerializer()
|
||||||
SignatureSerializer signatureSerializer = new SignatureSerializer();
|
|
||||||
|
|
||||||
PropertyGetterDescriptor getter = descriptor.getGetter();
|
val getter = descriptor.getGetter()
|
||||||
PropertySetterDescriptor setter = descriptor.getSetter();
|
val setter = descriptor.getSetter()
|
||||||
Method getterMethod = getter == null ? null : bindings.get(METHOD_FOR_FUNCTION, getter);
|
val getterMethod = if (getter == null) null else bindings.get(METHOD_FOR_FUNCTION, getter!!)
|
||||||
Method setterMethod = setter == null ? null : bindings.get(METHOD_FOR_FUNCTION, setter);
|
val setterMethod = if (setter == null) null else bindings.get(METHOD_FOR_FUNCTION, setter!!)
|
||||||
|
|
||||||
Pair<Type, String> field = bindings.get(FIELD_FOR_PROPERTY, descriptor);
|
val field = bindings.get(FIELD_FOR_PROPERTY, descriptor)
|
||||||
Method syntheticMethod = bindings.get(SYNTHETIC_METHOD_FOR_PROPERTY, descriptor);
|
val syntheticMethod = bindings.get(SYNTHETIC_METHOD_FOR_PROPERTY, descriptor)
|
||||||
|
|
||||||
JvmProtoBuf.JvmPropertySignature signature = signatureSerializer.propertySignature(
|
val signature = signatureSerializer.propertySignature(
|
||||||
descriptor,
|
descriptor,
|
||||||
field != null ? field.second : null,
|
field?.second,
|
||||||
field != null ? field.first.getDescriptor() : null,
|
field?.first?.descriptor,
|
||||||
syntheticMethod != null ? signatureSerializer.methodSignature(null, syntheticMethod) : null,
|
if (syntheticMethod != null) signatureSerializer.methodSignature(null, syntheticMethod) else null,
|
||||||
getterMethod != null ? signatureSerializer.methodSignature(null, getterMethod) : null,
|
if (getterMethod != null) signatureSerializer.methodSignature(null, getterMethod) else null,
|
||||||
setterMethod != null ? signatureSerializer.methodSignature(null, setterMethod) : null
|
if (setterMethod != null) signatureSerializer.methodSignature(null, setterMethod) else null
|
||||||
);
|
)
|
||||||
|
|
||||||
proto.setExtension(JvmProtoBuf.propertySignature, signature);
|
proto.setExtension<JvmPropertySignature>(JvmProtoBuf.propertySignature, signature)
|
||||||
Boolean fieldMovedFromInterfaceCompanion = bindings.get(FIELD_MOVED_FROM_INTERFACE_COMPANION, descriptor);
|
val fieldMovedFromInterfaceCompanion = bindings.get(FIELD_MOVED_FROM_INTERFACE_COMPANION, descriptor)
|
||||||
if (fieldMovedFromInterfaceCompanion != null && fieldMovedFromInterfaceCompanion) {
|
if (fieldMovedFromInterfaceCompanion != null && fieldMovedFromInterfaceCompanion) {
|
||||||
proto.setExtension(JvmProtoBuf.isMovedFromInterfaceCompanion, 1);
|
proto.setExtension(JvmProtoBuf.isMovedFromInterfaceCompanion, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun serializeErrorType(type: KotlinType, builder: ProtoBuf.Type.Builder) {
|
||||||
public void serializeErrorType(@NotNull KotlinType type, @NotNull ProtoBuf.Type.Builder builder) {
|
if (classBuilderMode === ClassBuilderMode.KAPT3) {
|
||||||
if (classBuilderMode == ClassBuilderMode.KAPT3) {
|
builder.className = stringTable.getStringIndex(TypeSignatureMappingKt.NON_EXISTENT_CLASS_NAME)
|
||||||
builder.setClassName(stringTable.getStringIndex(TypeSignatureMappingKt.NON_EXISTENT_CLASS_NAME));
|
return
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
super.serializeErrorType(type, builder);
|
super.serializeErrorType(type, builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SignatureSerializer {
|
private inner class SignatureSerializer {
|
||||||
@Nullable
|
fun methodSignature(descriptor: FunctionDescriptor?, method: Method): JvmProtoBuf.JvmMethodSignature? {
|
||||||
public JvmProtoBuf.JvmMethodSignature methodSignature(@Nullable FunctionDescriptor descriptor, @NotNull Method method) {
|
val builder = JvmProtoBuf.JvmMethodSignature.newBuilder()
|
||||||
JvmProtoBuf.JvmMethodSignature.Builder builder = JvmProtoBuf.JvmMethodSignature.newBuilder();
|
if (descriptor == null || descriptor.name.asString() != method.name) {
|
||||||
if (descriptor == null || !descriptor.getName().asString().equals(method.getName())) {
|
builder.name = stringTable.getStringIndex(method.name)
|
||||||
builder.setName(stringTable.getStringIndex(method.getName()));
|
|
||||||
}
|
}
|
||||||
if (descriptor == null || requiresSignature(descriptor, method.getDescriptor())) {
|
if (descriptor == null || requiresSignature(descriptor, method.descriptor)) {
|
||||||
builder.setDesc(stringTable.getStringIndex(method.getDescriptor()));
|
builder.desc = stringTable.getStringIndex(method.descriptor)
|
||||||
}
|
}
|
||||||
return builder.hasName() || builder.hasDesc() ? builder.build() : null;
|
return if (builder.hasName() || builder.hasDesc()) builder.build() else null
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't write those signatures which can be trivially reconstructed from already serialized data
|
// We don't write those signatures which can be trivially reconstructed from already serialized data
|
||||||
// TODO: make JvmStringTable implement NameResolver and use JvmProtoBufUtil#getJvmMethodSignature instead
|
// TODO: make JvmStringTable implement NameResolver and use JvmProtoBufUtil#getJvmMethodSignature instead
|
||||||
private boolean requiresSignature(@NotNull FunctionDescriptor descriptor, @NotNull String desc) {
|
private fun requiresSignature(descriptor: FunctionDescriptor, desc: String): Boolean {
|
||||||
StringBuilder sb = new StringBuilder();
|
val sb = StringBuilder()
|
||||||
sb.append("(");
|
sb.append("(")
|
||||||
ReceiverParameterDescriptor receiverParameter = descriptor.getExtensionReceiverParameter();
|
val receiverParameter = descriptor.extensionReceiverParameter
|
||||||
if (receiverParameter != null) {
|
if (receiverParameter != null) {
|
||||||
String receiverDesc = mapTypeDefault(receiverParameter.getValue().getType());
|
val receiverDesc = mapTypeDefault(receiverParameter.value.type) ?: return true
|
||||||
if (receiverDesc == null) return true;
|
sb.append(receiverDesc)
|
||||||
sb.append(receiverDesc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ValueParameterDescriptor valueParameter : descriptor.getValueParameters()) {
|
for (valueParameter in descriptor.valueParameters) {
|
||||||
String paramDesc = mapTypeDefault(valueParameter.getType());
|
val paramDesc = mapTypeDefault(valueParameter.type) ?: return true
|
||||||
if (paramDesc == null) return true;
|
sb.append(paramDesc)
|
||||||
sb.append(paramDesc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.append(")");
|
sb.append(")")
|
||||||
|
|
||||||
KotlinType returnType = descriptor.getReturnType();
|
val returnType = descriptor.returnType
|
||||||
String returnTypeDesc = returnType == null ? "V" : mapTypeDefault(returnType);
|
val returnTypeDesc = (if (returnType == null) "V" else mapTypeDefault(returnType)) ?: return true
|
||||||
if (returnTypeDesc == null) return true;
|
sb.append(returnTypeDesc)
|
||||||
sb.append(returnTypeDesc);
|
|
||||||
|
|
||||||
return !sb.toString().equals(desc);
|
return sb.toString() != desc
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean requiresSignature(@NotNull PropertyDescriptor descriptor, @NotNull String desc) {
|
private fun requiresSignature(descriptor: PropertyDescriptor, desc: String): Boolean {
|
||||||
return !desc.equals(mapTypeDefault(descriptor.getType()));
|
return desc != mapTypeDefault(descriptor.type)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
private fun mapTypeDefault(type: KotlinType): String? {
|
||||||
private String mapTypeDefault(@NotNull KotlinType type) {
|
val classifier = type.constructor.declarationDescriptor as? ClassDescriptor ?: return null
|
||||||
ClassifierDescriptor classifier = type.getConstructor().getDeclarationDescriptor();
|
val classId = classifier.classId
|
||||||
if (!(classifier instanceof ClassDescriptor)) return null;
|
return if (classId == null) null else ClassMapperLite.mapClass(classId.asString())
|
||||||
ClassId classId = DescriptorUtilsKt.getClassId((ClassDescriptor) classifier);
|
|
||||||
return classId == null ? null : ClassMapperLite.mapClass(classId.asString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
fun propertySignature(
|
||||||
public JvmProtoBuf.JvmPropertySignature propertySignature(
|
descriptor: PropertyDescriptor,
|
||||||
@NotNull PropertyDescriptor descriptor,
|
fieldName: String?,
|
||||||
@Nullable String fieldName,
|
fieldDesc: String?,
|
||||||
@Nullable String fieldDesc,
|
syntheticMethod: JvmProtoBuf.JvmMethodSignature?,
|
||||||
@Nullable JvmProtoBuf.JvmMethodSignature syntheticMethod,
|
getter: JvmProtoBuf.JvmMethodSignature?,
|
||||||
@Nullable JvmProtoBuf.JvmMethodSignature getter,
|
setter: JvmProtoBuf.JvmMethodSignature?
|
||||||
@Nullable JvmProtoBuf.JvmMethodSignature setter
|
): JvmProtoBuf.JvmPropertySignature {
|
||||||
) {
|
val signature = JvmProtoBuf.JvmPropertySignature.newBuilder()
|
||||||
JvmProtoBuf.JvmPropertySignature.Builder signature = JvmProtoBuf.JvmPropertySignature.newBuilder();
|
|
||||||
|
|
||||||
if (fieldDesc != null) {
|
if (fieldDesc != null) {
|
||||||
assert fieldName != null : "Field name shouldn't be null when there's a field type: " + fieldDesc;
|
assert(fieldName != null) { "Field name shouldn't be null when there's a field type: $fieldDesc" }
|
||||||
signature.setField(fieldSignature(descriptor, fieldName, fieldDesc));
|
signature.field = fieldSignature(descriptor, fieldName!!, fieldDesc)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (syntheticMethod != null) {
|
if (syntheticMethod != null) {
|
||||||
signature.setSyntheticMethod(syntheticMethod);
|
signature.syntheticMethod = syntheticMethod
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getter != null) {
|
if (getter != null) {
|
||||||
signature.setGetter(getter);
|
signature.getter = getter
|
||||||
}
|
}
|
||||||
if (setter != null) {
|
if (setter != null) {
|
||||||
signature.setSetter(setter);
|
signature.setter = setter
|
||||||
}
|
}
|
||||||
|
|
||||||
return signature.build();
|
return signature.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
fun fieldSignature(
|
||||||
public JvmProtoBuf.JvmFieldSignature fieldSignature(
|
descriptor: PropertyDescriptor,
|
||||||
@NotNull PropertyDescriptor descriptor,
|
name: String,
|
||||||
@NotNull String name,
|
desc: String
|
||||||
@NotNull String desc
|
): JvmProtoBuf.JvmFieldSignature {
|
||||||
) {
|
val builder = JvmProtoBuf.JvmFieldSignature.newBuilder()
|
||||||
JvmProtoBuf.JvmFieldSignature.Builder builder = JvmProtoBuf.JvmFieldSignature.newBuilder();
|
if (descriptor.name.asString() != name) {
|
||||||
if (!descriptor.getName().asString().equals(name)) {
|
builder.name = stringTable.getStringIndex(name)
|
||||||
builder.setName(stringTable.getStringIndex(name));
|
|
||||||
}
|
}
|
||||||
if (requiresSignature(descriptor, desc)) {
|
if (requiresSignature(descriptor, desc)) {
|
||||||
builder.setDesc(stringTable.getStringIndex(desc));
|
builder.desc = stringTable.getStringIndex(desc)
|
||||||
}
|
}
|
||||||
return builder.build();
|
return builder.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun releaseCoroutines(): Boolean {
|
||||||
public boolean releaseCoroutines() {
|
return isReleaseCoroutines
|
||||||
return isReleaseCoroutines;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user