Skip to content

Commit

Permalink
feat: Export type aliases (#3065)
Browse files Browse the repository at this point in the history
Fixes #3047

When a typealias is used in a verb, set it to exported
  • Loading branch information
tomdaffurn authored Oct 10, 2024
1 parent f85767a commit 0205548
Showing 1 changed file with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public Type buildType(org.jboss.jandex.Type type, boolean export, Nullability nu
return ref;
} else {
// If this data was processed already, skip early
if (updateData(name, type.hasAnnotation(EXPORT) || export)) {
if (setDeclExport(name, type.hasAnnotation(EXPORT) || export)) {
return ref;
}
Data.Builder data = Data.newBuilder();
Expand Down Expand Up @@ -505,16 +505,14 @@ private void buildDataElement(Data.Builder data, DotName className) {
public ModuleBuilder addDecls(Decl decl) {
if (decl.hasData()) {
Data data = decl.getData();
if (updateData(data.getName(), data.getExport())) {
return this;
if (!setDeclExport(data.getName(), data.getExport())) {
addDecl(decl, data.getPos(), data.getName());
}
addDecl(decl, data.getPos(), data.getName());
} else if (decl.hasEnum()) {
xyz.block.ftl.v1.schema.Enum enuum = decl.getEnum();
if (updateEnum(enuum.getName(), decl)) {
return this;
if (!updateEnum(enuum.getName(), decl)) {
addDecl(decl, enuum.getPos(), enuum.getName());
}
addDecl(decl, enuum.getPos(), enuum.getName());
} else if (decl.hasDatabase()) {
addDecl(decl, decl.getDatabase().getPos(), decl.getDatabase().getName());
} else if (decl.hasConfig()) {
Expand Down Expand Up @@ -614,7 +612,7 @@ private boolean updateEnum(String name, Decl decl) {
for (var childDecl : merged.getVariantsList()) {
if (childDecl.getValue().hasTypeValue() && childDecl.getValue().getTypeValue().getValue().hasRef()) {
var ref = childDecl.getValue().getTypeValue().getValue().getRef();
updateData(ref.getName(), true);
setDeclExport(ref.getName(), true);
}
}
}
Expand All @@ -624,20 +622,21 @@ private boolean updateEnum(String name, Decl decl) {
}

/**
* Check if a data with the given name already exists in the module. If it does, update its export field to
* match <code>export</code>, and return true
* Set a Decl's export field to <code>export</code>. Return true iff the Decl exists
*/
private boolean updateData(String name, boolean export) {
if (decls.containsKey(name)) {
var existing = decls.get(name);
if (!existing.hasData()) {
return true;
private boolean setDeclExport(String name, boolean export) {
var existing = decls.get(name);
if (existing != null) {
if (existing.hasData()) {
var merged = existing.getData().toBuilder().setExport(export).build();
decls.put(name, Decl.newBuilder().setData(merged).build());
} else if (existing.hasTypeAlias()) {
var merged = existing.getTypeAlias().toBuilder().setExport(export).build();
decls.put(name, Decl.newBuilder().setTypeAlias(merged).build());
}
var merged = existing.getData().toBuilder().setExport(export).build();
decls.put(name, Decl.newBuilder().setData(merged).build());
return true;

}
return false;
return existing != null;
}

private void duplicateNameValidationError(String name, Position pos) {
Expand Down

0 comments on commit 0205548

Please sign in to comment.