summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-05-29 17:14:13 +0100
committerMichael Williamson <mike@zwobble.org>2026-05-29 17:14:13 +0100
commite6e4d79f9c9a34262406de00942ef91d35add318 (patch)
tree755d167f6add87521c0f07e7b9366bfe39524206 /src/main/java
parent43f022793da7ca97d91892d43205fec8b16f76c7 (diff)
Have builders for structs implement builders for sums
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedConstructedTypeNode.java2
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedNativeTypeDefinitionNode.java2
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedStructDefinitionNode.java2
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedSumDefinitionNode.java2
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTypeLevelReferenceNode.java2
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javatypes/JavaTypesGenerator.java6
6 files changed, 10 insertions, 6 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedConstructedTypeNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedConstructedTypeNode.java
index 6a74b8a..42f6a1f 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedConstructedTypeNode.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedConstructedTypeNode.java
@@ -5,7 +5,7 @@ public record UntypedConstructedTypeNode(org.zwobble.hobgoblin.compiler.ast.unty
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedConstructedTypeNode.Builder(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode.arbitrary().build(), java.util.List.of(), org.zwobble.hobgoblin.compiler.ast.untyped.Native.arbitrarySource());
}
- public record Builder(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode receiver, java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode> args, org.zwobble.hobgoblin.compiler.sources.Source source) {
+ public record Builder(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode receiver, java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode> args, org.zwobble.hobgoblin.compiler.sources.Source source) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode.Builder {
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedConstructedTypeNode build() {
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedConstructedTypeNode(receiver, args, source);
}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedNativeTypeDefinitionNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedNativeTypeDefinitionNode.java
index fb0d550..9b99c32 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedNativeTypeDefinitionNode.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedNativeTypeDefinitionNode.java
@@ -5,7 +5,7 @@ public record UntypedNativeTypeDefinitionNode(String name, org.zwobble.hobgoblin
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNativeTypeDefinitionNode.Builder("", org.zwobble.hobgoblin.compiler.ast.untyped.Native.arbitraryDocComment(), org.zwobble.hobgoblin.compiler.ast.untyped.Native.arbitrarySource());
}
- public record Builder(String name, org.zwobble.hobgoblin.compiler.ast.DocComment docComment, org.zwobble.hobgoblin.compiler.sources.Source source) {
+ public record Builder(String name, org.zwobble.hobgoblin.compiler.ast.DocComment docComment, org.zwobble.hobgoblin.compiler.sources.Source source) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNamespaceStatementNode.Builder {
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNativeTypeDefinitionNode build() {
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNativeTypeDefinitionNode(name, docComment, source);
}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedStructDefinitionNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedStructDefinitionNode.java
index 80c6c3a..8611651 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedStructDefinitionNode.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedStructDefinitionNode.java
@@ -5,7 +5,7 @@ public record UntypedStructDefinitionNode(String name, java.util.List<org.zwobbl
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructDefinitionNode.Builder("", java.util.List.of(), org.zwobble.hobgoblin.compiler.ast.untyped.Native.arbitraryDocComment(), org.zwobble.hobgoblin.compiler.ast.untyped.Native.arbitrarySource());
}
- public record Builder(String name, java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructFieldDefinitionNode> fields, org.zwobble.hobgoblin.compiler.ast.DocComment docComment, org.zwobble.hobgoblin.compiler.sources.Source source) {
+ public record Builder(String name, java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructFieldDefinitionNode> fields, org.zwobble.hobgoblin.compiler.ast.DocComment docComment, org.zwobble.hobgoblin.compiler.sources.Source source) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNamespaceStatementNode.Builder {
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructDefinitionNode build() {
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructDefinitionNode(name, fields, docComment, source);
}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedSumDefinitionNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedSumDefinitionNode.java
index 3a95cfb..8f5520b 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedSumDefinitionNode.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedSumDefinitionNode.java
@@ -5,7 +5,7 @@ public record UntypedSumDefinitionNode(String name, java.util.List<org.zwobble.h
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumDefinitionNode.Builder("", java.util.List.of(), org.zwobble.hobgoblin.compiler.ast.untyped.Native.arbitraryDocComment(), org.zwobble.hobgoblin.compiler.ast.untyped.Native.arbitrarySource());
}
- public record Builder(String name, java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode> variants, org.zwobble.hobgoblin.compiler.ast.DocComment docComment, org.zwobble.hobgoblin.compiler.sources.Source source) {
+ public record Builder(String name, java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode> variants, org.zwobble.hobgoblin.compiler.ast.DocComment docComment, org.zwobble.hobgoblin.compiler.sources.Source source) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNamespaceStatementNode.Builder {
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumDefinitionNode build() {
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumDefinitionNode(name, variants, docComment, source);
}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTypeLevelReferenceNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTypeLevelReferenceNode.java
index f2bc5e6..bcde610 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTypeLevelReferenceNode.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTypeLevelReferenceNode.java
@@ -5,7 +5,7 @@ public record UntypedTypeLevelReferenceNode(String name, org.zwobble.hobgoblin.c
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode.Builder("", org.zwobble.hobgoblin.compiler.ast.untyped.Native.arbitrarySource());
}
- public record Builder(String name, org.zwobble.hobgoblin.compiler.sources.Source source) {
+ public record Builder(String name, org.zwobble.hobgoblin.compiler.sources.Source source) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode.Builder {
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode build() {
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode(name, source);
}
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 5af408c..9202975 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
@@ -226,6 +226,10 @@ public class JavaTypesGenerator implements Generator {
) {
var builderJavaTypeRef = generateBuilderTypeRef(structDefinition.type());
+ var implementsTypes = context.variantOf(structDefinition.type()).stream()
+ .map(sumType -> this.generateBuilderTypeRef(sumType))
+ .toList();
+
var body = new ArrayList<JavaClassBodyDeclaration>();
body.add(new JavaMethodDeclaration(
"build",
@@ -260,7 +264,7 @@ public class JavaTypesGenerator implements Generator {
return new JavaRecordDeclaration(
BUILDER_TYPE_NAME,
components,
- List.of(),
+ implementsTypes,
body,
JavaCustomArea.type(builderJavaTypeRef, "body"),
DocComment.EMPTY