From 8406f6abb31124c01c2ac5ec7615f825e337e0d9 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 13 Jun 2026 21:13:24 +0100 Subject: Extract generateSumDefinition() --- .../generators/javatypes/JavaTypesGenerator.java | 63 ++++++++++++---------- 1 file changed, 35 insertions(+), 28 deletions(-) (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 8f9ea13..f4ed937 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 @@ -80,34 +80,7 @@ public class JavaTypesGenerator implements Generator { case TypedSumDefinitionNode sumDefinition -> { var javaCompilationUnit = new JavaCompilationUnit( packageParts, - new JavaInterfaceDeclaration( - sumDefinition.name(), - JavaInterfaceOpenness.SEALED, - sumDefinition.variants().stream() - .map(variant -> generateTypeRef(variant.type(), context)) - .toList(), - List.of( - new JavaInterfaceDeclaration( - BUILDER_TYPE_NAME, - JavaInterfaceOpenness.OPEN, - List.of(), - List.of( - new JavaMethodDeclaration( - "build", - JavaVisibility.PUBLIC, - JavaMethodKind.INSTANCE, - generateTypeRef(sumDefinition.type(), context), - List.of(), - Optional.empty() - ) - ), - JavaCustomArea.forType(generateBuilderTypeRef(sumDefinition.type()), "body"), - DocComment.EMPTY - ) - ), - JavaCustomArea.forType(generateTypeRef(sumDefinition.type(), context), "body"), - sumDefinition.docComment() - ) + generateSumDefinition(sumDefinition, context) ); javaCompilationUnits.add(javaCompilationUnit); @@ -246,6 +219,40 @@ public class JavaTypesGenerator implements Generator { ); } + private JavaInterfaceDeclaration generateSumDefinition( + TypedSumDefinitionNode sumDefinition, + Context context + ) { + return new JavaInterfaceDeclaration( + sumDefinition.name(), + JavaInterfaceOpenness.SEALED, + sumDefinition.variants().stream() + .map(variant -> generateTypeRef(variant.type(), context)) + .toList(), + List.of( + new JavaInterfaceDeclaration( + BUILDER_TYPE_NAME, + JavaInterfaceOpenness.OPEN, + List.of(), + List.of( + new JavaMethodDeclaration( + "build", + JavaVisibility.PUBLIC, + JavaMethodKind.INSTANCE, + generateTypeRef(sumDefinition.type(), context), + List.of(), + Optional.empty() + ) + ), + JavaCustomArea.forType(generateBuilderTypeRef(sumDefinition.type()), "body"), + DocComment.EMPTY + ) + ), + JavaCustomArea.forType(generateTypeRef(sumDefinition.type(), context), "body"), + sumDefinition.docComment() + ); + } + private List namespaceToJavaPackageParts(NamespaceName namespaceName) { return this.javaGenerator.namespaceToJavaPackageParts(namespaceName); } -- cgit v1.2.3