From 4b8dd80f18ae1e4bad0c61d55de685d69dfdbe1c Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 10 Aug 2026 10:47:26 +0100 Subject: Add type parameters to Java method declarations --- .../compiler/output/lang/java/JavaWriterTests.java | 20 ++++++++++++++++++++ .../lang/java/ast/JavaMethodDeclarationMatcher.java | 6 ++++++ 2 files changed, 26 insertions(+) (limited to 'src/test') diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java index e8556bc..68be253 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java @@ -790,6 +790,26 @@ public class JavaWriterTests { )); } + @Test + public void methodWithTypeParams() throws IOException { + var java = JavaMethodDeclaration.arbitrary() + .withName(JavaIdentifier.of("a")) + .withVisibility(JavaVisibility.PUBLIC) + .withKind(JavaMemberKind.INSTANCE) + .addTypeParameter(JavaTypeParameter.arbitrary().withName(JavaIdentifier.of("T1"))) + .addTypeParameter(JavaTypeParameter.arbitrary().withName(JavaIdentifier.of("T2"))) + .withReturnType(JavaTypeRef.VOID) + .withBody(JavaBlock.EMPTY) + .build(); + + var string = write(writer -> writer.writeMethodDeclaration(java)); + + assertThat(string, equalTo(""" + public void a() { + }""" + )); + } + @Test public void methodWithParams() throws IOException { var java = JavaMethodDeclaration.arbitrary() diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaMethodDeclarationMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaMethodDeclarationMatcher.java index ca0b998..1bd0d6f 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaMethodDeclarationMatcher.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaMethodDeclarationMatcher.java @@ -48,6 +48,12 @@ public final class JavaMethodDeclarationMatcher implements org.zwobble.precisely return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaMethodDeclarationMatcher(submatchers); } + public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaMethodDeclarationMatcher withTypeParameters(org.zwobble.precisely.Matcher> typeParameters) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("typeParameters", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaMethodDeclaration::typeParameters, typeParameters)); + return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaMethodDeclarationMatcher(submatchers); + } + public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaMethodDeclarationMatcher withReturnType(org.zwobble.precisely.Matcher returnType) { var submatchers = new java.util.ArrayList>(this.submatchers); submatchers.add(org.zwobble.precisely.Matchers.has("returnType", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaMethodDeclaration::returnType, returnType)); -- cgit v1.2.3