Exemple #1
0
        public static KotlinMetadata FromAnnotation(Annotation annotation)
        {
            var km = new KotlinMetadata {
                ByteCodeVersion = ParseVersion(annotation, "bv"),
                Kind            = (KotlinMetadataKind)ParseInteger(GetValue(annotation, "k")),
                MetadataVersion = ParseVersion(annotation, "mv")
            };

            km.Data1 = GetValues(annotation, "d1");
            km.Data2 = GetValues(annotation, "d2");

            return(km);
        }
Exemple #2
0
        public static void Fixup(IList <ClassFile> classes)
        {
            foreach (var c in classes)
            {
                // See if this is a Kotlin class
                var attr   = c.Attributes.OfType <RuntimeVisibleAnnotationsAttribute> ().FirstOrDefault();
                var kotlin = attr?.Annotations.SingleOrDefault(a => a.Type == "Lkotlin/Metadata;");

                if (kotlin is null)
                {
                    continue;
                }

                try {
                    var km       = KotlinMetadata.FromAnnotation(kotlin);
                    var metadata = km.ParseMetadata();

                    if (metadata is null)
                    {
                        continue;
                    }

                    // Do fixups only valid for full classes
                    var class_metadata = (metadata as KotlinClass);

                    if (class_metadata != null)
                    {
                        FixupClassVisibility(c, class_metadata);

                        if (!c.AccessFlags.IsPubliclyVisible())
                        {
                            continue;
                        }

                        foreach (var con in class_metadata.Constructors)
                        {
                            FixupConstructor(FindJavaConstructor(class_metadata, con, c), con);
                        }
                    }

                    // Do fixups valid for both classes and modules
                    // (We pass "class_metadata" even though it's sometimes null because it's
                    // used for generic type resolution if available for class types)
                    FixupJavaMethods(c.Methods);

                    foreach (var met in metadata.Functions)
                    {
                        FixupFunction(FindJavaMethod(metadata, met, c), met, class_metadata);
                    }

                    foreach (var prop in metadata.Properties)
                    {
                        var getter = FindJavaPropertyGetter(metadata, prop, c);
                        var setter = FindJavaPropertySetter(metadata, prop, c);

                        FixupProperty(getter, setter, prop);

                        FixupField(FindJavaFieldProperty(metadata, prop, c), prop);
                    }
                } catch (Exception ex) {
                    Log.Warning(0, $"class-parse: warning: Unable to parse Kotlin metadata on '{c.ThisClass.Name}': {ex}");
                }
            }
        }