diff options
Diffstat (limited to 'src/test/java')
2 files changed, 26 insertions, 0 deletions
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 @@ -791,6 +791,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 <T1, T2> void a() { + }""" + )); + } + + @Test public void methodWithParams() throws IOException { var java = JavaMethodDeclaration.arbitrary() .withName(JavaIdentifier.of("a")) 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<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTypeParameter>> typeParameters) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaMethodDeclaration>>(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<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTypeRef> returnType) { var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaMethodDeclaration>>(this.submatchers); submatchers.add(org.zwobble.precisely.Matchers.has("returnType", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaMethodDeclaration::returnType, returnType)); |
