Skip to content

Commit

Permalink
Extract schema from type enum holder classes
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdaffurn committed Oct 2, 2024
1 parent 401feab commit fdfbc89
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,8 @@ private boolean updateEnum(String name, Decl decl) {
.setExport(export)
.build();
decls.put(name, Decl.newBuilder().setEnum(merged).build());
if (export && !existing.getEnum().getExport()) {
// If the existing enum was not exported, we need to update variants too
if (export) {
// Need to update export on variants too
for (var childDecl : merged.getVariantsList()) {
if (childDecl.getValue().hasTypeValue() && childDecl.getValue().getTypeValue().getValue().hasRef()) {
var ref = childDecl.getValue().getTypeValue().getValue().getRef();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.squareup.javapoet.TypeVariableName;
import com.squareup.javapoet.WildcardTypeName;

import xyz.block.ftl.EnumHolder;
import xyz.block.ftl.GeneratedRef;
import xyz.block.ftl.Subscription;
import xyz.block.ftl.TypeAlias;
Expand Down Expand Up @@ -170,6 +171,7 @@ protected void generateEnum(Module module, Enum data, String packageName, Map<De
// Value type isn't a Ref, so we make a wrapper class that implements our interface
TypeSpec.Builder dataBuilder = TypeSpec.classBuilder(className(name))
.addAnnotation(getGeneratedRefAnnotation(module.getName(), name))
.addAnnotation(AnnotationSpec.builder(EnumHolder.class).build())
.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
dataBuilder.addField(valueTypeName, "value", Modifier.PRIVATE, Modifier.FINAL);
dataBuilder.addMethod(MethodSpec.constructorBuilder()
Expand Down Expand Up @@ -201,6 +203,8 @@ protected void generateDataObject(Module module, Data data, String packageName,
TypeSpec.Builder dataBuilder = TypeSpec.classBuilder(thisType)
.addAnnotation(getGeneratedRefAnnotation(module.getName(), data.getName()))
.addModifiers(Modifier.PUBLIC);

// if data is part of a type enum, generate the interface methods for each variant
DeclRef key = new DeclRef(module.getName(), data.getName());
if (enumVariantInfoMap.containsKey(key)) {
for (var enumVariantInfo : enumVariantInfoMap.get(key)) {
Expand All @@ -214,8 +218,8 @@ protected void generateDataObject(Module module, Data data, String packageName,
variantTypeName, variantValuesTypes, true);
}
}
MethodSpec.Builder allConstructor = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC);

MethodSpec.Builder allConstructor = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC);
dataBuilder.addMethod(allConstructor.build());
for (var param : data.getTypeParametersList()) {
dataBuilder.addTypeVariable(TypeVariableName.get(param.getName()));
Expand Down

0 comments on commit fdfbc89

Please sign in to comment.