static MethodInfo?FindJavaMethod(KotlinFile kotlinFile, KotlinFunction function, ClassFile klass) { var possible_methods = klass.Methods.Where(method => method.Name == function.JvmName && method.GetFilteredParameters().Length == function.ValueParameters?.Count); foreach (var method in possible_methods) { if (function.ReturnType == null) { continue; } if (!TypesMatch(method.ReturnType, function.ReturnType, kotlinFile)) { continue; } if (!ParametersMatch(kotlinFile, method, function.ValueParameters !)) { continue; } return(method); } return(null); }
internal static KotlinFile FromProtobuf(Package c, JvmNameResolver resolver) { return(new KotlinFile { Functions = c.Functions?.Select(f => KotlinFunction.FromProtobuf(f, resolver)).ToList(), Properties = c.Properties?.Select(p => KotlinProperty.FromProtobuf(p, resolver)).ToList(), TypeAliases = c.TypeAlias?.Select(tp => KotlinTypeAlias.FromProtobuf(tp, resolver)).ToList(), TypeTable = KotlinTypeTable.FromProtobuf(c.TypeTable, resolver), VersionRequirementTable = KotlinVersionRequirementTable.FromProtobuf(c.VersionRequirementTable, resolver) }); }
internal static KotlinClass FromProtobuf(Class c, JvmNameResolver resolver) { return(new KotlinClass { CompanionObjectName = c.CompanionObjectName > 0 ? resolver.GetString(c.CompanionObjectName) : null, Constructors = c.Constructors?.Select(ctor => KotlinConstructor.FromProtobuf(ctor, resolver)).ToList(), EnumEntries = c.EnumEntries?.Select(e => resolver.GetString(e.Name)).ToList(), Flags = (KotlinClassFlags)c.Flags, FullyQualifiedName = c.FqName > 0 ? resolver.GetString(c.FqName) : null, Functions = c.Functions?.Select(f => KotlinFunction.FromProtobuf(f, resolver)).ToList(), NestedClassNames = c.NestedClassNames?.Select(n => resolver.GetString(n)).ToList(), Properties = c.Properties?.Select(p => KotlinProperty.FromProtobuf(p, resolver)).ToList(), SealedSubclassFullyQualifiedNames = c.SealedSubclassFqNames?.Select(n => resolver.GetString(n)).ToList(), SuperTypeIds = c.SupertypeIds?.Select(n => resolver.GetString(n)).ToList(), SuperTypes = c.Supertypes?.Select(st => KotlinType.FromProtobuf(st, resolver)).ToList(), TypeAliases = c.TypeAlias?.Select(tp => KotlinTypeAlias.FromProtobuf(tp, resolver)).ToList(), TypeParameters = c.TypeParameters?.Select(tp => KotlinTypeParameter.FromProtobuf(tp, resolver)).ToList(), VersionRequirements = c.VersionRequirements, TypeTable = KotlinTypeTable.FromProtobuf(c.TypeTable, resolver), VersionRequirementTable = KotlinVersionRequirementTable.FromProtobuf(c.VersionRequirementTable, resolver) }); }
static void FixupFunction(MethodInfo?method, KotlinFunction metadata, KotlinClass?kotlinClass) { if (method is null || !method.IsPubliclyVisible) { return; } // Hide function if it isn't Public/Protected if (!metadata.Flags.IsPubliclyVisible()) { Log.Debug($"Kotlin: Hiding internal method {method.DeclaringType?.ThisClass.Name.Value} - {metadata.GetSignature ()}"); method.AccessFlags = SetVisibility(method.AccessFlags, MethodAccessFlags.Internal); return; } var java_parameters = method.GetFilteredParameters(); for (var i = 0; i < java_parameters.Length; i++) { var java_p = java_parameters [i]; var kotlin_p = metadata.ValueParameters == null ? null : metadata.ValueParameters [i]; if (kotlin_p == null || kotlin_p.Type == null || kotlin_p.Name == null) { continue; } // Kotlin provides actual parameter names if (TypesMatch(java_p.Type, kotlin_p.Type, kotlinClass) && java_p.IsUnnamedParameter() && !kotlin_p.IsUnnamedParameter()) { Log.Debug($"Kotlin: Renaming parameter {method.DeclaringType?.ThisClass.Name.Value} - {method.Name} - {java_p.Name} -> {kotlin_p.Name}"); java_p.Name = kotlin_p.Name; } // Handle erasure of Kotlin unsigned types java_p.KotlinType = GetKotlinType(java_p.Type.TypeSignature, kotlin_p.Type.ClassName); } // Handle erasure of Kotlin unsigned types method.KotlinReturnType = GetKotlinType(method.ReturnType.TypeSignature, metadata.ReturnType?.ClassName); }