From 87fd2998a124e2455dd4d326f09a65cd0e82e720 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 2 Jul 2026 13:27:13 +0100 Subject: Add Java local variable declaration --- .../compiler/output/lang/java/JavaWriterTests.java | 12 +++++++ .../ast/JavaLocalVariableDeclarationMatcher.java | 41 ++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaLocalVariableDeclarationMatcher.java (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 cd74430..3967c2b 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 @@ -769,6 +769,18 @@ public class JavaWriterTests { assertThat(string, equalTo("42;")); } + @Test + public void localVariableDeclaration() throws IOException { + var java = JavaLocalVariableDeclaration.arbitrary() + .withName(JavaIdentifier.of("count")) + .withInitializer(new JavaIntegerLiteral(42)) + .build(); + + var string = write(writer -> writer.writeBlockStatement(java)); + + assertThat(string, equalTo("var count = 42;")); + } + @Test public void returnStatement() throws IOException { var java = new JavaReturn(new JavaIntegerLiteral(42)); diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaLocalVariableDeclarationMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaLocalVariableDeclarationMatcher.java new file mode 100644 index 0000000..24fa147 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaLocalVariableDeclarationMatcher.java @@ -0,0 +1,41 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.java.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclarationMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclarationMatcher imports + +public class JavaLocalVariableDeclarationMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclarationMatcher isJavaLocalVariableDeclaration() { + return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclarationMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private JavaLocalVariableDeclarationMatcher(java.util.List> submatchers) { + this.submatchers = submatchers; + } + + public org.zwobble.precisely.MatchResult match(java.lang.Object actual) { + return this.toMatcher().match(actual); + } + + public org.zwobble.precisely.TextTree describe() { + return this.toMatcher().describe(); + } + + private org.zwobble.precisely.Matcher toMatcher() { + return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclaration.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclarationMatcher withName(org.zwobble.precisely.Matcher name) { + return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclarationMatcher(java.util.stream.Stream.concat(this.submatchers.stream(), java.util.stream.Stream.of(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclaration::name, name))).toList()); + } + + public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclarationMatcher withInitializer(org.zwobble.precisely.Matcher initializer) { + return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclarationMatcher(java.util.stream.Stream.concat(this.submatchers.stream(), java.util.stream.Stream.of(org.zwobble.precisely.Matchers.has("initializer", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclaration::initializer, initializer))).toList()); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclarationMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclarationMatcher body +} -- cgit v1.2.3