summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriter.java10
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaExpression.java2
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaUnsignedRightShift.java40
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java12
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaUnsignedRightShiftMatcher.java45
5 files changed, 108 insertions, 1 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriter.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriter.java
index be48e42..e512650 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriter.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriter.java
@@ -273,6 +273,10 @@ public class JavaWriter implements AutoCloseable {
case JavaStringLiteral stringLiteral -> {
writeStringLiteral(stringLiteral);
}
+
+ case JavaUnsignedRightShift unsignedRightShift -> {
+ writeUnsignedRightShift(unsignedRightShift);
+ }
}
}
@@ -567,6 +571,12 @@ public class JavaWriter implements AutoCloseable {
}
}
+ private void writeUnsignedRightShift(JavaUnsignedRightShift unsignedRightShift) throws IOException {
+ this.writeExpression(unsignedRightShift.left());
+ this.writer.write(" >>> ");
+ this.writeExpression(unsignedRightShift.right());
+ }
+
private void writeVisibility(JavaVisibility visibility) throws IOException {
this.writer.write(switch (visibility) {
case PUBLIC -> "public";
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaExpression.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaExpression.java
index 00a491e..7e9cdad 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaExpression.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaExpression.java
@@ -5,7 +5,7 @@ package org.zwobble.hobgoblin.compiler.output.lang.java.ast;
// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression imports
// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression imports
-public sealed interface JavaExpression permits org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaAssignment, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaBooleanLiteral, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaFieldAccess, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaIntegerLiteral, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaMethodCall, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaMethodRef, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaNewExpression, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaNullLiteral, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRef, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaStaticFieldAccess, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaStaticMethodCall, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaStringLiteral {
+public sealed interface JavaExpression permits org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaAssignment, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaBooleanLiteral, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaFieldAccess, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaIntegerLiteral, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaMethodCall, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaMethodRef, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaNewExpression, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaNullLiteral, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRef, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaStaticFieldAccess, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaStaticMethodCall, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaStringLiteral, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift {
public interface Builder {
public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression build();
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaUnsignedRightShift.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaUnsignedRightShift.java
new file mode 100644
index 0000000..aced126
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaUnsignedRightShift.java
@@ -0,0 +1,40 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.java.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift imports
+
+public record JavaUnsignedRightShift(org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression left, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression right) implements org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression {
+ public static org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift.Builder arbitrary() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift.Builder(org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaBooleanLiteral.arbitrary().build(), org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaBooleanLiteral.arbitrary().build());
+ }
+
+ public record Builder(org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression left, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression right) implements org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression.Builder {
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift build() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift(left, right);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift.Builder withLeft(org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression left) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift.Builder(left, right);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift.Builder withLeft(org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression.Builder left) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift.Builder(left.build(), right);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift.Builder withRight(org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression right) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift.Builder(left, right);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift.Builder withRight(org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression.Builder right) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift.Builder(left, right.build());
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift body
+}
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 aa0dc96..ff374fb 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
@@ -905,6 +905,18 @@ public class JavaWriterTests {
}
@Test
+ public void unsignedRightShift() throws IOException {
+ var java = JavaUnsignedRightShift.arbitrary()
+ .withLeft(JavaRef.arbitrary().withName(JavaIdentifier.of("x")))
+ .withRight(JavaRef.arbitrary().withName(JavaIdentifier.of("y")))
+ .build();
+
+ var string = write(writer -> writer.writeExpression(java));
+
+ assertThat(string, equalTo("x >>> y"));
+ }
+
+ @Test
public void typeRefWithoutArgsHasNoAngleBrackets() throws IOException {
var java = JavaTypeRef.topLevel(
JavaPackageName.of("abc", "def"),
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaUnsignedRightShiftMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaUnsignedRightShiftMatcher.java
new file mode 100644
index 0000000..7da71c1
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaUnsignedRightShiftMatcher.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.JavaUnsignedRightShiftMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShiftMatcher imports
+
+public class JavaUnsignedRightShiftMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShiftMatcher isJavaUnsignedRightShift() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShiftMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift>> submatchers;
+
+ private JavaUnsignedRightShiftMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift>> 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<java.lang.Object> toMatcher() {
+ return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShiftMatcher withLeft(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression> left) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("left", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift::left, left));
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShiftMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShiftMatcher withRight(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression> right) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("right", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShift::right, right));
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShiftMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShiftMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaUnsignedRightShiftMatcher body
+}