summaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-05-23 11:31:02 +0100
committerMichael Williamson <mike@zwobble.org>2026-05-23 11:31:02 +0100
commit4575cd222aa78442d41373b710be0640b24871c5 (patch)
treeeb9bce51dd0b3ec617228104dd72dff4ff4851aa /src/main/java/org
parentc7fbd6c9fdc3fe140b0f1ff713855ab3a3ad599e (diff)
Write custom area delimiters
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriter.java46
1 files changed, 28 insertions, 18 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 89c3aa0..ff8171a 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
@@ -77,17 +77,16 @@ public class JavaWriter implements AutoCloseable {
this.writer.write(" {");
this.writer.indent();
- writeWithSeparator(
- classDeclaration.body(),
- bodyDeclaration -> {
- writer.newLine();
- writeClassBodyDeclaration(bodyDeclaration);
- },
- () -> writer.newLine()
- );
+ for (var bodyDeclaration: classDeclaration.body()) {
+ writer.newLine();
+ writeClassBodyDeclaration(bodyDeclaration);
+ writer.newLine();
+ }
- this.writer.dedent();
this.writer.newLine();
+ this.writeCustomArea("body", classDeclaration.customArea());
+
+ this.writer.dedent();
this.writer.write("}");
}
@@ -103,6 +102,15 @@ public class JavaWriter implements AutoCloseable {
}
}
+ private void writeCustomArea(String name, JavaCustomArea javaCustomArea) throws IOException {
+ this.writer.write("// Custom area start: ");
+ this.writer.write(name);
+ this.writer.newLine();
+ this.writer.write("// Custom area end: ");
+ this.writer.write(name);
+ this.writer.newLine();
+ }
+
void writeExpression(JavaExpression expression) throws IOException {
switch (expression) {
case JavaIntegerLiteral integerLiteral -> {
@@ -149,7 +157,10 @@ public class JavaWriter implements AutoCloseable {
}
this.writer.write("{");
+ this.writer.indent();
this.writer.newLine();
+ this.writeCustomArea("body", interfaceDeclaration.customArea());
+ this.writer.dedent();
this.writer.write("}");
}
@@ -247,17 +258,16 @@ public class JavaWriter implements AutoCloseable {
this.writer.write("{");
this.writer.indent();
- writeWithSeparator(
- recordDeclaration.body(),
- bodyDeclaration -> {
- writer.newLine();
- writeClassBodyDeclaration(bodyDeclaration);
- },
- () -> writer.newLine()
- );
+ for (var bodyDeclaration : recordDeclaration.body()) {
+ writer.newLine();
+ writeClassBodyDeclaration(bodyDeclaration);
+ writer.newLine();
+ }
- this.writer.dedent();
this.writer.newLine();
+ this.writeCustomArea("body", recordDeclaration.customArea());
+
+ this.writer.dedent();
this.writer.write("}");
}