Skip to content
This repository has been archived by the owner on Oct 15, 2019. It is now read-only.

Commit

Permalink
[swift-generator] skip un-generate-able constants
Browse files Browse the repository at this point in the history
There is a bug that the swift generator cannot handle certain kinds of constants (e.g. maps that have enums for key or value type). This bug will take a bit of restructuring in the generator to fix properly, but some of the users of the generator don't actually need those constants generated at this point, they just need the generator to keep going instead of break and fail to generate any further types. This change does that.
  • Loading branch information
andrewcox committed Jul 9, 2014
1 parent 78fd1e1 commit 1edc68d
Showing 1 changed file with 9 additions and 1 deletion.
Expand Up @@ -21,6 +21,8 @@
import com.facebook.swift.generator.util.TemplateLoader;
import com.facebook.swift.parser.model.Const;
import com.facebook.swift.parser.visitor.Visitable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
Expand All @@ -29,6 +31,7 @@

public class ConstantsVisitor extends AbstractTemplateVisitor
{
private static final Logger LOG = LoggerFactory.getLogger(ConstantsVisitor.class);
private final Set<Const> constants = new HashSet<>();

public ConstantsVisitor(final TemplateLoader templateLoader,
Expand Down Expand Up @@ -61,7 +64,12 @@ public void finish()
final ConstantsContext constantContext = contextGenerator.constantsFromThrift();

for (final Const constant : constants) {
constantContext.addConstant(contextGenerator.constantFromThrift(constant));
try {
constantContext.addConstant(contextGenerator.constantFromThrift(constant));
}
catch (IllegalStateException e) {
LOG.error("Could not generate code for constant '{}' due to https://github.com/facebook/swift/issues/209, skipping...", constant.getName());
}
}
render(constantContext, "constants");
}
Expand Down

0 comments on commit 1edc68d

Please sign in to comment.