diff options
Diffstat (limited to 'src/main/java')
3 files changed, 15 insertions, 1 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javatypes/JavaTypesGenerator.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javatypes/JavaTypesGenerator.java index 8f6bd48..867ba23 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javatypes/JavaTypesGenerator.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javatypes/JavaTypesGenerator.java @@ -139,6 +139,7 @@ public class JavaTypesGenerator implements Generator { packageParts, new JavaInterfaceDeclaration( sumDefinition.name(), + JavaInterfaceDeclaration.Openness.SEALED, sumDefinition.variants().stream() .map(variant -> generateTypeRef(variant.type(), context)) .toList(), 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 3cf58ce..677b1a6 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 @@ -155,7 +155,15 @@ public class JavaWriter implements AutoCloseable { private void writeInterfaceDeclaration(JavaInterfaceDeclaration interfaceDeclaration) throws IOException { writeDocComment(interfaceDeclaration.docComment()); - this.writer.write("public sealed interface "); + this.writer.write("public "); + switch (interfaceDeclaration.openness()) { + case OPEN -> { + } + case SEALED -> { + this.writer.write("sealed "); + } + } + this.writer.write("interface "); this.writer.write(interfaceDeclaration.name()); this.writer.write(" "); diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaInterfaceDeclaration.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaInterfaceDeclaration.java index d0bd0a1..a35de51 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaInterfaceDeclaration.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaInterfaceDeclaration.java @@ -6,9 +6,14 @@ import java.util.List; public record JavaInterfaceDeclaration( String name, + Openness openness, List<JavaTypeRef> permitsTypes, List<JavaClassBodyDeclaration> body, JavaCustomArea customArea, DocComment docComment ) implements JavaTypeDeclaration { + public enum Openness { + OPEN, + SEALED + } } |
