[jnigen] Propagate Javadoc deprecation messages#3475
Conversation
PR HealthChangelog Entry ✔️
Changes to files need to be accounted for in their respective changelogs. This check can be disabled by tagging the PR with API leaks ✔️The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
This check can be disabled by tagging the PR with Breaking changes ✔️
This check can be disabled by tagging the PR with |
liamappelbe
left a comment
There was a problem hiding this comment.
Sorry for the slow review. I was pretty swamped last week. Since this is hard to cover with integration tests, and deprecatedMessage is a pretty fiddly little function, it's a good candidate for a unit test. You can just add a new test file directly in pkgs/jnigen/test. Construct a bunch of synthetic JavaDocComment objects, and make sure the deprecatedMessage returns the right answer across all edge cases.
|
To fix this error, you'll either need to:
|
|
Can you also add a CHANGELOG entry? I forgot to ask for this in the previous PR. |
|
Thanks! I've added the unit tests, moved the jsonEncode logic into deprecatedMessage, and added a CHANGELOG entry. |
| final message = messageLines.join('\n').trim(); | ||
| if (message.isEmpty) return null; | ||
|
|
||
| final encoded = jsonEncode(message); |
There was a problem hiding this comment.
We should probably roll our own Dart string escaper, rather than relying on this JSON encoding trick. It's sort of a coincidence that JSON uses mostly the same escape characters as Dart. In fact there are some small differences in the escaping rules that are leading to test failures like this. It'd be better to write (and unit test) a dedicated function for this.
You may also need to regenerate the bindings for that test, to fix this failure. Try tool/regenerate_all_bindings.dart. That tool can be a bit problematic to run, so let me know if you have issues with it (eg errors, or spurious diffs) and I can regerenate the bindings for you on my machine.
|
Thanks! I'll implement a dedicated Dart string escaper and add unit tests. Just to make sure I match your expectations: do you have a preferred set of escape rules in mind (or an existing helper in the repo I should follow), or should I implement a minimal escaper that emits valid single-quoted Dart string literals and expand it if tests require additional cases? |
I think it's just |
|
Thanks a lot for the help! I moved the escaping logic into dart_generator.dart with a dedicated escapeDartString helper and added unit tests covering the escaping behavior. I regenerated the existing Jackson test bindings instead of running regenerate_all_bindings.dart to keep the diff focused, since the full regeneration produced many unrelated changes. |
|
@Siya-05 I don't see any new changes. Did you forget to push? |
|
Sorry about that! I missed the push error on my end yesterday. I've pushed the latest changes now. |
Description
This PR is a follow-up to #3429 and addresses part of #2796.
The previous PR generated Dart
@Deprecatedannotations for Java methods annotated withjava.lang.Deprecated, using a generic deprecation message.This PR propagates the Java
@deprecatedJavadoc message into the generated Dart@Deprecated(...)annotation when bindings are generated with the doclet backend, providing developers with the original deprecation guidance from the Java source.When Javadocs are unavailable (for example, when using the ASM backend), the generator continues to fall back to the generic
"This Java method is deprecated."message.Changes
JavaDocComment.deprecatedMessagehelper to extract the@deprecatedJavadoc message.@Deprecated(...)annotations using the extracted Javadoc message when available.simple_packagetest fixture with a Javadoc deprecation message.Related Issues
Addresses part of #2796.
PR Checklist
dart tool/ci.dart --alllocally 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 toplevelpubspec.yamlworkspace.@deprecatedJavadoc message into generated Dart@Deprecated(...)annotations.CHANGELOG.mdfor the relevant packages. (Not needed for small changes such as doc typos.)