summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javapreciselymatchers/JavaPreciselyMatchersGenerator.java3
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriter.java29
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaClassDeclaration.java1
3 files changed, 21 insertions, 12 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javapreciselymatchers/JavaPreciselyMatchersGenerator.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javapreciselymatchers/JavaPreciselyMatchersGenerator.java
index cbdcc90..b999deb 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javapreciselymatchers/JavaPreciselyMatchersGenerator.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javapreciselymatchers/JavaPreciselyMatchersGenerator.java
@@ -8,7 +8,6 @@ import org.zwobble.hobgoblin.compiler.ast.typed.TypedSumDefinitionNode;
import org.zwobble.hobgoblin.compiler.config.OutputConfig;
import org.zwobble.hobgoblin.compiler.output.generators.Generator;
import org.zwobble.hobgoblin.compiler.output.generators.java.JavaGenerator;
-import org.zwobble.hobgoblin.compiler.output.generators.javatypes.JavaTypesGenerator;
import org.zwobble.hobgoblin.compiler.output.lang.java.ast.*;
import org.zwobble.hobgoblin.compiler.typechecker.TypesInfo;
import org.zwobble.hobgoblin.compiler.types.*;
@@ -18,7 +17,6 @@ import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
-import java.util.Optional;
public class JavaPreciselyMatchersGenerator implements Generator {
public static final String NAME = "java-precisely-matchers";
@@ -94,6 +92,7 @@ public class JavaPreciselyMatchersGenerator implements Generator {
return new JavaClassDeclaration(
matcherTypeName,
List.of(),
+ List.of(),
JavaCustomArea.type(javaTypeRef, "body"),
DocComment.EMPTY
);
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 3b7987b..87da849 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
@@ -7,6 +7,7 @@ import org.zwobble.hobgoblin.compiler.output.lang.java.ast.*;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.file.Path;
+import java.util.List;
public class JavaWriter implements AutoCloseable {
private static final String LINE_COMMENT_START = "//";
@@ -93,7 +94,11 @@ public class JavaWriter implements AutoCloseable {
this.writer.write("public class ");
this.writer.write(classDeclaration.name());
- this.writer.write(" {");
+ this.writer.write(" ");
+
+ this.writeImplements(classDeclaration.implementsTypes());
+
+ this.writer.write("{");
this.writer.indent();
for (var bodyDeclaration: classDeclaration.body()) {
@@ -157,6 +162,18 @@ public class JavaWriter implements AutoCloseable {
}
}
+ private void writeImplements(List<JavaTypeRef> implementsTypes) throws IOException {
+ if (!implementsTypes.isEmpty()) {
+ this.writer.write("implements ");
+ writeWithSeparator(
+ implementsTypes,
+ this::writeTypeRef,
+ () -> writer.write(", ")
+ );
+ writer.write(" ");
+ }
+ }
+
private void writeIntegerLiteral(JavaIntegerLiteral integerLiteral) throws IOException {
this.writer.write(Long.toString(integerLiteral.value()));
}
@@ -286,15 +303,7 @@ public class JavaWriter implements AutoCloseable {
writer.write(") ");
- if (!recordDeclaration.implementsTypes().isEmpty()) {
- this.writer.write("implements ");
- writeWithSeparator(
- recordDeclaration.implementsTypes(),
- this::writeTypeRef,
- () -> writer.write(", ")
- );
- writer.write(" ");
- }
+ this.writeImplements(recordDeclaration.implementsTypes());
this.writer.write("{");
this.writer.indent();
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaClassDeclaration.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaClassDeclaration.java
index 4e6c4b7..7a099ef 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaClassDeclaration.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaClassDeclaration.java
@@ -6,6 +6,7 @@ import java.util.List;
public record JavaClassDeclaration(
String name,
+ List<JavaTypeRef> implementsTypes,
List<JavaClassBodyDeclaration> body,
JavaCustomArea customArea,
DocComment docComment