final String thriftNamespace = extractThriftNamespace(thriftUri);
Preconditions.checkState(!isBlank(thriftNamespace), "Thrift URI %s can not be translated to a namespace", thriftUri);
final SwiftDocumentContext context = new SwiftDocumentContext(thriftUri, thriftNamespace, swiftGeneratorConfig, typeRegistry, typedefRegistry);
final Document document = context.getDocument();
final Header header = document.getHeader();
String effectiveJavaNamespace = "java.swift";
if (swiftGeneratorConfig.usePlainJavaNamespace()) {
effectiveJavaNamespace = "java";
}
// Override takes precedence
String javaPackage = swiftGeneratorConfig.getOverridePackage();
// Otherwise fallback on package specified in .thrift file
if (javaPackage == null) {
javaPackage = header.getNamespace(effectiveJavaNamespace);
}
// Or the default if we don't have an override package or a package in the .thrift file
if (javaPackage == null) {
javaPackage = swiftGeneratorConfig.getDefaultPackage();
}
// If none of the above options get us a package to use, fail
Preconditions.checkState(javaPackage != null, "thrift uri %s does not declare a '%s' namespace!", thriftUri, effectiveJavaNamespace);
// Make a note that this document is a parent of all the documents included, directly or recursively
parentDocuments.push(thriftUri);
try {
for (final String include : header.getIncludes()) {
final URI includeUri = swiftGeneratorConfig.getInputBase().resolve(include);
LOG.debug("Found {} included from {}.", includeUri, thriftUri);
parseDocument(includeUri,
// If the includes should also generate code, pass the list of
// contexts down to the include parser, otherwise pass a null in
swiftGeneratorConfig.isGenerateIncludedCode() ? contexts : null,
typeRegistry,
typedefRegistry);
}
}
finally {
// Done parsing this document's includes, remove it from the parent chain
parentDocuments.pop();
}
// Make a note that we've already parsed this document
parsedDocuments.add(thriftUri);
document.visit(new TypeVisitor(javaPackage, context));
if (contexts != null && contexts.put(context.getNamespace(), context) != null) {
LOG.info("Thrift Namespace {} included multiple times!", context.getNamespace());
}
}