Skip to content

Fix KotlinTemplate building for annotations#6522

Merged
Laurens-W merged 5 commits intomainfrom
fix-kotlin-template-for-annotations
Jan 13, 2026
Merged

Fix KotlinTemplate building for annotations#6522
Laurens-W merged 5 commits intomainfrom
fix-kotlin-template-for-annotations

Conversation

@Laurens-W
Copy link
Contributor

@Laurens-W Laurens-W commented Jan 13, 2026

What's changed?

Introduces extensibility to the AnnotationTemplateGenerator so that other languages (like Kotlin) can intercept certain steps
Introduced Kotlin specific AnnotationTemplateGenerator so that KotlinTemplate can create valid snippets for annotations

What's your motivation?

AddMockitoExtensionIfAnnotationsUsed currently adds the annotation with a Java style class reference, I'm working on expanding that to work for Kotlin

Any additional context

Without this change a KotlinTemplate like this KotlinTemplate.builder("@ExtendWith(MockitoExtension::class)") will complain about the $ before Class and Placeholder

\607541286333800\openRewriteFile.kt:6:7: error: name expected
class $Clazz {}
      ^
\607541286333800\openRewriteFile.kt:7:1: error: expected annotation identifier after '@'
@interface $Placeholder {}
^
\607541286333800\openRewriteFile.kt:7:12: error: name expected
@interface $Placeholder {}
           ^

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

…eGenerator so that KotlinAnnotationTemplateGenerator can build up a valid template
@Laurens-W Laurens-W self-assigned this Jan 13, 2026
@Laurens-W Laurens-W added the enhancement New feature or request label Jan 13, 2026
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Jan 13, 2026
Copy link
Member

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me, thanks! Added a very small comment; the class itself is already in an internal package, but still we've seen that's not always stopping folks.

@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Jan 13, 2026
@Laurens-W Laurens-W merged commit b451613 into main Jan 13, 2026
2 checks passed
@Laurens-W Laurens-W deleted the fix-kotlin-template-for-annotations branch January 13, 2026 14:11
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants