Ejemplo n.º 1
0
        static bool ParametersMatch(KotlinFile kotlinClass, MethodInfo method, List <KotlinValueParameter> kotlinParameters)
        {
            var java_parameters = method.GetFilteredParameters();

            if (java_parameters.Length == 0 && kotlinParameters.Count == 0)
            {
                return(true);
            }

            for (var i = 0; i < java_parameters.Length; i++)
            {
                var java_p   = java_parameters [i];
                var kotlin_p = kotlinParameters [i];

                if (!TypesMatch(java_p.Type, kotlin_p.Type, kotlinClass))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        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 = MethodAccessFlags.Private;
                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 [i];

                // 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);
        }