From 3b93e3c4aac0911ef928a611f45f20669e6c553b Mon Sep 17 00:00:00 2001 From: Jordan Kiesel Date: Wed, 27 May 2026 21:18:08 -0600 Subject: [PATCH] fix: preserve annotations on generic method return types --- src/printers/classes.ts | 9 +++++++++ test/unit-test/generic_class/_input.java | 2 ++ test/unit-test/generic_class/_output.java | 2 ++ 3 files changed, 13 insertions(+) diff --git a/src/printers/classes.ts b/src/printers/classes.ts index d4b465c8c..d39c209a8 100644 --- a/src/printers/classes.ts +++ b/src/printers/classes.ts @@ -138,6 +138,15 @@ export default { declaration.push(group(path.call(print, "type_parametersNode")), " "); } + path.each(child => { + if ( + child.node.type === SyntaxType.Annotation || + child.node.type === SyntaxType.MarkerAnnotation + ) { + declaration.push(print(child), " "); + } + }, "children"); + declaration.push(path.call(print, "typeNode")); if (hasChild(path, "dimensionsNode")) { diff --git a/test/unit-test/generic_class/_input.java b/test/unit-test/generic_class/_input.java index 32532e09d..b05bef176 100644 --- a/test/unit-test/generic_class/_input.java +++ b/test/unit-test/generic_class/_input.java @@ -41,4 +41,6 @@ public class Foo { public void example(U u) {} public void example(U u) {} + + @Nullable T foo() {} } diff --git a/test/unit-test/generic_class/_output.java b/test/unit-test/generic_class/_output.java index 0ead5c3d6..2f3c354be 100644 --- a/test/unit-test/generic_class/_output.java +++ b/test/unit-test/generic_class/_output.java @@ -32,4 +32,6 @@ public class Foo { public void example(U u) {} public void example(U u) {} + + @Nullable T foo() {} }