public void Execute(RazorCodeDocument document) { var chunkTree = document.GetChunkTree(); var classInfo = document.GetClassName(); var chunkGeneratorContext = new ChunkGeneratorContext(_host, classInfo.Class, classInfo.Namespace, document.Source.Filename, shouldGenerateLinePragmas: true); chunkGeneratorContext.ChunkTreeBuilder = new AspNetCore.Razor.Chunks.ChunkTreeBuilder(); chunkGeneratorContext.ChunkTreeBuilder.Root.Association = chunkTree.Root.Association; chunkGeneratorContext.ChunkTreeBuilder.Root.Start = chunkTree.Root.Start; foreach (var chunk in chunkTree.Root.Children) { chunkGeneratorContext.ChunkTreeBuilder.Root.Children.Add(chunk); } var codeGeneratorContext = new CodeGeneratorContext(chunkGeneratorContext, document.ErrorSink); var codeGenerator = new PageCodeGenerator(codeGeneratorContext); var codeGeneratorResult = codeGenerator.Generate(); document.SetGeneratedCSharpDocument(new GeneratedCSharpDocument() { GeneratedCode = codeGeneratorResult.Code, }); }
public CSharpSourceTree Execute(RazorCodeDocument document, RazorChunkTree chunkTree) { var builder = new SourceTreeBuilder(); var context = new CSharpSourceLoweringContext { Builder = builder, Host = _host, SourceFileName = document.Source.Filename }; var checksum = new Checksum { FileName = document.Source.Filename, Guid = Sha1AlgorithmId, Bytes = document.GetChecksumBytes() }; builder.Add(checksum); var classInfo = document.GetClassName(); using (builder.BuildBlock <NamespaceDeclaration>(declaration => declaration.Namespace = classInfo.Namespace)) { AddNamespaceImports(chunkTree, context); using (builder.BuildBlock <ViewClassDeclaration>( declaration => { declaration.Accessor = "public"; declaration.Name = classInfo.Class; var baseTypeVisitor = new BaseTypeVisitor(); baseTypeVisitor.Accept(chunkTree.Root); declaration.BaseTypeName = baseTypeVisitor.BaseTypeName ?? _host.DefaultBaseClass; })) { new TagHelperFieldDeclarationVisitor(context).Accept(chunkTree.Root); new FunctionsDirectiveVisitor(context).Accept(chunkTree.Root); using (builder.BuildBlock <ExecuteMethodDeclaration>( declaration => { declaration.Accessor = "public"; declaration.Modifiers = new[] { "override", "async" }; declaration.ReturnTypeName = typeof(Task).FullName; declaration.Name = _host.GeneratedClassContext.ExecuteMethodName; })) { new ExecuteMethodBodyVisitor(context).Accept(chunkTree.Root); } } } return(builder.Root); }
public RazorChunkTree Execute(RazorCodeDocument document, RazorSyntaxTree syntaxTree) { var classInfo = document.GetClassName(); var generator = new RazorChunkGenerator(classInfo.Class, classInfo.Namespace, document.Source.Filename, _host); syntaxTree.Root.Accept(generator); foreach (var error in syntaxTree.Diagnostics) { generator.VisitError(error); } generator.OnComplete(); return(new DefaultRazorChunkTree(generator.Context.ChunkTreeBuilder.Root)); }