Skip to content

[jnigen] Expose editable documentation on the visitor API #3496 - #3602

Open
AzazelSensei wants to merge 2 commits into
dart-lang:mainfrom
AzazelSensei:fix-3496-visitor-docs
Open

[jnigen] Expose editable documentation on the visitor API #3496#3602
AzazelSensei wants to merge 2 commits into
dart-lang:mainfrom
AzazelSensei:fix-3496-visitor-docs

Conversation

@AzazelSensei

Copy link
Copy Markdown

Description

The visitor API could rename or exclude members but not touch Javadoc. I exposed a documentation string on classes, methods, fields, and parameters so a visitor can replace, insert, or drop comments. If the new text has no @deprecated tag, the original one is still used for Dart @Deprecated.

Related Issues

Fixes #3496

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.

Visitors can replace, insert, or clear documentation on classes,
methods, fields, and parameters. Custom docs that omit @deprecated
still pick up the original tag for Dart @deprecated.

Fixes dart-lang#3496
if (GenerationStage.renamer <= until) {
cloned.finalName = finalName;
}
cloned.userDefinedName = userDefinedName;

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.

Match the logic in Method.clone: only clone the userDefined* things if GenerationStage.userVisitor <= until

import 'resolver.dart';
import 'visitor.dart';

JavaDocComment? _docsFor(JavaDocComment? original, String? userDefined) {

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.

It might be cleaner to store the user defined javadoc inside the JavaDocComment, rather than constructing all these temp JavaDocComment objects. Probably also makes sense to rename the field to JavaDocComment.userDefinedComment and rename JavaDocComment.comment to originalComment.

That would also let you simplify this pattern: _classDecl.userDefinedJavadoc ?? _classDecl.javadoc?.comment ?? ''. You could add a getter named comment that does userDefinedJavadoc ?? originalComment. Then that original pattern would become _classDecl.javadoc?.comment ?? ''`.

@liamappelbe

Copy link
Copy Markdown
Contributor

Analysis error is preventing the tests from running. Make sure to dart format and dart analyze before you push your changes. Saves a cycle of checking.

Keep originalComment and userDefinedComment on the same node so
the generator does not build throwaway copies. Param.clone now
copies userDefined fields only when the clone includes the user
visitor stage.

Fixes analyze prefer_const_constructors in the visitor docs test.
@AzazelSensei

Copy link
Copy Markdown
Author

Pushed a follow-up. Visitor docs now live on JavaDocComment as originalComment/userDefinedComment, Param.clone only copies userDefined fields when that stage is included, and the test uses a const Annotation so analyze is clean.

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 allow editing documentation

2 participants