예제 #1
0
        static MethodInfo FindJavaPropertySetter(KotlinFile kotlinClass, KotlinProperty property, ClassFile klass)
        {
            var possible_methods = klass.Methods.Where(method => string.Compare(method.GetMethodNameWithoutSuffix(), $"set{property.Name}", true) == 0 &&
                                                       property.ReturnType != null &&
                                                       method.GetParameters().Length == 1 &&
                                                       method.ReturnType.BinaryName == "V" &&
                                                       TypesMatch(method.GetParameters() [0].Type, property.ReturnType, kotlinClass));

            return(possible_methods.FirstOrDefault());
        }
예제 #2
0
        static void FixupField(FieldInfo field, KotlinProperty metadata)
        {
            if (field is null)
            {
                return;
            }

            // Handle erasure of Kotlin unsigned types
            field.KotlinType = GetKotlinType(field.Descriptor, metadata.ReturnType.ClassName);
        }
예제 #3
0
 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)
     });
 }
예제 #4
0
        static void FixupProperty(MethodInfo getter, MethodInfo setter, KotlinProperty metadata)
        {
            if (getter is null && setter is null)
            {
                return;
            }

            // Hide property if it isn't Public/Protected
            if (!metadata.Flags.IsPubliclyVisible())
            {
                if (getter?.IsPubliclyVisible == true)
                {
                    Log.Debug($"Kotlin: Hiding internal getter method {getter.DeclaringType?.ThisClass.Name.Value} - {getter.Name}");
                    getter.AccessFlags = MethodAccessFlags.Private;
                }

                if (setter?.IsPubliclyVisible == true)
                {
                    Log.Debug($"Kotlin: Hiding internal setter method {setter.DeclaringType?.ThisClass.Name.Value} - {setter.Name}");
                    setter.AccessFlags = MethodAccessFlags.Private;
                }

                return;
            }

            // Handle erasure of Kotlin unsigned types
            if (getter != null)
            {
                getter.KotlinReturnType = GetKotlinType(getter.ReturnType.TypeSignature, metadata.ReturnType.ClassName);
            }

            if (setter != null)
            {
                var setter_parameter = setter.GetParameters().First();

                if (setter_parameter.IsUnnamedParameter() || setter_parameter.Name == "<set-?>")
                {
                    Log.Debug($"Kotlin: Renaming setter parameter {setter.DeclaringType?.ThisClass.Name.Value} - {setter.Name} - {setter_parameter.Name} -> value");
                    setter_parameter.Name = "value";
                }

                // Handle erasure of Kotlin unsigned types
                setter_parameter.KotlinType = GetKotlinType(setter_parameter.Type.TypeSignature, metadata.ReturnType.ClassName);
            }
        }
예제 #5
0
 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)
     });
 }