Skip to content

[class-parse] Add Kotlin metadata to -dump. #1150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 16, 2023
Merged

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented Oct 16, 2023

For initial "why did class-parse mark this function as kotlin-internal" type questions, it would be helpful if class-parse -dump could output a parsed Kotlin metadata blob.

Unfortunately, the Kotlin metadata blob is pretty raw, but if we start adding our logic to it then the output will be incorrect if our assumptions about how the data works are incorrect. Thus this PR is up for debate if it actually improves the situation or not.

Example:

class-parse -dump EmojiPickerView.class

--- cut normal content ---

Kotlin Class Metadata [1.8.0]:
{
  "$id": "1",
  "CompanionObjectName": "Companion",
  "Constructors": { ... },
  "EnumEntries": {
    "$id": "14",
    "$values": []
  },
  "Flags": 6,
  "FullyQualifiedName": null,
  "Inheritability": 0,
  "NestedClassNames": {
    "$id": "15",
    "$values": [
      "Companion"
    ]
  },
  "ObjectType": 0,
  "SealedSubclassFullyQualifiedNames": null,
  "SuperTypeIds": null,
  "SuperTypes": {
    "$id": "16",
    "$values": [
      {
        "$id": "17",
        "Arguments": {
          "$id": "18",
          "$values": []
        },
        "Nullable": false,
        "FlexibleTypeCapabilitiesId": null,
        "FlexibleUpperBound": null,
        "FlexibleUpperBoundId": 0,
        "ClassName": "android/widget/FrameLayout;",
        "TypeParameter": null,
        "TypeParameterName": null,
        "TypeAliasName": null,
        "OuterType": null,
        "OuterTypeId": null,
        "AbbreviatedType": null,
        "AbbreviatedTypeId": null,
        "Flags": 0
      }
    ]
  },
  "TypeParameters": {
    "$id": "19",
    "$values": []
  },
  "VersionRequirements": null,
  "Visibility": 3,
  "Functions": {
    "$id": "20",
    "$values": [
      ...
      {
        "$id": "145",
        "Name": "setOnEmojiPickedListener",
        "JvmName": "setOnEmojiPickedListener",
        "JvmSignature": null,
        "Flags": 6,
        "ReturnType": {
          "$id": "146",
          "Arguments": {
            "$id": "147",
            "$values": []
          },
          "Nullable": false,
          "FlexibleTypeCapabilitiesId": null,
          "FlexibleUpperBound": null,
          "FlexibleUpperBoundId": 0,
          "ClassName": "kotlin/Unit",
          "TypeParameter": null,
          "TypeParameterName": null,
          "TypeAliasName": null,
          "OuterType": null,
          "OuterTypeId": null,
          "AbbreviatedType": null,
          "AbbreviatedTypeId": null,
          "Flags": 0
        },
        "ReturnTypeId": 0,
        "TypeParameters": {
          "$id": "148",
          "$values": []
        },
        "ReceiverType": null,
        "ReceiverTypeId": 0,
        "TypeTable": null,
        "Contract": null,
        "ValueParameters": {
          "$id": "149",
          "$values": [
            {
              "$id": "150",
              "Flags": 0,
              "Name": "onEmojiPickedListener",
              "Type": {
                "$id": "151",
                "Arguments": {
                  "$id": "152",
                  "$values": [
                    {
                      "$id": "153",
                      "Projection": 2,
                      "Type": {
                        "$id": "154",
                        "Arguments": {
                          "$id": "155",
                          "$values": []
                        },
                        "Nullable": false,
                        "FlexibleTypeCapabilitiesId": null,
                        "FlexibleUpperBound": null,
                        "FlexibleUpperBoundId": 0,
                        "ClassName": "androidx/emoji2/emojipicker/EmojiViewItem;",
                        "TypeParameter": null,
                        "TypeParameterName": null,
                        "TypeAliasName": null,
                        "OuterType": null,
                        "OuterTypeId": null,
                        "AbbreviatedType": null,
                        "AbbreviatedTypeId": null,
                        "Flags": 0
                      },
                      "TypeId": 0
                    }
                  ]
                },
                "Nullable": true,
                "FlexibleTypeCapabilitiesId": null,
                "FlexibleUpperBound": null,
                "FlexibleUpperBoundId": 0,
                "ClassName": "androidx/core/util/Consumer;",
                "TypeParameter": null,
                "TypeParameterName": null,
                "TypeAliasName": null,
                "OuterType": null,
                "OuterTypeId": null,
                "AbbreviatedType": null,
                "AbbreviatedTypeId": null,
                "Flags": 0
              },
              "TypeId": 0,
              "VarArgElementType": null,
              "VarArgElementTypeId": 0
            }
          ]
        },
        "VersionRequirements": null
      },
  ...
  },
  "Properties": {... },
  "TypeAliases": {
    "$id": "230",
    "$values": []
  },
  "TypeTable": null,
  "VersionRequirementTable": {
    "$id": "231",
    "Requirements": {
      "$id": "232",
      "$values": [
        {
          "$id": "233",
          "Version": 25,
          "VersionFull": 0,
          "Level": 1,
          "ErrorCode": 0,
          "Message": 0,
          "VersionKind": 0
        }
      ]
    }
  }
}

Kotlin Metadata String Table:
[
  "Landroidx/emoji2/emojipicker/EmojiPickerView;",
  "Landroid/widget/FrameLayout;",
  "context",
  "Landroid/content/Context;",
  "attrs",
  "Landroid/util/AttributeSet;",
  "defStyleAttr",
  "",
  "(Landroid/content/Context;Landroid/util/AttributeSet;I)V",
  "_emojiGridRows",
  "",
  "Ljava/lang/Float;",
  "bodyAdapter",
  "Landroidx/emoji2/emojipicker/EmojiPickerBodyAdapter;",
  "value",
  "emojiGridColumns",
  "getEmojiGridColumns",
  "()I",
  "setEmojiGridColumns",
  "(I)V",
  "emojiGridRows",
  "getEmojiGridRows",
  "()F",
  "setEmojiGridRows",
  "(F)V",
  "emojiPickerItems",
  "Landroidx/emoji2/emojipicker/EmojiPickerItems;",
  "onEmojiPickedListener",
  "Landroidx/core/util/Consumer;",
  "Landroidx/emoji2/emojipicker/EmojiViewItem;",
  "recentEmojiProvider",
  "Landroidx/emoji2/emojipicker/RecentEmojiProvider;",
  "recentItemGroup",
  "Landroidx/emoji2/emojipicker/ItemGroup;",
  "recentItems",
  "",
  "Landroidx/emoji2/emojipicker/EmojiViewData;",
  "recentNeedsRefreshing",
  "",
  "scope",
  "Lkotlinx/coroutines/CoroutineScope;",
  "stickyVariantProvider",
  "Landroidx/emoji2/emojipicker/StickyVariantProvider;",
  "addView",
  "",
  "child",
  "Landroid/view/View;",
  "params",
  "Landroid/view/ViewGroup$LayoutParams;",
  "index",
  "width",
  "height",
  "buildEmojiPickerItems",
  "buildEmojiPickerItems$emoji2_emojipicker_release",
  "createEmojiPickerBodyAdapter",
  "refreshRecent",
  "refreshRecent$emoji2_emojipicker_release",
  "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;",
  "removeAllViews",
  "removeView",
  "removeViewAt",
  "removeViewInLayout",
  "removeViews",
  "start",
  "count",
  "removeViewsInLayout",
  "setOnEmojiPickedListener",
  "setRecentEmojiProvider",
  "showEmojiPickerView",
  "Companion",
  "emoji2-emojipicker_release"
]

@jpobst jpobst marked this pull request as ready for review October 16, 2023 19:00
All writes should go through `output.`, not `Console`, so that `class-parse -o FILE` works properly.

Re-indent various pieces of code.

Update JSON printing so that it starts on the same line as the "header", a'la

```
Kotlin Class Metadata [1.8.0]: {
  "$id": "1",
  …
}
```
@jonpryor jonpryor merged commit 3c83179 into main Oct 16, 2023
@jonpryor jonpryor deleted the cp-kotlin-metadata branch October 16, 2023 23:09
jonpryor pushed a commit to dotnet/android that referenced this pull request Oct 17, 2023
Changes: dotnet/java-interop@ed63d89...3c83179

  * dotnet/java-interop@3c831796: [class-parse] Add Kotlin metadata to `-dump`. (dotnet/java-interop#1150)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
jonathanpeppers pushed a commit to dotnet/android that referenced this pull request Oct 17, 2023
Changes: dotnet/java-interop@ed63d89...3c83179

  * dotnet/java-interop@3c831796: [class-parse] Add Kotlin metadata to `-dump`. (dotnet/java-interop#1150)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants