Skip to content

Add Kotlin test coverage for AddCommentToMethodInvocations#8165

Merged
MBoegers merged 1 commit into
mainfrom
cri-2673
Jul 3, 2026
Merged

Add Kotlin test coverage for AddCommentToMethodInvocations#8165
MBoegers merged 1 commit into
mainfrom
cri-2673

Conversation

@MBoegers

@MBoegers MBoegers commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

What's changed?

Test-only change:

  • rewrite-kotlin: a Kotlin counterpart to AddCommentToMethodInvocationsTest proving the recipe adds a comment to a Kotlin method invocation and stays idempotent when an equivalent line or block comment already exists.
  • rewrite-core: a Comments trait test pinning that a source file whose language registers no CommentService is a hard UnsupportedOperationException, not a silent skip, and that the trait requires a cursor rooted at a SourceFile.

What's your motivation?

A customer running org.openrewrite.java.AddCommentToMethodInvocations against Kotlin sources hit:

java.lang.UnsupportedOperationException: Service class org.openrewrite.internal.CommentService not supported
  org.openrewrite.kotlin.tree.K$CompilationUnit.service(K.java:363)
  org.openrewrite.trait.Comments.service(Comments.java:169)
  • (moderneinc/customer-requests#2673)

  • Since Create a Comments trait to make it easy to add formatted comments to LST elements. #8131, JavaSourceFile.service() resolves CommentService to JavaCommentService, and K.CompilationUnit.service() falls back to it — so Kotlin (like Groovy) is served by the shared J-model implementation and the failure no longer reproduces on a coherent 8.86.0+ classpath. The crash only occurs when an older rewrite-java is mixed with a newer rewrite-core/rewrite-kotlin. These tests pin the working behavior so it cannot regress, and document that erroring out (rather than silently skipping) is the intended contract for languages without a CommentService.

Anyone you would like to review specifically?

@timtebeek

Kotlin sources resolve the CommentService through
K.CompilationUnit.service(), which falls back to
JavaSourceFile.service() providing JavaCommentService since 8.86.0.
These tests pin that AddCommentToMethodInvocations adds comments to
Kotlin method invocations (and stays idempotent), and that the
Comments trait intentionally errors out on source files whose
language registers no CommentService.
@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite Jul 3, 2026
@MBoegers MBoegers merged commit a2c651d into main Jul 3, 2026
1 check passed
@MBoegers MBoegers deleted the cri-2673 branch July 3, 2026 14:21
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants