diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-08-10 10:28:42 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-08-10 10:28:42 +0100 |
| commit | d049a89e2e5ff0b52519f37502dbf0c17cb9455f (patch) | |
| tree | 994056a0e8e70d2ecc541b2bc189fefc397fe110 /src/test/java/org | |
| parent | db1ae9e80a9b330f399f5bdbff8ee402d41a9f0e (diff) | |
Add type parameters to record declaration in Java AST
Diffstat (limited to 'src/test/java/org')
2 files changed, 34 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 75a57a6..e8556bc 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 @@ -395,6 +395,7 @@ public class JavaWriterTests { List.of(), List.of(), List.of(), + List.of(), DocComment.EMPTY ); @@ -415,6 +416,7 @@ public class JavaWriterTests { List.of(), List.of(), List.of(), + List.of(), new DocComment("A 2D point.") ); @@ -430,10 +432,33 @@ public class JavaWriterTests { } @Test + public void recordDeclarationWithTypeParams() throws IOException { + var java = JavaRecordDeclaration.arbitrary() + .withType(JavaTypeRef.topLevel(JavaPackageName.EMPTY, JavaIdentifier.of("X"))) + .addTypeParameter(JavaTypeParameter.arbitrary() + .withName(JavaIdentifier.of("T1")) + ) + .addTypeParameter(JavaTypeParameter.arbitrary() + .withName(JavaIdentifier.of("T2")) + ) + .build(); + + var string = write(writer -> writer.writeTypeDeclaration(java)); + + assertThat(string, equalTo(""" + public record X<T1, T2>() { + // Custom area start: X body + // Custom area end: X body + }""" + )); + } + + @Test public void recordDeclarationImplementingOneInterface() throws IOException { var java = new JavaRecordDeclaration( JavaTypeRef.topLevel(JavaPackageName.EMPTY, JavaIdentifier.of("Rectangle")), List.of(), + List.of(), List.of( JavaTypeRef.topLevel(JavaPackageName.of("com", "example"), JavaIdentifier.of("Shape")) ), @@ -456,6 +481,7 @@ public class JavaWriterTests { var java = new JavaRecordDeclaration( JavaTypeRef.topLevel(JavaPackageName.EMPTY, JavaIdentifier.of("Rectangle")), List.of(), + List.of(), List.of( JavaTypeRef.topLevel(JavaPackageName.of("com", "example"), JavaIdentifier.of("Shape")), JavaTypeRef.topLevel(JavaPackageName.of("com", "example"), JavaIdentifier.of("Drawable")) @@ -480,6 +506,7 @@ public class JavaWriterTests { JavaTypeRef.topLevel(JavaPackageName.EMPTY, JavaIdentifier.of("Rectangle")), List.of(), List.of(), + List.of(), List.of( JavaMethodDeclaration.arbitrary() .withName(JavaIdentifier.of("a")) @@ -1851,6 +1878,7 @@ public class JavaWriterTests { List.of(), List.of(), List.of(), + List.of(), DocComment.EMPTY ); diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaRecordDeclarationMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaRecordDeclarationMatcher.java index 56ac030..8661a62 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaRecordDeclarationMatcher.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaRecordDeclarationMatcher.java @@ -36,6 +36,12 @@ public final class JavaRecordDeclarationMatcher implements org.zwobble.precisely return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRecordDeclarationMatcher(submatchers); } + public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRecordDeclarationMatcher 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.JavaRecordDeclaration>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("typeParameters", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRecordDeclaration::typeParameters, typeParameters)); + return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRecordDeclarationMatcher(submatchers); + } + public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRecordDeclarationMatcher withComponents(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRecordComponent>> components) { var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRecordDeclaration>>(this.submatchers); submatchers.add(org.zwobble.precisely.Matchers.has("components", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRecordDeclaration::components, components)); |
