Skip to content

[jnigen] Support renaming interface mixins - #3528

Open
Siya-05 wants to merge 1 commit into
dart-lang:mainfrom
Siya-05:jnigen-rename-interface-mixins
Open

[jnigen] Support renaming interface mixins#3528
Siya-05 wants to merge 1 commit into
dart-lang:mainfrom
Siya-05:jnigen-rename-interface-mixins

Conversation

@Siya-05

@Siya-05 Siya-05 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Description

Adds support for renaming generated interface mixins through the jnigen config visitor API while preserving the existing $ClassName default.

Custom names use the same identifier preprocessing and conflict resolution as other generated names and are used consistently in generated bindings.

Adds tests for renaming, name conflicts, and generated output.

Related Issues

Fixes #3495

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.

@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.

You've also got merge conflicts to resolve.

..._reservedTopLevelNames,
};
final Map<ClassDecl, Map<String, int>> nameCounts = {};
final Map<String, Map<String, int>> fileNameCounts = {};

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.

Ok, so it looks like before this change, we were making the assumption that we didn't need to resolve class name conflicts in singleFile mode. This was valid because there was only one user namable class in each file (since the interface mixin's name was based on the main class's name).

Now that the user can provide an arbitrary name for the interface mixin, there's a potential for a name conflict with the main class. So you added this extra map that is used to resolve those conflicts within files. This works, but is overcomplicated.

A simpler solution would be to delete uniquifyName and topLevelNameCounts, and have all top-level names go through fileNameCounts, regardless of what how many files we're outputting to.

While we're at it, fileNameCounts is a bit of an odd name, so call it topLevelNameCounts, like the map you just deleted.


final generatedFileNameCounts = uniquifyName
? topLevelNameCounts
: fileNameCounts.putIfAbsent(

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 putIfAbsent call feels like it should be in a little private util method on this class.

/// By default, the mixin for an interface named `Foo` is named `$Foo`.
String get interfaceMixinName =>
_classDecl.userDefinedInterfaceMixinName ??
'\$${_classDecl.userDefinedName ?? _classDecl.name}';

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.

I don't like this duplication of logic. It might get out of sync with the renamer. Better to just make this getter nullable.

@Siya-05
Siya-05 force-pushed the jnigen-rename-interface-mixins branch from c505921 to 65d1ad4 Compare August 13, 2026 03:39
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.

[jnigen] Config visitor API should support renaming interface mixins

2 participants