From fe0d7c79e4f0ee959fd3f10eb172e8e16dd72f69 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 12 Jun 2026 20:25:51 +0100 Subject: Move Java interface openness to top-level type --- .../output/generators/javatypes/JavaTypesGenerator.java | 4 ++-- .../output/lang/java/ast/JavaInterfaceDeclaration.java | 6 +----- .../compiler/output/lang/java/ast/JavaInterfaceOpenness.java | 6 ++++++ .../hobgoblin/compiler/output/lang/java/JavaWriterTests.java | 10 +++++----- 4 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaInterfaceOpenness.java (limited to 'src') 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 fe25a04..de33968 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 @@ -82,14 +82,14 @@ public class JavaTypesGenerator implements Generator { packageParts, new JavaInterfaceDeclaration( sumDefinition.name(), - JavaInterfaceDeclaration.Openness.SEALED, + JavaInterfaceOpenness.SEALED, sumDefinition.variants().stream() .map(variant -> generateTypeRef(variant.type(), context)) .toList(), List.of( new JavaInterfaceDeclaration( BUILDER_TYPE_NAME, - JavaInterfaceDeclaration.Openness.OPEN, + JavaInterfaceOpenness.OPEN, List.of(), List.of( new JavaMethodDeclaration( 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 a35de51..e3780c7 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,14 +6,10 @@ import java.util.List; public record JavaInterfaceDeclaration( String name, - Openness openness, + JavaInterfaceOpenness openness, List permitsTypes, List body, JavaCustomArea customArea, DocComment docComment ) implements JavaTypeDeclaration { - public enum Openness { - OPEN, - SEALED - } } diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaInterfaceOpenness.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaInterfaceOpenness.java new file mode 100644 index 0000000..c6fa444 --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaInterfaceOpenness.java @@ -0,0 +1,6 @@ +package org.zwobble.hobgoblin.compiler.output.lang.java.ast; + +public enum JavaInterfaceOpenness { + OPEN, + SEALED +} 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 51e5f87..1de864d 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 @@ -177,7 +177,7 @@ public class JavaWriterTests { public void openInterfaceDeclaration() throws IOException { var java = new JavaInterfaceDeclaration( "Shape", - JavaInterfaceDeclaration.Openness.OPEN, + JavaInterfaceOpenness.OPEN, List.of(), List.of(), new JavaCustomArea(JavaTypeRef.topLevel(List.of(), "Shape"), "body"), @@ -198,7 +198,7 @@ public class JavaWriterTests { public void sealedInterfaceDeclaration() throws IOException { var java = new JavaInterfaceDeclaration( "Shape", - JavaInterfaceDeclaration.Openness.SEALED, + JavaInterfaceOpenness.SEALED, List.of(), List.of(), new JavaCustomArea(JavaTypeRef.topLevel(List.of(), "Shape"), "body"), @@ -219,7 +219,7 @@ public class JavaWriterTests { public void sealedInterfaceDeclarationWithPermitsTypes() throws IOException { var java = new JavaInterfaceDeclaration( "Shape", - JavaInterfaceDeclaration.Openness.SEALED, + JavaInterfaceOpenness.SEALED, List.of( JavaTypeRef.topLevel(List.of("abc", "def"), "One"), JavaTypeRef.topLevel(List.of("abc", "def"), "Two") @@ -243,7 +243,7 @@ public class JavaWriterTests { public void interfaceDeclarationWithDocComment() throws IOException { var java = new JavaInterfaceDeclaration( "Shape", - JavaInterfaceDeclaration.Openness.OPEN, + JavaInterfaceOpenness.OPEN, List.of(), List.of(), new JavaCustomArea(JavaTypeRef.topLevel(List.of(), "Shape"), "body"), @@ -265,7 +265,7 @@ public class JavaWriterTests { public void interfaceDeclarationWithBody() throws IOException { var java = new JavaInterfaceDeclaration( "Shape", - JavaInterfaceDeclaration.Openness.OPEN, + JavaInterfaceOpenness.OPEN, List.of(), List.of( new JavaMethodDeclaration( -- cgit v1.2.3