From a8f916ed81731eaba61b2bd1ef6f3b6fb40c23af Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 12 Jul 2026 17:43:27 +0100 Subject: Add postfix expressions to Java AST --- .../compiler/output/lang/java/JavaWriterTests.java | 26 +++++++++++++ .../java/ast/JavaPostfixExpressionMatcher.java | 45 ++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaPostfixExpressionMatcher.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 b8bfe5c..8eb738a 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 @@ -1372,6 +1372,32 @@ public class JavaWriterTests { assertThat(string, equalTo("null")); } + // === Postfix expressions === + + @Test + public void postfixDecrement() throws IOException { + var java = JavaPostfixExpression.arbitrary() + .withOperator(JavaPostfixOperator.DECREMENT) + .withOperand(JavaRef.arbitrary().withName(JavaIdentifier.of("x"))) + .build(); + + var string = write(writer -> writer.writeTopLevelExpression(java)); + + assertThat(string, equalTo("x--")); + } + + @Test + public void postfixIncrement() throws IOException { + var java = JavaPostfixExpression.arbitrary() + .withOperator(JavaPostfixOperator.INCREMENT) + .withOperand(JavaRef.arbitrary().withName(JavaIdentifier.of("x"))) + .build(); + + var string = write(writer -> writer.writeTopLevelExpression(java)); + + assertThat(string, equalTo("x++")); + } + // === Refs === @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaPostfixExpressionMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaPostfixExpressionMatcher.java new file mode 100644 index 0000000..2a0cb13 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaPostfixExpressionMatcher.java @@ -0,0 +1,45 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.java.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpressionMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpressionMatcher imports + +public class JavaPostfixExpressionMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpressionMatcher isJavaPostfixExpression() { + return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpressionMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private JavaPostfixExpressionMatcher(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.JavaPostfixExpression.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpressionMatcher withOperator(org.zwobble.precisely.Matcher operator) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("operator", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpression::operator, operator)); + return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpressionMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpressionMatcher withOperand(org.zwobble.precisely.Matcher operand) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("operand", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpression::operand, operand)); + return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpressionMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpressionMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpressionMatcher body +} -- cgit v1.2.3