Conversation
…iables
AnnotationTemplateGenerator hardcoded Java syntax for the dummy method
(" void $method() {}") and dummy variable (" int $variable;") that
annotation template stubs attach to, so any KotlinTemplate applied with
annotation coordinates (e.g. replaceArguments()) on a method or property
produced a stub the Kotlin parser rejects:
Could not parse as Java:
class Test{/*__TEMPLATE__*/@example("RedundantSuppression")
void $method() {}}
Extract the stubs into protected hooks (addDummyMethod, addDummyVariable,
variable()) alongside the existing addDummyClass/addDummyAnnotationType
from #6522, and override them in KotlinAnnotationTemplateGenerator with
Kotlin syntax. The stub fragments are concatenated on a single line with
an appended `return ...;` when the enclosing function has a return type,
so the Kotlin stubs carry explicit `;` terminators.
timtebeek
approved these changes
Jul 6, 2026
timtebeek
left a comment
Member
There was a problem hiding this comment.
Good to fix this generically, thanks!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's changed?
AnnotationTemplateGeneratorhardcoded Java syntax for the dummy declarations that annotation template stubs attach to (void $method() {}andint $variable;). This change extracts them into protected hooks —addDummyMethod(StringBuilder),addDummyVariable(StringBuilder), and thevariable()helper — alongside the existingaddDummyClass/addDummyAnnotationTypehooks from #6522, and overrides them inKotlinAnnotationTemplateGeneratorwith Kotlin syntax.What's your motivation?
Any
KotlinTemplateapplied with annotation coordinates (e.g.annotation.getCoordinates().replaceArguments()) on a method or property failed, because the generated stub mixed Java member syntax into a Kotlin source:Two subtleties beyond the plain syntax swap:
return ...;is appended when the enclosing function declares a return type — so the Kotlin stubs need explicit;terminators (val `$variable`: Int = 0;), otherwise a localvalannotation insidefun foo(): Intproduced the unparseableval `$variable`: Int = 0return null;.variable()(used to stub out locals that precede the templated annotation) emitted Java declaration order (Int y;); the Kotlin override emitsval y: Int.Base implementations keep byte-identical output, so Java and Groovy templates are unaffected.
Anything in particular you'd like reviewers to focus on?
ScalaAnnotationTemplateGeneratorhas the same latent gap (it still inherits the Java method/variable stubs), left for a follow-up since rewrite-scala has no annotation-template test coverage yet.val(with enclosing return type, and preceded by a typed local), parameter substitution (#{any()}), and cursor-at-declaration viaaddAnnotation.Checklist