Skip to content

[ffigen] [jnigen] Util to dump entire parsed API - #3621

Open
amanmaurya92 wants to merge 1 commit into
dart-lang:mainfrom
amanmaurya92:feat/dump-api-3605
Open

amanmaurya92 wants to merge 1 commit into
dart-lang:mainfrom
amanmaurya92:feat/dump-api-3605

Conversation

@amanmaurya92

@amanmaurya92 amanmaurya92 commented Sep 8, 2026 •

Copy link
Copy Markdown

Description

When configuring FFIgen or JNIgen, users frequently encounter scenarios where expected API elements do not appear in the generated bindings (due to incorrect entry point headers, missing include paths, preprocessor flags, or misconfigured filters). Diagnosing this previously required users to construct custom AST visitor debug scripts from scratch.

This PR introduces a standardized AST dumping utility:

  • Adds ApiDumperVisitor to package:ffigen to traverse and format all public AST declarations into a clear, greppable format (Node(name, USR/parent)).
  • Adds dumpApi({StringSink? sink, Logger? logger, Uri? libclangDylib}) extension method on FfiGenerator that parses headers without writing output binding files.
  • Adds matching ApiDumperVisitor and dumpApi({StringSink? sink, Logger? logger}) on JniGenerator in package:jnigen to dump Java classes, methods, parameters, and fields.
  • Adds comprehensive unit tests in both pkgs/ffigen and pkgs/jnigen covering synthetic AST node dumping and end-to-end header parsing.
  • Updates CHANGELOG.md for both packages.

Related Issues

Fixes #3605

PR Checklist

  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
  • I've run dart tool/ci.dart --all locally and resolved all issues identified. This ensures the PR is formatted, has no lint errors, and ran all code generators. This applies to the packages part of the toplevel pubspec.yaml workspace.
  • All existing and new tests are passing. I added new tests to check the change I am making.
  • The PR is actually solving the issue. PRs that don't solve the issue will be closed. Please be respectful of the maintainers' time. If it's not clear what the issue is, feel free to ask questions on the GitHub issue before submitting a PR.
  • I have updated CHANGELOG.md for the relevant packages. (Not needed for small changes such as doc typos).
  • I have updated the pubspec package version if necessary.

Comment thread pkgs/ffigen/lib/src/config_provider/api_dumper.dart Outdated
Comment thread pkgs/ffigen/lib/src/config_provider/api_dumper.dart Outdated
Comment thread pkgs/ffigen/lib/src/config_provider/config.dart
Comment thread pkgs/ffigen/lib/src/ffigen.dart Outdated
Comment thread pkgs/ffigen/CHANGELOG.md Outdated
Comment thread pkgs/jnigen/lib/src/elements/api_dumper.dart Outdated
Comment thread pkgs/jnigen/lib/src/elements/api_dumper.dart Outdated
Comment thread pkgs/jnigen/lib/src/elements/api_dumper.dart Outdated
@amanmaurya92 amanmaurya92 changed the title [ffigen][jnigen] Util to dump entire parsed API [ffigen] [jnigen] Util to dump entire parsed API Sep 10, 2026
@amanmaurya92

Copy link
Copy Markdown
Author

@liamappelbe all CI are green now, please merge this, as this is my first pr here 😄. I appreciate your guidance.

@liamappelbe liamappelbe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there. Just a few more details.

/// Whether this method is a constructor.
bool get isConstructor => _method.isConstructor;

/// The method descriptor (e.g. `(Ljava/lang/String;)V`), if available.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems unrelated?

If you want to include it, it'll need a changelog entry. I'm also wondering why it's nullable. Under what circumstances would the descriptor not be available? It'll also need a test (for both the non-null and null cases). And at that point it should probably be a separate PR.

///
/// Returns the formatted dump string.
Future<String> dumpApi({Logger? logger}) async {
logger ??= createDefaultLogger();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of this function duplicates line 67-96 of generate. Can you factor out the logic into a helper? Looks like the helper could just take a Logger? and return userClasses.

Comment thread pkgs/jnigen/CHANGELOG.md
- Allow interface mixin names to be customized using the visitor API.
- Support customizing the command `java -jar ApiSummarizer.jar` via the
`summarizer.command` field in config.
- Add `dumpApi` utility and `ApiDumperVisitor` to dump parsed Java AST.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to the changelog entry for 1.0.1-wip, and bump it to 1.1.0-wip. You'll also need to update the jnigen pubspec, and I think there's a const variable somewhere in jnigen that holds the version too.

As of #3627, you at least won't need to update all the bindings files 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ffigen][jnigen] Util to dump entire parsed API

2 participants