summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriter.java6
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java62
2 files changed, 68 insertions, 0 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 ff8171a..9f87e0f 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
@@ -106,6 +106,12 @@ public class JavaWriter implements AutoCloseable {
this.writer.write("// Custom area start: ");
this.writer.write(name);
this.writer.newLine();
+
+ for (var line : javaCustomArea.lines()) {
+ this.writer.write(line);
+ this.writer.newLine();
+ }
+
this.writer.write("// Custom area end: ");
this.writer.write(name);
this.writer.newLine();
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 5595b62..e13c3dd 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
@@ -73,6 +73,26 @@ public class JavaWriterTests {
}
@Test
+ public void classDeclarationWithCustomArea() throws IOException {
+ var java = new JavaClassDeclaration(
+ "Point",
+ List.of(),
+ new JavaCustomArea(List.of("// <custom area>")),
+ DocComment.EMPTY
+ );
+
+ var string = write(writer -> writer.writeTypeDeclaration(java));
+
+ assertThat(string, equalTo("""
+ public class Point {
+ // Custom area start: body
+ // <custom area>
+ // Custom area end: body
+ }"""
+ ));
+ }
+
+ @Test
public void classDeclarationWithDocComment() throws IOException {
var java = new JavaClassDeclaration(
"Point",
@@ -134,6 +154,26 @@ public class JavaWriterTests {
}
@Test
+ public void interfaceDeclarationWithCustomArea() throws IOException {
+ var java = new JavaInterfaceDeclaration(
+ "Shape",
+ List.of(),
+ new JavaCustomArea(List.of("// <custom area>")),
+ DocComment.EMPTY
+ );
+
+ var string = write(writer -> writer.writeTypeDeclaration(java));
+
+ assertThat(string, equalTo("""
+ public sealed interface Shape {
+ // Custom area start: body
+ // <custom area>
+ // Custom area end: body
+ }"""
+ ));
+ }
+
+ @Test
public void interfaceDeclarationWithDocComment() throws IOException {
var java = new JavaInterfaceDeclaration(
"Shape",
@@ -175,6 +215,28 @@ public class JavaWriterTests {
}
@Test
+ public void recordDeclarationWithCustomArea() throws IOException {
+ var java = new JavaRecordDeclaration(
+ "Point",
+ List.of(),
+ List.of(),
+ List.of(),
+ new JavaCustomArea(List.of("// <custom area>")),
+ DocComment.EMPTY
+ );
+
+ var string = write(writer -> writer.writeTypeDeclaration(java));
+
+ assertThat(string, equalTo("""
+ public record Point() {
+ // Custom area start: body
+ // <custom area>
+ // Custom area end: body
+ }"""
+ ));
+ }
+
+ @Test
public void recordDeclarationWithDocComment() throws IOException {
var java = new JavaRecordDeclaration(
"Point",