private void parseDocument(Uri tripUri, Dictionary<string, DocumentContext> contexts, TypeRegistry typeRegistry) { if (tripUri == null || !tripUri.IsAbsoluteUri) { throw new ArgumentException("Only absolute URIs can be parsed!"); } if (parentDocuments.Contains(tripUri)) { throw new ArgumentException(string.Format("Input {0} recursively includes itself ({1})", tripUri, string.Join(" -> ", parentDocuments) + " -> " + tripUri)); } if (parsedDocuments.Contains(tripUri)) { LOG.Debug(string.Format("Skipping already parsed file {0}...", tripUri)); return; } LOG.Debug(string.Format("Parsing {0}...", tripUri)); var tripNamespace = extractLeanNamespace(tripUri); if (string.IsNullOrWhiteSpace(tripNamespace)) { throw new ArgumentException(string.Format("Lean URI {0} can not be translated to a namespace", tripUri)); } var context = new DocumentContext(tripUri, tripNamespace, generatorConfig, typeRegistry); var document = context.Document; var header = document.Header; var javaPackage = context.JavaPackage; // Make a note that this document is a parent of all the documents included, directly or recursively parentDocuments.Push(tripUri); try { if (header != null) { foreach (var include in header.Includes) { Uri includeUri = null; Uri.TryCreate(generatorConfig.InputBase, include, out includeUri); parseDocument(includeUri, // If the includes should also generate code, pass the list of // contexts down to the include parser, otherwise pass a null in generatorConfig.GenerateIncludedCode ? contexts : null, typeRegistry); } } } finally { // Done parsing this document's includes, remove it from the parent chain parentDocuments.Pop(); } // Make a note that we've already passed this document parsedDocuments.Add(tripUri); new TypeVisitor(javaPackage, context).Visit(document); if (contexts != null) { if (contexts.ContainsKey(context.Namespace)) { LOG.Info(string.Format("Lean Namespace {0} included multiple times!", context.Namespace)); } contexts[context.Namespace] = context; } }
private void generateFiles(DocumentContext context) { LOG.Debug(string.Format("Generating code for {0}...", context.Namespace)); Enforce.IsNotNull(outputFolder, "The output folder was not set!"); // TODO, check folder valid var codeGenerator = new CodeGenerator(templateLoader, context, generatorConfig, outputFolder); codeGenerator.Visit(context.Document); }