summaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-06-19 18:27:41 +0100
committerMichael Williamson <mike@zwobble.org>2026-06-19 18:27:41 +0100
commit64344428233e3ed4250477b52f5eb560e168c29b (patch)
tree7d2f4e049a798bd91de7da679112a915ca0d1acc /src/main/java/org/zwobble
parent4a50855f064f0744a0e4b03cb505271880589936 (diff)
Add Java enum declarations
Diffstat (limited to 'src/main/java/org/zwobble')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriter.java30
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaEnumConstant.java25
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaEnumDeclaration.java41
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaTypeDeclaration.java2
4 files changed, 97 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 0299a31..0e5fd92 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
@@ -61,6 +61,10 @@ public class JavaWriter implements AutoCloseable {
writeClassDeclaration(classDeclaration);
}
+ case JavaEnumDeclaration enumDeclaration -> {
+ writeEnumDeclaration(enumDeclaration);
+ }
+
case JavaInterfaceDeclaration interfaceDeclaration -> {
writeInterfaceDeclaration(interfaceDeclaration);
}
@@ -181,6 +185,32 @@ public class JavaWriter implements AutoCloseable {
this.writer.writeCustomArea(customAreaName.toString());
}
+ private void writeEnumDeclaration(JavaEnumDeclaration enumDeclaration) throws IOException {
+ this.writeDocComment(enumDeclaration.docComment());
+ this.writer.write("public enum ");
+ this.writer.write(enumDeclaration.name());
+ this.writer.write(" {");
+ this.writer.indent();
+ this.writer.newLine();
+
+ if (!enumDeclaration.constants().isEmpty()) {
+ writeWithSeparator(
+ enumDeclaration.constants(),
+ constant -> this.writer.write(constant.name()),
+ () -> {
+ this.writer.write(",");
+ this.writer.newLine();
+ }
+ );
+ this.writer.newLine();
+ this.writer.newLine();
+ }
+
+ this.writeCustomArea(enumDeclaration.customArea());
+ this.writer.dedent();
+ this.writer.write("}");
+ }
+
void writeExpression(JavaExpression expression) throws IOException {
switch (expression) {
case JavaAssignment assignment -> {
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaEnumConstant.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaEnumConstant.java
new file mode 100644
index 0000000..6e7e775
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaEnumConstant.java
@@ -0,0 +1,25 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.java.ast;
+
+public record JavaEnumConstant(String name) {
+ public static org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstant.Builder arbitrary() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstant.Builder("");
+ }
+
+ public record Builder(String name) {
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstant build() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstant(name);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstant.Builder withName(String name) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstant.Builder(name);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstant.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstant.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstant body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstant body
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaEnumDeclaration.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaEnumDeclaration.java
new file mode 100644
index 0000000..dffd204
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaEnumDeclaration.java
@@ -0,0 +1,41 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.java.ast;
+
+public record JavaEnumDeclaration(String name, java.util.List<org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstant> constants, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaCustomArea customArea, org.zwobble.hobgoblin.compiler.ast.DocComment docComment) implements org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTypeDeclaration {
+ public static org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration.Builder arbitrary() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration.Builder("", java.util.List.of(), org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaCustomArea.arbitrary().build(), org.zwobble.hobgoblin.compiler.ast.Native.arbitraryDocComment());
+ }
+
+ public record Builder(String name, java.util.List<org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstant> constants, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaCustomArea customArea, org.zwobble.hobgoblin.compiler.ast.DocComment docComment) implements org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTypeDeclaration.Builder {
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration build() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration(name, constants, customArea, docComment);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration.Builder withName(String name) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration.Builder(name, constants, customArea, docComment);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration.Builder withConstants(java.util.List<org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstant> constants) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration.Builder(name, constants, customArea, docComment);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration.Builder withCustomArea(org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaCustomArea customArea) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration.Builder(name, constants, customArea, docComment);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration.Builder withCustomArea(org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaCustomArea.Builder customArea) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration.Builder(name, constants, customArea.build(), docComment);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration.Builder withDocComment(org.zwobble.hobgoblin.compiler.ast.DocComment docComment) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration.Builder(name, constants, customArea, docComment);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration body
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaTypeDeclaration.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaTypeDeclaration.java
index b4c5d49..93e3474 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaTypeDeclaration.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaTypeDeclaration.java
@@ -2,7 +2,7 @@
package org.zwobble.hobgoblin.compiler.output.lang.java.ast;
-public sealed interface JavaTypeDeclaration permits org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaClassDeclaration, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaInterfaceDeclaration, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRecordDeclaration {
+public sealed interface JavaTypeDeclaration permits org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaClassDeclaration, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaInterfaceDeclaration, org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRecordDeclaration {
public interface Builder {
public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTypeDeclaration build();