diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkHelper.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkHelper.cs index 0f01093891..352dbc61f2 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkHelper.cs @@ -4,7 +4,7 @@ using System; using System.Linq; using Microsoft.AspNet.Mvc.Razor.Host; -using Microsoft.AspNet.Razor.Generator.Compiler; +using Microsoft.AspNet.Razor.Chunks; using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Razor.Directives @@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives /// /// The type to cast to. /// The chunk to cast. - /// The cast to . + /// The cast to . /// is not an instance of /// . public static TChunk EnsureChunk([NotNull] Chunk chunk) @@ -40,31 +40,32 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives /// /// Returns the used to determine the model name for the page generated - /// using the specified + /// using the specified /// - /// The to scan for s in. - /// The last in the if found, null otherwise. + /// The to scan for s in. + /// The last in the if found, null otherwise. /// - public static ModelChunk GetModelChunk([NotNull] CodeTree codeTree) + public static ModelChunk GetModelChunk([NotNull] ChunkTree chunkTree) { // If there's more than 1 model chunk there will be a Razor error BUT we want intellisense to show up on // the current model chunk that the user is typing. - return codeTree.Chunks + return chunkTree.Chunks .OfType() .LastOrDefault(); } /// /// Returns the type name of the Model specified via a in the - /// if specified or the default model type. + /// if specified or the default model type. /// - /// The to scan for s in. + /// The to scan for s in. /// The name of the default model. /// The model type name for the generated page. - public static string GetModelTypeName([NotNull] CodeTree codeTree, - [NotNull] string defaultModelName) + public static string GetModelTypeName( + [NotNull] ChunkTree chunkTree, + [NotNull] string defaultModelName) { - var modelChunk = GetModelChunk(codeTree); + var modelChunk = GetModelChunk(chunkTree); return modelChunk != null ? modelChunk.ModelType : defaultModelName; } diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkInheritanceUtility.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkInheritanceUtility.cs index e4eb66afe6..679dd5e7e8 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkInheritanceUtility.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkInheritanceUtility.cs @@ -7,7 +7,7 @@ using System.IO; using System.Linq; using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Razor; -using Microsoft.AspNet.Razor.Generator.Compiler; +using Microsoft.AspNet.Razor.Chunks; using Microsoft.AspNet.Razor.Parser; using Microsoft.Framework.Internal; @@ -20,36 +20,37 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives { private readonly MvcRazorHost _razorHost; private readonly IReadOnlyList _defaultInheritedChunks; - private readonly ICodeTreeCache _codeTreeCache; + private readonly IChunkTreeCache _chunkTreeCache; /// /// Initializes a new instance of . /// /// The used to parse _ViewImports pages. - /// that caches instances. + /// that caches instances. /// /// Sequence of s inherited by default. - public ChunkInheritanceUtility([NotNull] MvcRazorHost razorHost, - [NotNull] ICodeTreeCache codeTreeCache, - [NotNull] IReadOnlyList defaultInheritedChunks) + public ChunkInheritanceUtility( + [NotNull] MvcRazorHost razorHost, + [NotNull] IChunkTreeCache chunkTreeCache, + [NotNull] IReadOnlyList defaultInheritedChunks) { _razorHost = razorHost; _defaultInheritedChunks = defaultInheritedChunks; - _codeTreeCache = codeTreeCache; + _chunkTreeCache = chunkTreeCache; } /// - /// Gets an ordered of parsed for each + /// Gets an ordered of parsed for each /// _ViewImports that is applicable to the page located at . The list is - /// ordered so that the for the _ViewImports closest to the + /// ordered so that the for the _ViewImports closest to the /// in the file system appears first. /// /// The path of the page to locate inherited chunks for. - /// A of parsed _ViewImports - /// s. - public virtual IReadOnlyList GetInheritedCodeTrees([NotNull] string pagePath) + /// A of parsed _ViewImports + /// s. + public virtual IReadOnlyList GetInheritedChunkTrees([NotNull] string pagePath) { - var inheritedCodeTrees = new List(); + var inheritedChunkTrees = new List(); var templateEngine = new RazorTemplateEngine(_razorHost); foreach (var viewImportsPath in ViewHierarchyUtility.GetViewImportsLocations(pagePath)) { @@ -57,38 +58,41 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives // Since the parsing of a _ViewImports would cause parent _ViewImports to be parsed // we need to ensure the paths are app-relative to allow the GetGlobalFileLocations // for the current _ViewImports to succeed. - var codeTree = _codeTreeCache.GetOrAdd(viewImportsPath, - fileInfo => ParseViewFile(templateEngine, - fileInfo, - viewImportsPath)); + var chunkTree = _chunkTreeCache.GetOrAdd( + viewImportsPath, + fileInfo => ParseViewFile( + templateEngine, + fileInfo, + viewImportsPath)); - if (codeTree != null) + if (chunkTree != null) { - inheritedCodeTrees.Add(codeTree); + inheritedChunkTrees.Add(chunkTree); } } - return inheritedCodeTrees; + return inheritedChunkTrees; } /// - /// Merges inherited by default and instances produced by parsing - /// _ViewImports files into the specified . + /// Merges inherited by default and instances produced by parsing + /// _ViewImports files into the specified . /// - /// The to merge in to. - /// inherited from _ViewImports + /// The to merge in to. + /// inherited from _ViewImports /// files. /// The list of chunks to merge. - public void MergeInheritedCodeTrees([NotNull] CodeTree codeTree, - [NotNull] IReadOnlyList inheritedCodeTrees, - string defaultModel) + public void MergeInheritedChunkTrees( + [NotNull] ChunkTree chunkTree, + [NotNull] IReadOnlyList inheritedChunkTrees, + string defaultModel) { - var mergerMappings = GetMergerMappings(codeTree, defaultModel); + var mergerMappings = GetMergerMappings(chunkTree, defaultModel); IChunkMerger merger; - // We merge chunks into the codeTree in two passes. In the first pass, we traverse the CodeTree visiting + // We merge chunks into the ChunkTree in two passes. In the first pass, we traverse the ChunkTree visiting // a mapped IChunkMerger for types that are registered. - foreach (var chunk in codeTree.Chunks) + foreach (var chunk in chunkTree.Chunks) { if (mergerMappings.TryGetValue(chunk.GetType(), out merger)) { @@ -97,25 +101,25 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives } // In the second phase we invoke IChunkMerger.Merge for each chunk that has a mapped merger. - // During this phase, the merger can either add to the CodeTree or ignore the chunk based on the merging + // During this phase, the merger can either add to the ChunkTree or ignore the chunk based on the merging // rules. // Read the chunks outside in - that is chunks from the _ViewImports closest to the page get merged in first // and the furthest one last. This allows the merger to ignore a directive like @model that was previously // seen. - var chunksToMerge = inheritedCodeTrees.SelectMany(tree => tree.Chunks) + var chunksToMerge = inheritedChunkTrees.SelectMany(tree => tree.Chunks) .Concat(_defaultInheritedChunks); foreach (var chunk in chunksToMerge) { if (mergerMappings.TryGetValue(chunk.GetType(), out merger)) { - merger.Merge(codeTree, chunk); + merger.Merge(chunkTree, chunk); } } } - private static Dictionary GetMergerMappings(CodeTree codeTree, string defaultModel) + private static Dictionary GetMergerMappings(ChunkTree chunkTree, string defaultModel) { - var modelType = ChunkHelper.GetModelTypeName(codeTree, defaultModel); + var modelType = ChunkHelper.GetModelTypeName(chunkTree, defaultModel); return new Dictionary { { typeof(UsingChunk), new UsingChunkMerger() }, @@ -124,9 +128,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives }; } - private static CodeTree ParseViewFile(RazorTemplateEngine engine, - IFileInfo fileInfo, - string viewImportsPath) + private static ChunkTree ParseViewFile( + RazorTemplateEngine engine, + IFileInfo fileInfo, + string viewImportsPath) { using (var stream = fileInfo.CreateReadStream()) { @@ -135,15 +140,16 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives var parseResults = engine.ParseTemplate(streamReader, viewImportsPath); var className = ParserHelpers.SanitizeClassName(fileInfo.Name); var language = engine.Host.CodeLanguage; - var codeGenerator = language.CreateCodeGenerator(className, - engine.Host.DefaultNamespace, - viewImportsPath, - engine.Host); - codeGenerator.Visit(parseResults); + var chunkGenerator = language.CreateChunkGenerator( + className, + engine.Host.DefaultNamespace, + viewImportsPath, + engine.Host); + chunkGenerator.Visit(parseResults); // Rewrite the location of inherited chunks so they point to the global import file. - var codeTree = codeGenerator.Context.CodeTreeBuilder.CodeTree; - foreach (var chunk in codeTree.Chunks) + var chunkTree = chunkGenerator.Context.ChunkTreeBuilder.ChunkTree; + foreach (var chunk in chunkTree.Chunks) { chunk.Start = new SourceLocation( viewImportsPath, @@ -152,7 +158,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives chunk.Start.CharacterIndex); } - return codeTree; + return chunkTree; } } } diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/DefaultCodeTreeCache.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/DefaultChunkTreeCache.cs similarity index 65% rename from src/Microsoft.AspNet.Mvc.Razor.Host/Directives/DefaultCodeTreeCache.cs rename to src/Microsoft.AspNet.Mvc.Razor.Host/Directives/DefaultChunkTreeCache.cs index 568de7b45d..56a91c4af8 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/DefaultCodeTreeCache.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/DefaultChunkTreeCache.cs @@ -3,16 +3,16 @@ using System; using Microsoft.AspNet.FileProviders; -using Microsoft.AspNet.Razor.Generator.Compiler; +using Microsoft.AspNet.Razor.Chunks; using Microsoft.Framework.Caching.Memory; using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Razor.Directives { /// - /// Default implementation of . + /// Default implementation of . /// - public class DefaultCodeTreeCache : ICodeTreeCache + public class DefaultChunkTreeCache : IChunkTreeCache { private static readonly MemoryCacheOptions MemoryCacheOptions = new MemoryCacheOptions { @@ -20,31 +20,32 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives }; private static readonly TimeSpan SlidingExpirationDuration = TimeSpan.FromMinutes(1); private readonly IFileProvider _fileProvider; - private readonly IMemoryCache _codeTreeCache; + private readonly IMemoryCache _chunkTreeCache; /// - /// Initializes a new instance of . + /// Initializes a new instance of . /// /// The application's . - public DefaultCodeTreeCache(IFileProvider fileProvider) + public DefaultChunkTreeCache(IFileProvider fileProvider) : this(fileProvider, MemoryCacheOptions) { } // Internal for unit testing - internal DefaultCodeTreeCache(IFileProvider fileProvider, + internal DefaultChunkTreeCache(IFileProvider fileProvider, MemoryCacheOptions options) { _fileProvider = fileProvider; - _codeTreeCache = new MemoryCache(options); + _chunkTreeCache = new MemoryCache(options); } /// - public CodeTree GetOrAdd([NotNull] string pagePath, - [NotNull] Func getCodeTree) + public ChunkTree GetOrAdd( + [NotNull] string pagePath, + [NotNull] Func getChunkTree) { - CodeTree codeTree; - if (!_codeTreeCache.TryGetValue(pagePath, out codeTree)) + ChunkTree chunkTree; + if (!_chunkTreeCache.TryGetValue(pagePath, out chunkTree)) { // GetOrAdd is invoked for each _GlobalImport that might potentially exist in the path. // We can avoid performing file system lookups for files that do not exist by caching @@ -55,13 +56,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives .SetSlidingExpiration(SlidingExpirationDuration); var file = _fileProvider.GetFileInfo(pagePath); - codeTree = file.Exists ? getCodeTree(file) : null; + chunkTree = file.Exists ? getChunkTree(file) : null; - _codeTreeCache.Set(pagePath, codeTree, options); + _chunkTreeCache.Set(pagePath, chunkTree, options); } - return codeTree; + return chunkTree; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/IChunkMerger.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/IChunkMerger.cs index 9324698bf2..e12c23213f 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/IChunkMerger.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/IChunkMerger.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Razor.Generator.Compiler; +using Microsoft.AspNet.Razor.Chunks; namespace Microsoft.AspNet.Mvc.Razor.Directives { @@ -11,16 +11,16 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives public interface IChunkMerger { /// - /// Visits a from the to merge into. + /// Visits a from the to merge into. /// /// A from the tree. void VisitChunk(Chunk chunk); /// - /// Merges an inherited into the . + /// Merges an inherited into the . /// - /// The to merge into. + /// The to merge into. /// The to merge. - void Merge(CodeTree codeTree, Chunk chunk); + void Merge(ChunkTree chunkTree, Chunk chunk); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/IChunkTreeCache.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/IChunkTreeCache.cs new file mode 100644 index 0000000000..c4f624870d --- /dev/null +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/IChunkTreeCache.cs @@ -0,0 +1,27 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNet.FileProviders; +using Microsoft.AspNet.Razor.Chunks; + +namespace Microsoft.AspNet.Mvc.Razor.Directives +{ + /// + /// A cache for parsed s. + /// + public interface IChunkTreeCache + { + /// + /// Get an existing , or create and add a new one if it is + /// not available in the cache or is expired. + /// + /// The application relative path of the Razor page. + /// A delegate that creates a new . + /// The if a file exists at , + /// null otherwise. + /// The resulting does not contain inherited chunks from _ViewStart or + /// default inherited chunks. + ChunkTree GetOrAdd(string pagePath, Func getChunkTree); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ICodeTreeCache.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ICodeTreeCache.cs deleted file mode 100644 index c1b67e5d4c..0000000000 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ICodeTreeCache.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.AspNet.FileProviders; -using Microsoft.AspNet.Razor.Generator.Compiler; - -namespace Microsoft.AspNet.Mvc.Razor.Directives -{ - /// - /// A cache for parsed s. - /// - public interface ICodeTreeCache - { - /// - /// Get an existing , or create and add a new one if it is - /// not available in the cache or is expired. - /// - /// The application relative path of the Razor page. - /// A delegate that creates a new . - /// The if a file exists at , - /// null otherwise. - /// The resulting does not contain inherited chunks from _ViewStart or - /// default inherited chunks. - CodeTree GetOrAdd(string pagePath, Func getCodeTree); - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/InjectChunkMerger.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/InjectChunkMerger.cs index fb8e9fb7e7..bb7ea85ee5 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/InjectChunkMerger.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/InjectChunkMerger.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; -using Microsoft.AspNet.Razor.Generator.Compiler; +using Microsoft.AspNet.Razor.Chunks; using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Razor.Directives @@ -34,13 +34,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives } /// - public void Merge([NotNull] CodeTree codeTree, [NotNull] Chunk chunk) + public void Merge([NotNull] ChunkTree chunkTree, [NotNull] Chunk chunk) { var injectChunk = ChunkHelper.EnsureChunk(chunk); if (!_addedMemberNames.Contains(injectChunk.MemberName)) { _addedMemberNames.Add(injectChunk.MemberName); - codeTree.Chunks.Add(TransformChunk(injectChunk)); + chunkTree.Chunks.Add(TransformChunk(injectChunk)); } } diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/SetBaseTypeChunkMerger.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/SetBaseTypeChunkMerger.cs index 27bfd41435..92cd2789f0 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/SetBaseTypeChunkMerger.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/SetBaseTypeChunkMerger.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Razor.Generator.Compiler; +using Microsoft.AspNet.Razor.Chunks; using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Razor.Directives @@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives } /// - public void Merge([NotNull] CodeTree codeTree, [NotNull] Chunk chunk) + public void Merge([NotNull] ChunkTree chunkTree, [NotNull] Chunk chunk) { if (!_isBaseTypeSet) { @@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives // The base type can set exactly once and the first one we encounter wins. _isBaseTypeSet = true; - codeTree.Chunks.Add(TransformChunk(baseTypeChunk)); + chunkTree.Chunks.Add(TransformChunk(baseTypeChunk)); } } diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/UsingChunkMerger.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/UsingChunkMerger.cs index cede88cfab..7c570c8007 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/UsingChunkMerger.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/UsingChunkMerger.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; -using Microsoft.AspNet.Razor.Generator.Compiler; +using Microsoft.AspNet.Razor.Chunks; using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Razor.Directives @@ -23,14 +23,14 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives } /// - public void Merge([NotNull] CodeTree codeTree, [NotNull] Chunk chunk) + public void Merge([NotNull] ChunkTree chunkTree, [NotNull] Chunk chunk) { var namespaceChunk = ChunkHelper.EnsureChunk(chunk); if (!_currentUsings.Contains(namespaceChunk.Namespace)) { _currentUsings.Add(namespaceChunk.Namespace); - codeTree.Chunks.Add(namespaceChunk); + chunkTree.Chunks.Add(namespaceChunk); } } } diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/IMvcRazorHost.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/IMvcRazorHost.cs index 06ba442095..ad2b7ef855 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/IMvcRazorHost.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/IMvcRazorHost.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO; -using Microsoft.AspNet.Razor; +using Microsoft.AspNet.Razor.CodeGenerators; namespace Microsoft.AspNet.Mvc.Razor { diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/InjectChunk.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/InjectChunk.cs index 1f8eb59129..fccb761bff 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/InjectChunk.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/InjectChunk.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Razor.Generator.Compiler; +using Microsoft.AspNet.Razor.Chunks; namespace Microsoft.AspNet.Mvc.Razor { @@ -12,8 +12,9 @@ namespace Microsoft.AspNet.Mvc.Razor /// /// The type name of the property to be injected /// The member name of the property to be injected. - public InjectChunk(string typeName, - string propertyName) + public InjectChunk( + string typeName, + string propertyName) { TypeName = typeName; MemberName = propertyName; diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/InjectChunkVisitor.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/InjectChunkVisitor.cs index 1620d1120f..16e9f22c25 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/InjectChunkVisitor.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/InjectChunkVisitor.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using Microsoft.AspNet.Razor.Generator; -using Microsoft.AspNet.Razor.Generator.Compiler.CSharp; +using Microsoft.AspNet.Razor.CodeGenerators; +using Microsoft.AspNet.Razor.CodeGenerators.Visitors; using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Razor @@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Mvc.Razor private readonly string _injectAttribute; public InjectChunkVisitor([NotNull] CSharpCodeWriter writer, - [NotNull] CodeBuilderContext context, + [NotNull] CodeGeneratorContext context, [NotNull] string injectAttributeName) : base(writer, context) { diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/InjectParameterGenerator.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/InjectParameterGenerator.cs index 94ae029786..a2ed9c0686 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/InjectParameterGenerator.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/InjectParameterGenerator.cs @@ -3,12 +3,12 @@ using System; using System.Globalization; -using Microsoft.AspNet.Razor.Generator; +using Microsoft.AspNet.Razor.Chunks.Generators; using Microsoft.AspNet.Razor.Parser.SyntaxTree; namespace Microsoft.AspNet.Mvc.Razor { - public class InjectParameterGenerator : SpanCodeGenerator + public class InjectParameterGenerator : SpanChunkGenerator { public InjectParameterGenerator(string typeName, string propertyName) { @@ -20,10 +20,10 @@ namespace Microsoft.AspNet.Mvc.Razor public string PropertyName { get; private set; } - public override void GenerateCode(Span target, CodeGeneratorContext context) + public override void GenerateChunk(Span target, ChunkGeneratorContext context) { var injectChunk = new InjectChunk(TypeName, PropertyName); - context.CodeTreeBuilder.AddChunk(injectChunk, target); + context.ChunkTreeBuilder.AddChunk(injectChunk, target); } public override string ToString() diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/ModelChunk.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/ModelChunk.cs index a258cdfbfb..684b8bf2f2 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/ModelChunk.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/ModelChunk.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Razor.Generator.Compiler; +using Microsoft.AspNet.Razor.Chunks; namespace Microsoft.AspNet.Mvc.Razor { diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/ModelCodeGenerator.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/ModelChunkGenerator.cs similarity index 71% rename from src/Microsoft.AspNet.Mvc.Razor.Host/ModelCodeGenerator.cs rename to src/Microsoft.AspNet.Mvc.Razor.Host/ModelChunkGenerator.cs index fa1f632abf..a6650141d7 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/ModelCodeGenerator.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/ModelChunkGenerator.cs @@ -3,13 +3,14 @@ using System; using Microsoft.AspNet.Mvc.Razor; +using Microsoft.AspNet.Razor.Chunks.Generators; using Microsoft.AspNet.Razor.Parser.SyntaxTree; namespace Microsoft.AspNet.Razor.Generator { - public class ModelCodeGenerator : SpanCodeGenerator + public class ModelChunkGenerator : SpanChunkGenerator { - public ModelCodeGenerator(string baseType, string modelType) + public ModelChunkGenerator(string baseType, string modelType) { BaseType = baseType; ModelType = modelType; @@ -18,10 +19,10 @@ namespace Microsoft.AspNet.Razor.Generator public string BaseType { get; private set; } public string ModelType { get; private set; } - public override void GenerateCode(Span target, CodeGeneratorContext context) + public override void GenerateChunk(Span target, ChunkGeneratorContext context) { var modelChunk = new ModelChunk(BaseType, ModelType); - context.CodeTreeBuilder.AddChunk(modelChunk, target, topLevel: true); + context.ChunkTreeBuilder.AddChunk(modelChunk, target, topLevel: true); } public override string ToString() @@ -31,7 +32,7 @@ namespace Microsoft.AspNet.Razor.Generator public override bool Equals(object obj) { - var other = obj as ModelCodeGenerator; + var other = obj as ModelChunkGenerator; return other != null && string.Equals(ModelType, other.ModelType, StringComparison.Ordinal); } diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/ModelChunkVisitor.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/ModelChunkVisitor.cs index e0294f3749..81997ffe01 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/ModelChunkVisitor.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/ModelChunkVisitor.cs @@ -1,16 +1,17 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Razor.Generator; -using Microsoft.AspNet.Razor.Generator.Compiler.CSharp; +using Microsoft.AspNet.Razor.CodeGenerators; +using Microsoft.AspNet.Razor.CodeGenerators.Visitors; using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Razor { public class ModelChunkVisitor : MvcCSharpCodeVisitor { - public ModelChunkVisitor([NotNull] CSharpCodeWriter writer, - [NotNull] CodeBuilderContext context) + public ModelChunkVisitor( + [NotNull] CSharpCodeWriter writer, + [NotNull] CodeGeneratorContext context) : base(writer, context) { } diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcCSharpChunkVisitor.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcCSharpChunkVisitor.cs index a682d89c8a..036afe02f8 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcCSharpChunkVisitor.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcCSharpChunkVisitor.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Razor.Generator; -using Microsoft.AspNet.Razor.Generator.Compiler; -using Microsoft.AspNet.Razor.Generator.Compiler.CSharp; +using Microsoft.AspNet.Razor.Chunks; +using Microsoft.AspNet.Razor.CodeGenerators; +using Microsoft.AspNet.Razor.CodeGenerators.Visitors; using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Razor @@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Mvc.Razor public abstract class MvcCSharpChunkVisitor : CodeVisitor { public MvcCSharpChunkVisitor([NotNull] CSharpCodeWriter writer, - [NotNull] CodeBuilderContext context) + [NotNull] CodeGeneratorContext context) : base(writer, context) { } diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcCSharpCodeBuilder.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcCSharpCodeGenerator.cs similarity index 76% rename from src/Microsoft.AspNet.Mvc.Razor.Host/MvcCSharpCodeBuilder.cs rename to src/Microsoft.AspNet.Mvc.Razor.Host/MvcCSharpCodeGenerator.cs index 9851403bda..a37b01732a 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcCSharpCodeBuilder.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcCSharpCodeGenerator.cs @@ -3,23 +3,23 @@ using System.Globalization; using Microsoft.AspNet.Mvc.Razor.Directives; -using Microsoft.AspNet.Razor.Generator; -using Microsoft.AspNet.Razor.Generator.Compiler; -using Microsoft.AspNet.Razor.Generator.Compiler.CSharp; +using Microsoft.AspNet.Razor.CodeGenerators; +using Microsoft.AspNet.Razor.CodeGenerators.Visitors; using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Razor { - public class MvcCSharpCodeBuilder : CSharpCodeBuilder + public class MvcCSharpCodeGenerator : CSharpCodeGenerator { private readonly GeneratedTagHelperAttributeContext _tagHelperAttributeContext; private readonly string _defaultModel; private readonly string _injectAttribute; - public MvcCSharpCodeBuilder([NotNull] CodeBuilderContext context, - [NotNull] string defaultModel, - [NotNull] string injectAttribute, - [NotNull] GeneratedTagHelperAttributeContext tagHelperAttributeContext) + public MvcCSharpCodeGenerator( + [NotNull] CodeGeneratorContext context, + [NotNull] string defaultModel, + [NotNull] string injectAttribute, + [NotNull] GeneratedTagHelperAttributeContext tagHelperAttributeContext) : base(context) { _tagHelperAttributeContext = tagHelperAttributeContext; @@ -29,8 +29,9 @@ namespace Microsoft.AspNet.Mvc.Razor private string Model { get; set; } - protected override CSharpCodeVisitor CreateCSharpCodeVisitor([NotNull] CSharpCodeWriter writer, - [NotNull] CodeBuilderContext context) + protected override CSharpCodeVisitor CreateCSharpCodeVisitor( + [NotNull] CSharpCodeWriter writer, + [NotNull] CodeGeneratorContext context) { var csharpCodeVisitor = base.CreateCSharpCodeVisitor(writer, context); @@ -43,7 +44,7 @@ namespace Microsoft.AspNet.Mvc.Razor protected override CSharpCodeWritingScope BuildClassDeclaration(CSharpCodeWriter writer) { // Grab the last model chunk so it gets intellisense. - var modelChunk = ChunkHelper.GetModelChunk(Context.CodeTreeBuilder.CodeTree); + var modelChunk = ChunkHelper.GetModelChunk(Context.ChunkTreeBuilder.ChunkTree); Model = modelChunk != null ? modelChunk.ModelType : _defaultModel; @@ -73,7 +74,7 @@ namespace Microsoft.AspNet.Mvc.Razor writer.WriteLineHiddenDirective(); var injectVisitor = new InjectChunkVisitor(writer, Context, _injectAttribute); - injectVisitor.Accept(Context.CodeTreeBuilder.CodeTree.Chunks); + injectVisitor.Accept(Context.ChunkTreeBuilder.ChunkTree.Chunks); writer.WriteLine(); writer.WriteLineHiddenDirective(); diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcCSharpCodeVistor.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcCSharpCodeVistor.cs index 2f68e04bfe..6a7c42b765 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcCSharpCodeVistor.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcCSharpCodeVistor.cs @@ -1,16 +1,16 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Razor.Generator; -using Microsoft.AspNet.Razor.Generator.Compiler.CSharp; +using Microsoft.AspNet.Razor.CodeGenerators; using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Razor { public abstract class MvcCSharpCodeVisitor : MvcCSharpChunkVisitor { - public MvcCSharpCodeVisitor([NotNull] CSharpCodeWriter writer, - [NotNull] CodeBuilderContext context) + public MvcCSharpCodeVisitor( + [NotNull] CSharpCodeWriter writer, + [NotNull] CodeGeneratorContext context) : base(writer, context) { } diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorCodeParser.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorCodeParser.cs index 84470586ef..5e84fe68da 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorCodeParser.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorCodeParser.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using Microsoft.AspNet.Mvc.Razor.Host; using Microsoft.AspNet.Razor; +using Microsoft.AspNet.Razor.Chunks.Generators; using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser.SyntaxTree; @@ -55,7 +56,7 @@ namespace Microsoft.AspNet.Mvc.Razor BaseTypeDirective(Resources.FormatMvcRazorCodeParser_KeywordMustBeFollowedByTypeName(ModelKeyword), - CreateModelCodeGenerator); + CreateModelChunkGenerator); if (_modelStatementFound) { @@ -136,16 +137,16 @@ namespace Microsoft.AspNet.Mvc.Razor // ';' is optional propertyName = RemoveWhitespaceAndTrailingSemicolons(propertyName); - Span.CodeGenerator = new InjectParameterGenerator(typeName.Trim(), propertyName); + Span.ChunkGenerator = new InjectParameterGenerator(typeName.Trim(), propertyName); // Output the span and finish the block CompleteBlock(); Output(SpanKind.Code, AcceptedCharacters.AnyExceptNewline); } - private SpanCodeGenerator CreateModelCodeGenerator(string model) + private SpanChunkGenerator CreateModelChunkGenerator(string model) { - return new ModelCodeGenerator(_baseType, model); + return new ModelChunkGenerator(_baseType, model); } // Internal for unit testing diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorHost.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorHost.cs index 11753cdf39..9b1cb2392d 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorHost.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorHost.cs @@ -9,8 +9,8 @@ using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Mvc.Razor.Directives; using Microsoft.AspNet.Mvc.Razor.Internal; using Microsoft.AspNet.Razor; -using Microsoft.AspNet.Razor.Generator; -using Microsoft.AspNet.Razor.Generator.Compiler; +using Microsoft.AspNet.Razor.Chunks; +using Microsoft.AspNet.Razor.CodeGenerators; using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Runtime.TagHelpers; using Microsoft.Framework.Internal; @@ -41,16 +41,16 @@ namespace Microsoft.AspNet.Mvc.Razor // CodeGenerationContext.DefaultBaseClass is set to MyBaseType. // This field holds the type name without the generic decoration (MyBaseType) private readonly string _baseType; - private readonly ICodeTreeCache _codeTreeCache; + private readonly IChunkTreeCache _ChunkTreeCache; private readonly RazorPathNormalizer _pathNormalizer; private ChunkInheritanceUtility _chunkInheritanceUtility; - internal MvcRazorHost(ICodeTreeCache codeTreeCache, RazorPathNormalizer pathNormalizer) + internal MvcRazorHost(IChunkTreeCache ChunkTreeCache, RazorPathNormalizer pathNormalizer) : base(new CSharpRazorCodeLanguage()) { _pathNormalizer = pathNormalizer; _baseType = BaseType; - _codeTreeCache = codeTreeCache; + _ChunkTreeCache = ChunkTreeCache; TagHelperDescriptorResolver = new TagHelperDescriptorResolver(); DefaultBaseClass = BaseType + "<" + DefaultModel + ">"; @@ -116,19 +116,19 @@ namespace Microsoft.AspNet.Mvc.Razor /// The path to the application base. // Note: This constructor is used by tooling and is created once for each // Razor page that is loaded. Consequently, each loaded page has its own copy of - // the CodeTreeCache, but this ok - having a shared CodeTreeCache per application in tooling + // the ChunkTreeCache, but this ok - having a shared ChunkTreeCache per application in tooling // is problematic to manage. public MvcRazorHost(string root) - : this(new DefaultCodeTreeCache(new PhysicalFileProvider(root)), new DesignTimeRazorPathNormalizer(root)) + : this(new DefaultChunkTreeCache(new PhysicalFileProvider(root)), new DesignTimeRazorPathNormalizer(root)) { } #endif /// - /// Initializes a new instance of using the specified . + /// Initializes a new instance of using the specified . /// - /// An rooted at the application base path. - public MvcRazorHost(ICodeTreeCache codeTreeCache) - : this(codeTreeCache, new RazorPathNormalizer()) + /// An rooted at the application base path. + public MvcRazorHost(IChunkTreeCache ChunkTreeCache) + : this(ChunkTreeCache, new RazorPathNormalizer()) { } @@ -188,7 +188,7 @@ namespace Microsoft.AspNet.Mvc.Razor if (_chunkInheritanceUtility == null) { // This needs to be lazily evaluated to support DefaultInheritedChunks being virtual. - _chunkInheritanceUtility = new ChunkInheritanceUtility(this, _codeTreeCache, DefaultInheritedChunks); + _chunkInheritanceUtility = new ChunkInheritanceUtility(this, _ChunkTreeCache, DefaultInheritedChunks); } return _chunkInheritanceUtility; @@ -213,8 +213,8 @@ namespace Microsoft.AspNet.Mvc.Razor { sourceFileName = _pathNormalizer.NormalizePath(sourceFileName); - var inheritedCodeTrees = ChunkInheritanceUtility.GetInheritedCodeTrees(sourceFileName); - return new MvcRazorParser(razorParser, inheritedCodeTrees, DefaultInheritedChunks, ModelExpressionType); + var inheritedChunkTrees = ChunkInheritanceUtility.GetInheritedChunkTrees(sourceFileName); + return new MvcRazorParser(razorParser, inheritedChunkTrees, DefaultInheritedChunks, ModelExpressionType); } /// @@ -224,26 +224,29 @@ namespace Microsoft.AspNet.Mvc.Razor } /// - public override CodeBuilder DecorateCodeBuilder([NotNull] CodeBuilder incomingBuilder, - [NotNull] CodeBuilderContext context) + public override CodeGenerator DecorateCodeGenerator( + [NotNull] CodeGenerator incomingGenerator, + [NotNull] CodeGeneratorContext context) { // Need the normalized path to resolve inherited chunks only. Full paths are needed for generated Razor // files checksum and line pragmas to enable DesignTime debugging. var normalizedPath = _pathNormalizer.NormalizePath(context.SourceFile); - var inheritedChunks = ChunkInheritanceUtility.GetInheritedCodeTrees(normalizedPath); + var inheritedChunks = ChunkInheritanceUtility.GetInheritedChunkTrees(normalizedPath); - ChunkInheritanceUtility.MergeInheritedCodeTrees(context.CodeTreeBuilder.CodeTree, - inheritedChunks, - DefaultModel); + ChunkInheritanceUtility.MergeInheritedChunkTrees( + context.ChunkTreeBuilder.ChunkTree, + inheritedChunks, + DefaultModel); - return new MvcCSharpCodeBuilder(context, - DefaultModel, - InjectAttribute, - new GeneratedTagHelperAttributeContext - { - ModelExpressionTypeName = ModelExpressionType, - CreateModelExpressionMethodName = CreateModelExpressionMethod - }); + return new MvcCSharpCodeGenerator( + context, + DefaultModel, + InjectAttribute, + new GeneratedTagHelperAttributeContext + { + ModelExpressionTypeName = ModelExpressionType, + CreateModelExpressionMethodName = CreateModelExpressionMethod + }); } } } diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorParser.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorParser.cs index 24462e42c5..bbf5fc7447 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorParser.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorParser.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Mvc.Razor.Host; using Microsoft.AspNet.Razor; -using Microsoft.AspNet.Razor.Generator.Compiler; +using Microsoft.AspNet.Razor.Chunks; using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.TagHelpers; @@ -28,20 +28,20 @@ namespace Microsoft.AspNet.Mvc.Razor /// Initializes a new instance of . /// /// The to copy properties from. - /// The s that are inherited + /// The s that are inherited /// from parsed pages from _ViewImports files. /// The inherited by /// default by all Razor pages in the application. public MvcRazorParser( [NotNull] RazorParser parser, - [NotNull] IReadOnlyList inheritedCodeTrees, + [NotNull] IReadOnlyList inheritedChunkTrees, [NotNull] IReadOnlyList defaultInheritedChunks, [NotNull] string modelExpressionTypeName) : base(parser) { // Construct tag helper descriptors from @addTagHelper, @removeTagHelper and @tagHelperPrefix chunks _viewImportsDirectiveDescriptors = GetTagHelperDirectiveDescriptors( - inheritedCodeTrees, + inheritedChunkTrees, defaultInheritedChunks); _modelExpressionTypeName = modelExpressionTypeName; @@ -80,7 +80,7 @@ namespace Microsoft.AspNet.Mvc.Razor } private static IEnumerable GetTagHelperDirectiveDescriptors( - IReadOnlyList inheritedCodeTrees, + IReadOnlyList inheritedChunkTrees, IReadOnlyList defaultInheritedChunks) { var descriptors = new List(); @@ -89,7 +89,7 @@ namespace Microsoft.AspNet.Mvc.Razor // Consequently we must visit tag helpers outside-in - furthest _ViewImports first and nearest one last. // This is different from the behavior of chunk merging where we visit the nearest one first and ignore // chunks that were previously visited. - var chunksFromViewImports = inheritedCodeTrees + var chunksFromViewImports = inheritedChunkTrees .Reverse() .SelectMany(tree => tree.Chunks); var chunksInOrder = defaultInheritedChunks.Concat(chunksFromViewImports); diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcTagHelperAttributeValueCodeRenderer.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcTagHelperAttributeValueCodeRenderer.cs index 3eb428d2bc..953407f7ca 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcTagHelperAttributeValueCodeRenderer.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcTagHelperAttributeValueCodeRenderer.cs @@ -2,8 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Razor.Generator; -using Microsoft.AspNet.Razor.Generator.Compiler.CSharp; +using Microsoft.AspNet.Razor.CodeGenerators; using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.Framework.Internal; @@ -30,11 +29,12 @@ namespace Microsoft.AspNet.Mvc.Razor /// , then a model expression will be /// created by calling into . /// - public override void RenderAttributeValue([NotNull] TagHelperAttributeDescriptor attributeDescriptor, - [NotNull] CSharpCodeWriter writer, - [NotNull] CodeBuilderContext codeBuilderContext, - [NotNull] Action renderAttributeValue, - bool complexValue) + public override void RenderAttributeValue( + [NotNull] TagHelperAttributeDescriptor attributeDescriptor, + [NotNull] CSharpCodeWriter writer, + [NotNull] CodeGeneratorContext CodeGeneratorContext, + [NotNull] Action renderAttributeValue, + bool complexValue) { if (attributeDescriptor.TypeName.Equals(_context.ModelExpressionTypeName, StringComparison.Ordinal)) { @@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Mvc.Razor base.RenderAttributeValue( attributeDescriptor, writer, - codeBuilderContext, + CodeGeneratorContext, renderAttributeValue, complexValue); } diff --git a/src/Microsoft.AspNet.Mvc.Razor/Compilation/RazorCompilationService.cs b/src/Microsoft.AspNet.Mvc.Razor/Compilation/RazorCompilationService.cs index 69743552d6..d900fec816 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Compilation/RazorCompilationService.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Compilation/RazorCompilationService.cs @@ -7,6 +7,7 @@ using System.IO; using System.Linq; using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Razor; +using Microsoft.AspNet.Razor.CodeGenerators; using Microsoft.Framework.Internal; using Microsoft.Framework.OptionsModel; diff --git a/src/Microsoft.AspNet.Mvc.Razor/Precompilation/GeneratorResultExtensions.cs b/src/Microsoft.AspNet.Mvc.Razor/Precompilation/GeneratorResultExtensions.cs index db1458e3aa..8d7d665467 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Precompilation/GeneratorResultExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Precompilation/GeneratorResultExtensions.cs @@ -3,7 +3,7 @@ using System; using System.Linq; -using Microsoft.AspNet.Razor; +using Microsoft.AspNet.Razor.CodeGenerators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.Framework.Internal; diff --git a/src/Microsoft.AspNet.Mvc.Razor/Precompilation/RazorPreCompiler.cs b/src/Microsoft.AspNet.Mvc.Razor/Precompilation/RazorPreCompiler.cs index 29a788f2ef..9a0f0fc5b0 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Precompilation/RazorPreCompiler.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Precompilation/RazorPreCompiler.cs @@ -192,7 +192,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Precompilation protected IMvcRazorHost GetRazorHost() { var descriptorResolver = new TagHelperDescriptorResolver(TagHelperTypeResolver); - return new MvcRazorHost(new DefaultCodeTreeCache(FileProvider)) + return new MvcRazorHost(new DefaultChunkTreeCache(FileProvider)) { TagHelperDescriptorResolver = descriptorResolver }; diff --git a/src/Microsoft.AspNet.Mvc/MvcServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Mvc/MvcServiceCollectionExtensions.cs index 37bb13f21b..851889f04e 100644 --- a/src/Microsoft.AspNet.Mvc/MvcServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Mvc/MvcServiceCollectionExtensions.cs @@ -117,10 +117,10 @@ namespace Microsoft.Framework.DependencyInjection // Caches view locations that are valid for the lifetime of the application. services.TryAdd(ServiceDescriptor.Singleton()); - services.TryAdd(ServiceDescriptor.Singleton(serviceProvider => + services.TryAdd(ServiceDescriptor.Singleton(serviceProvider => { var cachedFileProvider = serviceProvider.GetRequiredService>(); - return new DefaultCodeTreeCache(cachedFileProvider.Options.FileProvider); + return new DefaultChunkTreeCache(cachedFileProvider.Options.FileProvider); })); // The host is designed to be discarded after consumption and is very inexpensive to initialize. diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/ChunkInheritanceUtilityTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/ChunkInheritanceUtilityTest.cs index 0f52bf1ce9..30f219aab3 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/ChunkInheritanceUtilityTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/ChunkInheritanceUtilityTest.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Razor.Generator.Compiler; +using Microsoft.AspNet.Razor.Chunks; using Xunit; namespace Microsoft.AspNet.Mvc.Razor.Directives @@ -30,19 +30,19 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives new InjectChunk("MyTestHtmlHelper", "Html"), new UsingChunk { Namespace = "AppNamespace.Model" }, }; - var cache = new DefaultCodeTreeCache(fileProvider); + var cache = new DefaultChunkTreeCache(fileProvider); var host = new MvcRazorHost(cache); var utility = new ChunkInheritanceUtility(host, cache, defaultChunks); // Act - var codeTrees = utility.GetInheritedCodeTrees(@"Views\home\Index.cshtml"); + var chunkTrees = utility.GetInheritedChunkTrees(@"Views\home\Index.cshtml"); // Assert - Assert.Collection(codeTrees, - codeTree => + Assert.Collection(chunkTrees, + ChunkTree => { var viewImportsPath = @"Views\home\_ViewImports.cshtml"; - Assert.Collection(codeTree.Chunks, + Assert.Collection(ChunkTree.Chunks, chunk => { Assert.IsType(chunk); @@ -60,10 +60,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives Assert.Equal(viewImportsPath, chunk.Start.FilePath); }); }, - codeTree => + ChunkTree => { var viewImportsPath = @"Views\_ViewImports.cshtml"; - Assert.Collection(codeTree.Chunks, + Assert.Collection(ChunkTree.Chunks, chunk => { Assert.IsType(chunk); @@ -114,7 +114,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives fileProvider.AddFile(@"_ViewImports.cs", string.Empty); fileProvider.AddFile(@"Views\_Layout.cshtml", string.Empty); fileProvider.AddFile(@"Views\home\_not-viewimports.cshtml", string.Empty); - var cache = new DefaultCodeTreeCache(fileProvider); + var cache = new DefaultChunkTreeCache(fileProvider); var host = new MvcRazorHost(cache); var defaultChunks = new Chunk[] { @@ -124,10 +124,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives var utility = new ChunkInheritanceUtility(host, cache, defaultChunks); // Act - var codeTrees = utility.GetInheritedCodeTrees(@"Views\home\Index.cshtml"); + var chunkTrees = utility.GetInheritedChunkTrees(@"Views\home\Index.cshtml"); // Assert - Assert.Empty(codeTrees); + Assert.Empty(chunkTrees); } [Fact] @@ -137,16 +137,16 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives var fileProvider = new TestFileProvider(); fileProvider.AddFile(@"Views\_ViewImports.cshtml", "@inject DifferentHelper Html"); - var cache = new DefaultCodeTreeCache(fileProvider); + var cache = new DefaultChunkTreeCache(fileProvider); var host = new MvcRazorHost(cache); var defaultChunks = new Chunk[] { new InjectChunk("MyTestHtmlHelper", "Html"), new UsingChunk { Namespace = "AppNamespace.Model" }, }; - var inheritedCodeTrees = new CodeTree[] + var inheritedChunkTrees = new ChunkTree[] { - new CodeTree + new ChunkTree { Chunks = new Chunk[] { @@ -154,7 +154,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives new LiteralChunk { Text = "some text" } } }, - new CodeTree + new ChunkTree { Chunks = new Chunk[] { @@ -164,18 +164,18 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives }; var utility = new ChunkInheritanceUtility(host, cache, defaultChunks); - var codeTree = new CodeTree(); + var chunkTree = new ChunkTree(); // Act - utility.MergeInheritedCodeTrees(codeTree, - inheritedCodeTrees, + utility.MergeInheritedChunkTrees(chunkTree, + inheritedChunkTrees, "dynamic"); // Assert - Assert.Equal(3, codeTree.Chunks.Count); - Assert.Same(inheritedCodeTrees[0].Chunks[0], codeTree.Chunks[0]); - Assert.Same(inheritedCodeTrees[1].Chunks[0], codeTree.Chunks[1]); - Assert.Same(defaultChunks[0], codeTree.Chunks[2]); + Assert.Equal(3, chunkTree.Chunks.Count); + Assert.Same(inheritedChunkTrees[0].Chunks[0], chunkTree.Chunks[0]); + Assert.Same(inheritedChunkTrees[1].Chunks[0], chunkTree.Chunks[1]); + Assert.Same(defaultChunks[0], chunkTree.Chunks[2]); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/DefaultCodeTreeCacheTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/DefaultCodeTreeCacheTest.cs index 676b320f8c..a6c7e8ebed 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/DefaultCodeTreeCacheTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/DefaultCodeTreeCacheTest.cs @@ -3,7 +3,7 @@ using System; using Microsoft.AspNet.Mvc.Razor.Directives; -using Microsoft.AspNet.Razor.Generator.Compiler; +using Microsoft.AspNet.Razor.Chunks; using Microsoft.Framework.Caching.Memory; using Microsoft.Framework.Internal; using Moq; @@ -11,7 +11,7 @@ using Xunit; namespace Microsoft.AspNet.Mvc.Razor.Host.Directives { - public class CodeTreeCacheTest + public class ChunkTreeCacheTest { [Fact] public void GetOrAdd_ReturnsCachedEntriesOnSubsequentCalls() @@ -21,12 +21,12 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives var mockFileProvider = new Mock { CallBase = true }; var fileProvider = mockFileProvider.Object; fileProvider.AddFile(path, "test content"); - var codeTreeCache = new DefaultCodeTreeCache(fileProvider); - var expected = new CodeTree(); + var chunkTreeCache = new DefaultChunkTreeCache(fileProvider); + var expected = new ChunkTree(); // Act - var result1 = codeTreeCache.GetOrAdd(path, fileInfo => expected); - var result2 = codeTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); }); + var result1 = chunkTreeCache.GetOrAdd(path, fileInfo => expected); + var result2 = chunkTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); }); // Assert Assert.Same(expected, result1); @@ -41,12 +41,12 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives var path = @"Views\_ViewStart.cshtml"; var mockFileProvider = new Mock { CallBase = true }; var fileProvider = mockFileProvider.Object; - var codeTreeCache = new DefaultCodeTreeCache(fileProvider); - var expected = new CodeTree(); + var chunkTreeCache = new DefaultChunkTreeCache(fileProvider); + var expected = new ChunkTree(); // Act - var result1 = codeTreeCache.GetOrAdd(path, fileInfo => expected); - var result2 = codeTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); }); + var result1 = chunkTreeCache.GetOrAdd(path, fileInfo => expected); + var result2 = chunkTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); }); // Assert Assert.Null(result1); @@ -61,19 +61,19 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives var path = @"Views\Home\_ViewStart.cshtml"; var fileProvider = new TestFileProvider(); fileProvider.AddFile(path, "test content"); - var codeTreeCache = new DefaultCodeTreeCache(fileProvider); - var expected1 = new CodeTree(); - var expected2 = new CodeTree(); + var chunkTreeCache = new DefaultChunkTreeCache(fileProvider); + var expected1 = new ChunkTree(); + var expected2 = new ChunkTree(); // Act 1 - var result1 = codeTreeCache.GetOrAdd(path, fileInfo => expected1); + var result1 = chunkTreeCache.GetOrAdd(path, fileInfo => expected1); // Assert 1 Assert.Same(expected1, result1); // Act 2 fileProvider.GetTrigger(path).IsExpired = true; - var result2 = codeTreeCache.GetOrAdd(path, fileInfo => expected2); + var result2 = chunkTreeCache.GetOrAdd(path, fileInfo => expected2); // Assert 2 Assert.Same(expected2, result2); @@ -86,11 +86,11 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives var path = @"Views\Home\_ViewStart.cshtml"; var fileProvider = new TestFileProvider(); fileProvider.AddFile(path, "test content"); - var codeTreeCache = new DefaultCodeTreeCache(fileProvider); - var expected1 = new CodeTree(); + var chunkTreeCache = new DefaultChunkTreeCache(fileProvider); + var expected1 = new ChunkTree(); // Act 1 - var result1 = codeTreeCache.GetOrAdd(path, fileInfo => expected1); + var result1 = chunkTreeCache.GetOrAdd(path, fileInfo => expected1); // Assert 1 Assert.Same(expected1, result1); @@ -98,7 +98,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives // Act 2 fileProvider.DeleteFile(path); fileProvider.GetTrigger(path).IsExpired = true; - var result2 = codeTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); }); + var result2 = chunkTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); }); // Assert 2 Assert.Null(result2); @@ -110,11 +110,11 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives // Arrange var path = @"Views\Home\_ViewStart.cshtml"; var fileProvider = new TestFileProvider(); - var codeTreeCache = new DefaultCodeTreeCache(fileProvider); - var expected = new CodeTree(); + var chunkTreeCache = new DefaultChunkTreeCache(fileProvider); + var expected = new ChunkTree(); // Act 1 - var result1 = codeTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); }); + var result1 = chunkTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); }); // Assert 1 Assert.Null(result1); @@ -122,7 +122,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives // Act 2 fileProvider.AddFile(path, "test content"); fileProvider.GetTrigger(path).IsExpired = true; - var result2 = codeTreeCache.GetOrAdd(path, fileInfo => expected); + var result2 = chunkTreeCache.GetOrAdd(path, fileInfo => expected); // Assert 2 Assert.Same(expected, result2); @@ -140,29 +140,29 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives clock.SetupGet(c => c.UtcNow) .Returns(() => utcNow); var options = new MemoryCacheOptions { Clock = clock.Object }; - var codeTreeCache = new DefaultCodeTreeCache(fileProvider, options); - var codeTree1 = new CodeTree(); - var codeTree2 = new CodeTree(); + var chunkTreeCache = new DefaultChunkTreeCache(fileProvider, options); + var chunkTree1 = new ChunkTree(); + var chunkTree2 = new ChunkTree(); // Act 1 - var result1 = codeTreeCache.GetOrAdd(path, fileInfo => codeTree1); + var result1 = chunkTreeCache.GetOrAdd(path, fileInfo => chunkTree1); // Assert 1 - Assert.Same(codeTree1, result1); + Assert.Same(chunkTree1, result1); // Act 2 utcNow = utcNow.AddSeconds(59); - var result2 = codeTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); }); + var result2 = chunkTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); }); // Assert 2 - Assert.Same(codeTree1, result2); + Assert.Same(chunkTree1, result2); // Act 3 utcNow = utcNow.AddSeconds(65); - var result3 = codeTreeCache.GetOrAdd(path, fileInfo => codeTree2); + var result3 = chunkTreeCache.GetOrAdd(path, fileInfo => chunkTree2); // Assert 3 - Assert.Same(codeTree2, result3); + Assert.Same(chunkTree2, result3); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/InjectChunkMergerTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/InjectChunkMergerTest.cs index 1dfbcaa445..41a3bbf451 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/InjectChunkMergerTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/InjectChunkMergerTest.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Razor.Generator.Compiler; +using Microsoft.AspNet.Razor.Chunks; using Microsoft.AspNet.Testing; using Xunit; @@ -45,41 +45,41 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives var merger = new InjectChunkMerger("dynamic"); // Act and Assert - ExceptionAssert.ThrowsArgument(() => merger.Merge(new CodeTree(), new LiteralChunk()), "chunk", expected); + ExceptionAssert.ThrowsArgument(() => merger.Merge(new ChunkTree(), new LiteralChunk()), "chunk", expected); } [Fact] - public void Merge_AddsChunkIfChunkWithMatchingPropertyNameWasNotVisitedInCodeTree() + public void Merge_AddsChunkIfChunkWithMatchingPropertyNameWasNotVisitedInChunkTree() { // Arrange var expectedType = "MyApp.MyHelperType"; var expectedProperty = "MyHelper"; var merger = new InjectChunkMerger("dynamic"); - var codeTree = new CodeTree(); + var chunkTree = new ChunkTree(); // Act - merger.Merge(codeTree, new InjectChunk(expectedType, expectedProperty)); + merger.Merge(chunkTree, new InjectChunk(expectedType, expectedProperty)); // Assert - var chunk = Assert.Single(codeTree.Chunks); + var chunk = Assert.Single(chunkTree.Chunks); var injectChunk = Assert.IsType(chunk); Assert.Equal(expectedType, injectChunk.TypeName); Assert.Equal(expectedProperty, injectChunk.MemberName); } [Fact] - public void Merge_IgnoresChunkIfChunkWithMatchingPropertyNameWasVisitedInCodeTree() + public void Merge_IgnoresChunkIfChunkWithMatchingPropertyNameWasVisitedInChunkTree() { // Arrange var merger = new InjectChunkMerger("dynamic"); - var codeTree = new CodeTree(); + var chunkTree = new ChunkTree(); // Act merger.VisitChunk(new InjectChunk("MyTypeA", "MyProperty")); - merger.Merge(codeTree, new InjectChunk("MyTypeB", "MyProperty")); + merger.Merge(chunkTree, new InjectChunk("MyTypeB", "MyProperty")); // Assert - Assert.Empty(codeTree.Chunks); + Assert.Empty(chunkTree.Chunks); } [Fact] @@ -87,20 +87,20 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives { // Arrange var merger = new InjectChunkMerger("dynamic"); - var codeTree = new CodeTree(); + var chunkTree = new ChunkTree(); // Act merger.VisitChunk(new InjectChunk("MyType", "MyProperty")); - merger.Merge(codeTree, new InjectChunk("MyType", "myproperty")); - merger.Merge(codeTree, new InjectChunk("MyTypeB", "different-property")); + merger.Merge(chunkTree, new InjectChunk("MyType", "myproperty")); + merger.Merge(chunkTree, new InjectChunk("MyTypeB", "different-property")); // Assert - Assert.Equal(2, codeTree.Chunks.Count); - var injectChunk = Assert.IsType(codeTree.Chunks[0]); + Assert.Equal(2, chunkTree.Chunks.Count); + var injectChunk = Assert.IsType(chunkTree.Chunks[0]); Assert.Equal("MyType", injectChunk.TypeName); Assert.Equal("myproperty", injectChunk.MemberName); - injectChunk = Assert.IsType(codeTree.Chunks[1]); + injectChunk = Assert.IsType(chunkTree.Chunks[1]); Assert.Equal("MyTypeB", injectChunk.TypeName); Assert.Equal("different-property", injectChunk.MemberName); } @@ -110,13 +110,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives { // Arrange var merger = new InjectChunkMerger("dynamic"); - var codeTree = new CodeTree(); + var chunkTree = new ChunkTree(); // Act - merger.Merge(codeTree, new InjectChunk("MyHelper", "MyProperty")); + merger.Merge(chunkTree, new InjectChunk("MyHelper", "MyProperty")); // Assert - var chunk = Assert.Single(codeTree.Chunks); + var chunk = Assert.Single(chunkTree.Chunks); var injectChunk = Assert.IsType(chunk); Assert.Equal("MyHelper", injectChunk.TypeName); Assert.Equal("MyProperty", injectChunk.MemberName); @@ -127,13 +127,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives { // Arrange var merger = new InjectChunkMerger("MyTestModel2"); - var codeTree = new CodeTree(); + var chunkTree = new ChunkTree(); // Act - merger.Merge(codeTree, new InjectChunk("MyHelper", "MyProperty")); + merger.Merge(chunkTree, new InjectChunk("MyHelper", "MyProperty")); // Assert - var chunk = Assert.Single(codeTree.Chunks); + var chunk = Assert.Single(chunkTree.Chunks); var injectChunk = Assert.IsType(chunk); Assert.Equal("MyHelper", injectChunk.TypeName); Assert.Equal("MyProperty", injectChunk.MemberName); @@ -144,14 +144,14 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives { // Arrange var merger = new InjectChunkMerger("dynamic"); - var codeTree = new CodeTree(); + var chunkTree = new ChunkTree(); // Act - merger.Merge(codeTree, new InjectChunk("SomeType", "Property")); - merger.Merge(codeTree, new InjectChunk("SomeOtherType", "Property")); + merger.Merge(chunkTree, new InjectChunk("SomeType", "Property")); + merger.Merge(chunkTree, new InjectChunk("SomeOtherType", "Property")); // Assert - var chunk = Assert.Single(codeTree.Chunks); + var chunk = Assert.Single(chunkTree.Chunks); var injectChunk = Assert.IsType(chunk); Assert.Equal("SomeType", injectChunk.TypeName); Assert.Equal("Property", injectChunk.MemberName); diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/SetBaseTypeChunkMergerTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/SetBaseTypeChunkMergerTest.cs index ef1a0cf87d..5142e455cc 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/SetBaseTypeChunkMergerTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/SetBaseTypeChunkMergerTest.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Razor.Generator.Compiler; +using Microsoft.AspNet.Razor.Chunks; using Microsoft.AspNet.Testing; using Xunit; @@ -14,7 +14,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives { // Arrange var expected = "Argument must be an instance of " + - "'Microsoft.AspNet.Razor.Generator.Compiler.SetBaseTypeChunk'."; + "'Microsoft.AspNet.Razor.Chunks.SetBaseTypeChunk'."; var merger = new SetBaseTypeChunkMerger("dynamic"); // Act and Assert @@ -45,43 +45,43 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives { // Arrange var expected = "Argument must be an instance of " + - "'Microsoft.AspNet.Razor.Generator.Compiler.SetBaseTypeChunk'."; + "'Microsoft.AspNet.Razor.Chunks.SetBaseTypeChunk'."; var merger = new SetBaseTypeChunkMerger("dynamic"); // Act and Assert - ExceptionAssert.ThrowsArgument(() => merger.Merge(new CodeTree(), new LiteralChunk()), "chunk", expected); + ExceptionAssert.ThrowsArgument(() => merger.Merge(new ChunkTree(), new LiteralChunk()), "chunk", expected); } [Fact] - public void Merge_SetsBaseTypeIfItHasNotBeenSetInCodeTree() + public void Merge_SetsBaseTypeIfItHasNotBeenSetInChunkTree() { // Arrange var expected = "MyApp.Razor.MyBaseType"; var merger = new SetBaseTypeChunkMerger("dynamic"); - var codeTree = new CodeTree(); + var chunkTree = new ChunkTree(); // Act - merger.Merge(codeTree, new SetBaseTypeChunk { TypeName = expected }); + merger.Merge(chunkTree, new SetBaseTypeChunk { TypeName = expected }); // Assert - var chunk = Assert.Single(codeTree.Chunks); + var chunk = Assert.Single(chunkTree.Chunks); var setBaseTypeChunk = Assert.IsType(chunk); Assert.Equal(expected, setBaseTypeChunk.TypeName); } [Fact] - public void Merge_IgnoresSetBaseTypeChunksIfCodeTreeContainsOne() + public void Merge_IgnoresSetBaseTypeChunksIfChunkTreeContainsOne() { // Arrange var merger = new SetBaseTypeChunkMerger("dynamic"); - var codeTree = new CodeTree(); + var chunkTree = new ChunkTree(); // Act merger.VisitChunk(new SetBaseTypeChunk { TypeName = "MyBaseType1" }); - merger.Merge(codeTree, new SetBaseTypeChunk { TypeName = "MyBaseType2" }); + merger.Merge(chunkTree, new SetBaseTypeChunk { TypeName = "MyBaseType2" }); // Assert - Assert.Empty(codeTree.Chunks); + Assert.Empty(chunkTree.Chunks); } [Fact] @@ -89,14 +89,14 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives { // Arrange var merger = new SetBaseTypeChunkMerger("dynamic"); - var codeTree = new CodeTree(); + var chunkTree = new ChunkTree(); // Act - merger.Merge(codeTree, new SetBaseTypeChunk { TypeName = "MyBase1" }); - merger.Merge(codeTree, new SetBaseTypeChunk { TypeName = "MyBase2" }); + merger.Merge(chunkTree, new SetBaseTypeChunk { TypeName = "MyBase1" }); + merger.Merge(chunkTree, new SetBaseTypeChunk { TypeName = "MyBase2" }); // Assert - var chunk = Assert.Single(codeTree.Chunks); + var chunk = Assert.Single(chunkTree.Chunks); var setBaseTypeChunk = Assert.IsType(chunk); Assert.Equal("MyBase1", setBaseTypeChunk.TypeName); } diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/UsingChunkMergerTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/UsingChunkMergerTest.cs index e924c7998b..58ea1daa8d 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/UsingChunkMergerTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/UsingChunkMergerTest.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Razor.Generator.Compiler; +using Microsoft.AspNet.Razor.Chunks; using Microsoft.AspNet.Testing; using Xunit; @@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives public void Visit_ThrowsIfThePassedInChunkIsNotAUsingChunk() { // Arrange - var expected = "Argument must be an instance of 'Microsoft.AspNet.Razor.Generator.Compiler.UsingChunk'."; + var expected = "Argument must be an instance of 'Microsoft.AspNet.Razor.Chunks.UsingChunk'."; var merger = new UsingChunkMerger(); // Act and Assert @@ -24,44 +24,44 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives public void Merge_ThrowsIfThePassedInChunkIsNotAUsingChunk() { // Arrange - var expected = "Argument must be an instance of 'Microsoft.AspNet.Razor.Generator.Compiler.UsingChunk'."; + var expected = "Argument must be an instance of 'Microsoft.AspNet.Razor.Chunks.UsingChunk'."; var merger = new UsingChunkMerger(); // Act and Assert - ExceptionAssert.ThrowsArgument(() => merger.Merge(new CodeTree(), new LiteralChunk()), "chunk", expected); + ExceptionAssert.ThrowsArgument(() => merger.Merge(new ChunkTree(), new LiteralChunk()), "chunk", expected); } [Fact] - public void Merge_AddsNamespacesThatHaveNotBeenVisitedInCodeTree() + public void Merge_AddsNamespacesThatHaveNotBeenVisitedInChunkTree() { // Arrange var expected = "MyApp.Models"; var merger = new UsingChunkMerger(); - var codeTree = new CodeTree(); + var chunkTree = new ChunkTree(); // Act merger.VisitChunk(new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }); - merger.Merge(codeTree, new UsingChunk { Namespace = expected }); + merger.Merge(chunkTree, new UsingChunk { Namespace = expected }); // Assert - var chunk = Assert.Single(codeTree.Chunks); + var chunk = Assert.Single(chunkTree.Chunks); var usingChunk = Assert.IsType(chunk); Assert.Equal(expected, usingChunk.Namespace); } [Fact] - public void Merge_IgnoresNamespacesThatHaveBeenVisitedInCodeTree() + public void Merge_IgnoresNamespacesThatHaveBeenVisitedInChunkTree() { // Arrange var merger = new UsingChunkMerger(); - var codeTree = new CodeTree(); + var chunkTree = new ChunkTree(); // Act merger.VisitChunk(new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }); - merger.Merge(codeTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }); + merger.Merge(chunkTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }); // Assert - Assert.Empty(codeTree.Chunks); + Assert.Empty(chunkTree.Chunks); } [Fact] @@ -69,18 +69,18 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives { // Arrange var merger = new UsingChunkMerger(); - var codeTree = new CodeTree(); + var chunkTree = new ChunkTree(); // Act - merger.Merge(codeTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }); - merger.Merge(codeTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }); - merger.Merge(codeTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc.Razor" }); + merger.Merge(chunkTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }); + merger.Merge(chunkTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }); + merger.Merge(chunkTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc.Razor" }); // Assert - Assert.Equal(2, codeTree.Chunks.Count); - var chunk = Assert.IsType(codeTree.Chunks[0]); + Assert.Equal(2, chunkTree.Chunks.Count); + var chunk = Assert.IsType(chunkTree.Chunks[0]); Assert.Equal("Microsoft.AspNet.Mvc", chunk.Namespace); - chunk = Assert.IsType(codeTree.Chunks[1]); + chunk = Assert.IsType(chunkTree.Chunks[1]); Assert.Equal("Microsoft.AspNet.Mvc.Razor", chunk.Namespace); } @@ -89,17 +89,17 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives { // Arrange var merger = new UsingChunkMerger(); - var codeTree = new CodeTree(); + var chunkTree = new ChunkTree(); // Act - merger.Merge(codeTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }); - merger.Merge(codeTree, new UsingChunk { Namespace = "Microsoft.AspNet.mvc" }); + merger.Merge(chunkTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }); + merger.Merge(chunkTree, new UsingChunk { Namespace = "Microsoft.AspNet.mvc" }); // Assert - Assert.Equal(2, codeTree.Chunks.Count); - var chunk = Assert.IsType(codeTree.Chunks[0]); + Assert.Equal(2, chunkTree.Chunks.Count); + var chunk = Assert.IsType(chunkTree.Chunks[0]); Assert.Equal("Microsoft.AspNet.Mvc", chunk.Namespace); - chunk = Assert.IsType(codeTree.Chunks[1]); + chunk = Assert.IsType(chunkTree.Chunks[1]); Assert.Equal("Microsoft.AspNet.mvc", chunk.Namespace); } } diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/InjectChunkVisitorTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/InjectChunkVisitorTest.cs index cda283ffb8..56477a4a07 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/InjectChunkVisitorTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/InjectChunkVisitorTest.cs @@ -4,9 +4,9 @@ using System; using Microsoft.AspNet.Mvc.Razor.Directives; using Microsoft.AspNet.Razor; -using Microsoft.AspNet.Razor.Generator; -using Microsoft.AspNet.Razor.Generator.Compiler; -using Microsoft.AspNet.Razor.Generator.Compiler.CSharp; +using Microsoft.AspNet.Razor.Chunks; +using Microsoft.AspNet.Razor.Chunks.Generators; +using Microsoft.AspNet.Razor.CodeGenerators; using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Xunit; @@ -144,15 +144,16 @@ MyType1 Assert.Equal(expected, code); } - private static CodeBuilderContext CreateContext() + private static CodeGeneratorContext CreateContext() { - var codeTreeCache = new DefaultCodeTreeCache(new TestFileProvider()); - return new CodeBuilderContext( - new CodeGeneratorContext(new MvcRazorHost(codeTreeCache), - "MyClass", - "MyNamespace", - string.Empty, - shouldGenerateLinePragmas: true), + var chunkTreeCache = new DefaultChunkTreeCache(new TestFileProvider()); + return new CodeGeneratorContext( + new ChunkGeneratorContext( + new MvcRazorHost(chunkTreeCache), + "MyClass", + "MyNamespace", + string.Empty, + shouldGenerateLinePragmas: true), new ErrorSink()); } } diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/ModelChunkVisitorTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/ModelChunkVisitorTest.cs index 1cd133f913..1c188335f4 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/ModelChunkVisitorTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/ModelChunkVisitorTest.cs @@ -4,9 +4,10 @@ using System; using Microsoft.AspNet.Mvc.Razor.Directives; using Microsoft.AspNet.Razor; +using Microsoft.AspNet.Razor.Chunks; +using Microsoft.AspNet.Razor.Chunks.Generators; +using Microsoft.AspNet.Razor.CodeGenerators; using Microsoft.AspNet.Razor.Generator; -using Microsoft.AspNet.Razor.Generator.Compiler; -using Microsoft.AspNet.Razor.Generator.Compiler.CSharp; using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Xunit; @@ -53,7 +54,7 @@ Environment.NewLine + var visitor = new ModelChunkVisitor(writer, context); var factory = SpanFactory.CreateCsHtml(); var node = (Span)factory.Code("Some code") - .As(new ModelCodeGenerator("MyBase", "MyGeneric")); + .As(new ModelChunkGenerator("MyBase", "MyGeneric")); // Act visitor.Accept(new Chunk[] @@ -86,7 +87,7 @@ Environment.NewLine + var visitor = new ModelChunkVisitor(writer, context); var factory = SpanFactory.CreateCsHtml(); var node = (Span)factory.Code("Some code") - .As(new ModelCodeGenerator("MyType", "MyPropertyName")); + .As(new ModelChunkGenerator("MyType", "MyPropertyName")); // Act visitor.Accept(new Chunk[] @@ -100,15 +101,16 @@ Environment.NewLine + Assert.Equal(expected, code); } - private static CodeBuilderContext CreateContext() + private static CodeGeneratorContext CreateContext() { var fileProvider = new TestFileProvider(); - return new CodeBuilderContext( - new CodeGeneratorContext(new MvcRazorHost(new DefaultCodeTreeCache(fileProvider)), - "MyClass", - "MyNamespace", - string.Empty, - shouldGenerateLinePragmas: true), + return new CodeGeneratorContext( + new ChunkGeneratorContext( + new MvcRazorHost(new DefaultChunkTreeCache(fileProvider)), + "MyClass", + "MyNamespace", + string.Empty, + shouldGenerateLinePragmas: true), new ErrorSink()); } } diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcCSharpRazorCodeParserTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcCSharpRazorCodeParserTest.cs index 97bd1118e3..1a3c5c03c9 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcCSharpRazorCodeParserTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcCSharpRazorCodeParserTest.cs @@ -5,8 +5,9 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Razor; +using Microsoft.AspNet.Razor.Chunks.Generators; +using Microsoft.AspNet.Razor.CodeGenerators; using Microsoft.AspNet.Razor.Generator; -using Microsoft.AspNet.Razor.Generator.Compiler; using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Text; @@ -46,7 +47,7 @@ namespace Microsoft.AspNet.Mvc.Razor factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code(" Foo") - .As(new ModelCodeGenerator("RazorView", "Foo")) + .As(new ModelChunkGenerator("RazorView", "Foo")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml() }; @@ -78,10 +79,10 @@ namespace Microsoft.AspNet.Mvc.Razor factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code(modelName + "\r\n") - .As(new ModelCodeGenerator("RazorView", expectedModel)) + .As(new ModelChunkGenerator("RazorView", expectedModel)) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.Markup("Bar") - .With(new MarkupCodeGenerator()) + .With(new MarkupChunkGenerator()) }; // Act @@ -110,7 +111,7 @@ namespace Microsoft.AspNet.Mvc.Razor factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code(" ") - .As(new ModelCodeGenerator("RazorView", string.Empty)) + .As(new ModelChunkGenerator("RazorView", string.Empty)) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml(), }; @@ -141,7 +142,7 @@ namespace Microsoft.AspNet.Mvc.Razor factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code("Foo\r\n") - .As(new ModelCodeGenerator("RazorView", "Foo")) + .As(new ModelChunkGenerator("RazorView", "Foo")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml(), factory.CodeTransition(SyntaxConstants.TransitionString) @@ -149,7 +150,7 @@ namespace Microsoft.AspNet.Mvc.Razor factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code("Bar") - .As(new ModelCodeGenerator("RazorView", "Bar")) + .As(new ModelChunkGenerator("RazorView", "Bar")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml() }; @@ -186,7 +187,7 @@ namespace Microsoft.AspNet.Mvc.Razor factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code("Foo\r\n") - .As(new ModelCodeGenerator("RazorView", "Foo")) + .As(new ModelChunkGenerator("RazorView", "Foo")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml(), factory.CodeTransition(SyntaxConstants.TransitionString) @@ -194,7 +195,7 @@ namespace Microsoft.AspNet.Mvc.Razor factory.MetaCode("inherits ") .Accepts(AcceptedCharacters.None), factory.Code("Bar") - .As(new SetBaseTypeCodeGenerator("Bar")) + .As(new SetBaseTypeChunkGenerator("Bar")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml() }; @@ -231,7 +232,7 @@ namespace Microsoft.AspNet.Mvc.Razor factory.MetaCode("inherits ") .Accepts(AcceptedCharacters.None), factory.Code("Bar" + Environment.NewLine) - .As(new SetBaseTypeCodeGenerator("Bar")) + .As(new SetBaseTypeChunkGenerator("Bar")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml(), factory.CodeTransition(SyntaxConstants.TransitionString) @@ -239,7 +240,7 @@ namespace Microsoft.AspNet.Mvc.Razor factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code("Foo") - .As(new ModelCodeGenerator("RazorView", "Foo")) + .As(new ModelChunkGenerator("RazorView", "Foo")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml() }; @@ -360,7 +361,7 @@ namespace Microsoft.AspNet.Mvc.Razor .As(new InjectParameterGenerator(expectedService, expectedPropertyName)) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.Markup("Bar") - .With(new MarkupCodeGenerator()) + .With(new MarkupChunkGenerator()) }; // Act @@ -389,7 +390,7 @@ namespace Microsoft.AspNet.Mvc.Razor .As(new InjectParameterGenerator(string.Empty, string.Empty)) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.Markup("Bar") - .With(new MarkupCodeGenerator()) + .With(new MarkupChunkGenerator()) }; var expectedErrors = new[] { @@ -456,7 +457,7 @@ namespace Microsoft.AspNet.Mvc.Razor .As(new InjectParameterGenerator("IMyService", string.Empty)) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.Markup("Bar") - .With(new MarkupCodeGenerator()) + .With(new MarkupChunkGenerator()) }; var expectedErrors = new[] { diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcRazorHostTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcRazorHostTest.cs index 7d379f54e7..5dabb95927 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcRazorHostTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcRazorHostTest.cs @@ -7,9 +7,10 @@ using System.IO; using Microsoft.AspNet.Mvc.Razor.Directives; using Microsoft.AspNet.Mvc.Razor.Internal; using Microsoft.AspNet.Razor; -using Microsoft.AspNet.Razor.Generator; -using Microsoft.AspNet.Razor.Generator.Compiler; -using Microsoft.AspNet.Razor.Generator.Compiler.CSharp; +using Microsoft.AspNet.Razor.Chunks; +using Microsoft.AspNet.Razor.Chunks.Generators; +using Microsoft.AspNet.Razor.CodeGenerators; +using Microsoft.AspNet.Razor.CodeGenerators.Visitors; using Microsoft.AspNet.Razor.Parser; using Microsoft.Framework.Internal; using Xunit; @@ -30,7 +31,7 @@ namespace Microsoft.AspNet.Mvc.Razor var rootedAppPath = $"{rootPrefix}SomeComputer/Location/Project/"; var rootedFilePath = $"{rootPrefix}SomeComputer/Location/Project/src/file.cshtml"; var host = new MvcRazorHost( - codeTreeCache: null, + ChunkTreeCache: null, pathNormalizer: new DesignTimeRazorPathNormalizer(rootedAppPath)); var parser = new RazorParser( host.CodeLanguage.CreateCodeParser(), @@ -43,7 +44,7 @@ namespace Microsoft.AspNet.Mvc.Razor host.DecorateRazorParser(parser, rootedFilePath); // Assert - Assert.Equal("src/file.cshtml", chunkInheritanceUtility.InheritedCodeTreePagePath, StringComparer.Ordinal); + Assert.Equal("src/file.cshtml", chunkInheritanceUtility.InheritedChunkTreePagePath, StringComparer.Ordinal); } [Theory] @@ -51,32 +52,32 @@ namespace Microsoft.AspNet.Mvc.Razor [InlineData("C:/")] [InlineData(@"\\")] [InlineData(@"C:\")] - public void DecorateCodeBuilder_DesignTimeRazorPathNormalizer_NormalizesChunkInheritanceUtilityPaths( + public void DecorateCodeGenerator_DesignTimeRazorPathNormalizer_NormalizesChunkInheritanceUtilityPaths( string rootPrefix) { // Arrange var rootedAppPath = $"{rootPrefix}SomeComputer/Location/Project/"; var rootedFilePath = $"{rootPrefix}SomeComputer/Location/Project/src/file.cshtml"; var host = new MvcRazorHost( - codeTreeCache: null, + ChunkTreeCache: null, pathNormalizer: new DesignTimeRazorPathNormalizer(rootedAppPath)); var chunkInheritanceUtility = new PathValidatingChunkInheritanceUtility(host); - var codeBuilderContext = new CodeBuilderContext( - new CodeGeneratorContext( + var CodeGeneratorContext = new CodeGeneratorContext( + new ChunkGeneratorContext( host, host.DefaultClassName, host.DefaultNamespace, rootedFilePath, shouldGenerateLinePragmas: true), new ErrorSink()); - var codeBuilder = new CSharpCodeBuilder(codeBuilderContext); + var codeGenerator = new CSharpCodeGenerator(CodeGeneratorContext); host.ChunkInheritanceUtility = chunkInheritanceUtility; // Act - host.DecorateCodeBuilder(codeBuilder, codeBuilderContext); + host.DecorateCodeGenerator(codeGenerator, CodeGeneratorContext); // Assert - Assert.Equal("src/file.cshtml", chunkInheritanceUtility.InheritedCodeTreePagePath, StringComparer.Ordinal); + Assert.Equal("src/file.cshtml", chunkInheritanceUtility.InheritedChunkTreePagePath, StringComparer.Ordinal); } [Fact] @@ -84,7 +85,7 @@ namespace Microsoft.AspNet.Mvc.Razor { // Arrange var fileProvider = new TestFileProvider(); - var host = new MvcRazorHost(new DefaultCodeTreeCache(fileProvider)); + var host = new MvcRazorHost(new DefaultChunkTreeCache(fileProvider)); // Act var instrumented = host.EnableInstrumentation; @@ -98,7 +99,7 @@ namespace Microsoft.AspNet.Mvc.Razor { // Arrange var fileProvider = new TestFileProvider(); - var host = new MvcRazorHost(new DefaultCodeTreeCache(fileProvider)) + var host = new MvcRazorHost(new DefaultChunkTreeCache(fileProvider)) { DesignTimeMode = true }; @@ -152,7 +153,7 @@ namespace Microsoft.AspNet.Mvc.Razor { // Arrange var fileProvider = new TestFileProvider(); - var host = new TestMvcRazorHost(new DefaultCodeTreeCache(fileProvider)); + var host = new TestMvcRazorHost(new DefaultChunkTreeCache(fileProvider)); // Act and Assert RunRuntimeTest(host, scenarioName); @@ -163,7 +164,7 @@ namespace Microsoft.AspNet.Mvc.Razor { // Arrange var fileProvider = new TestFileProvider(); - var host = new MvcRazorHost(new DefaultCodeTreeCache(fileProvider)) + var host = new MvcRazorHost(new DefaultChunkTreeCache(fileProvider)) { DesignTimeMode = true }; @@ -183,7 +184,7 @@ namespace Microsoft.AspNet.Mvc.Razor { // Arrange var fileProvider = new TestFileProvider(); - var host = new MvcRazorHost(new DefaultCodeTreeCache(fileProvider)) + var host = new MvcRazorHost(new DefaultChunkTreeCache(fileProvider)) { DesignTimeMode = true }; @@ -204,12 +205,12 @@ namespace Microsoft.AspNet.Mvc.Razor { // Arrange var fileProvider = new TestFileProvider(); - var host = new MvcRazorHost(new DefaultCodeTreeCache(fileProvider)) + var host = new MvcRazorHost(new DefaultChunkTreeCache(fileProvider)) { DesignTimeMode = true }; host.NamespaceImports.Clear(); - var expectedLineMappings = new [] + var expectedLineMappings = new[] { BuildLineMapping(7, 0, 7, 222, 6, 7, 7), BuildLineMapping(24, 1, 8, 747, 26, 8, 20), @@ -227,7 +228,7 @@ namespace Microsoft.AspNet.Mvc.Razor { // Arrange var fileProvider = new TestFileProvider(); - var host = new MvcRazorHost(new DefaultCodeTreeCache(fileProvider)) + var host = new MvcRazorHost(new DefaultChunkTreeCache(fileProvider)) { DesignTimeMode = true }; @@ -323,17 +324,17 @@ namespace Microsoft.AspNet.Mvc.Razor private class PathValidatingChunkInheritanceUtility : ChunkInheritanceUtility { public PathValidatingChunkInheritanceUtility(MvcRazorHost razorHost) - : base(razorHost, codeTreeCache: null, defaultInheritedChunks: new Chunk[0]) + : base(razorHost, chunkTreeCache: null, defaultInheritedChunks: new Chunk[0]) { } - public string InheritedCodeTreePagePath { get; private set; } + public string InheritedChunkTreePagePath { get; private set; } - public override IReadOnlyList GetInheritedCodeTrees([NotNull] string pagePath) + public override IReadOnlyList GetInheritedChunkTrees([NotNull] string pagePath) { - InheritedCodeTreePagePath = pagePath; + InheritedChunkTreePagePath = pagePath; - return new CodeTree[0]; + return new ChunkTree[0]; } } @@ -342,15 +343,15 @@ namespace Microsoft.AspNet.Mvc.Razor /// private class TestMvcRazorHost : MvcRazorHost { - public TestMvcRazorHost(ICodeTreeCache codeTreeCache) - : base(codeTreeCache) + public TestMvcRazorHost(IChunkTreeCache ChunkTreeCache) + : base(ChunkTreeCache) { } - public override CodeBuilder DecorateCodeBuilder(CodeBuilder incomingBuilder, CodeBuilderContext context) + public override CodeGenerator DecorateCodeGenerator(CodeGenerator incomingBuilder, CodeGeneratorContext context) { - base.DecorateCodeBuilder(incomingBuilder, context); + base.DecorateCodeGenerator(incomingBuilder, context); - return new TestCSharpCodeBuilder(context, + return new TestCSharpCodeGenerator(context, DefaultModel, "Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute", new GeneratedTagHelperAttributeContext @@ -360,11 +361,11 @@ namespace Microsoft.AspNet.Mvc.Razor }); } - protected class TestCSharpCodeBuilder : MvcCSharpCodeBuilder + protected class TestCSharpCodeGenerator : MvcCSharpCodeGenerator { private readonly GeneratedTagHelperAttributeContext _tagHelperAttributeContext; - public TestCSharpCodeBuilder(CodeBuilderContext context, + public TestCSharpCodeGenerator(CodeGeneratorContext context, string defaultModel, string activateAttribute, GeneratedTagHelperAttributeContext tagHelperAttributeContext) @@ -373,7 +374,7 @@ namespace Microsoft.AspNet.Mvc.Razor _tagHelperAttributeContext = tagHelperAttributeContext; } - protected override CSharpCodeVisitor CreateCSharpCodeVisitor(CSharpCodeWriter writer, CodeBuilderContext context) + protected override CSharpCodeVisitor CreateCSharpCodeVisitor(CSharpCodeWriter writer, CodeGeneratorContext context) { var visitor = base.CreateCSharpCodeVisitor(writer, context); visitor.TagHelperRenderer = new NoUniqueIdsTagHelperCodeRenderer(visitor, writer, context) @@ -388,7 +389,7 @@ namespace Microsoft.AspNet.Mvc.Razor { public NoUniqueIdsTagHelperCodeRenderer(IChunkVisitor bodyVisitor, CSharpCodeWriter writer, - CodeBuilderContext context) + CodeGeneratorContext context) : base(bodyVisitor, writer, context) { } diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcRazorParserTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcRazorParserTest.cs index c289e3edb3..bc5b516040 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcRazorParserTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcRazorParserTest.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Razor; -using Microsoft.AspNet.Razor.Generator.Compiler; +using Microsoft.AspNet.Razor.Chunks; using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.TagHelpers; @@ -21,21 +21,21 @@ namespace Microsoft.AspNet.Mvc.Razor { get { - // codeTrees, expectedDirectiveDescriptors - return new TheoryData + // chunkTrees, expectedDirectiveDescriptors + return new TheoryData { { - new[] { CreateCodeTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP" }) }, + new[] { CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP" }) }, new[] { CreateDirectiveDescriptor("THP", TagHelperDirectiveType.TagHelperPrefix) } }, { - new[] { CreateCodeTree(new AddTagHelperChunk { LookupText = "ATH" }) }, + new[] { CreateChunkTree(new AddTagHelperChunk { LookupText = "ATH" }) }, new[] { CreateDirectiveDescriptor("ATH", TagHelperDirectiveType.AddTagHelper) } }, { new[] { - CreateCodeTree( + CreateChunkTree( new AddTagHelperChunk { LookupText = "ATH1" }, new AddTagHelperChunk { LookupText = "ATH2" }) }, @@ -46,13 +46,13 @@ namespace Microsoft.AspNet.Mvc.Razor } }, { - new[] { CreateCodeTree(new RemoveTagHelperChunk { LookupText = "RTH" }) }, + new[] { CreateChunkTree(new RemoveTagHelperChunk { LookupText = "RTH" }) }, new[] { CreateDirectiveDescriptor("RTH", TagHelperDirectiveType.RemoveTagHelper) } }, { new[] { - CreateCodeTree( + CreateChunkTree( new RemoveTagHelperChunk { LookupText = "RTH1" }, new RemoveTagHelperChunk { LookupText = "RTH2" }) }, @@ -65,15 +65,15 @@ namespace Microsoft.AspNet.Mvc.Razor { new[] { - CreateCodeTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP1" }), - CreateCodeTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP2" }), + CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP1" }), + CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP2" }), }, new[] { CreateDirectiveDescriptor("THP1", TagHelperDirectiveType.TagHelperPrefix) } }, { new[] { - CreateCodeTree( + CreateChunkTree( new TagHelperPrefixDirectiveChunk { Prefix = "THP" }, new RemoveTagHelperChunk { LookupText = "RTH" }, new AddTagHelperChunk { LookupText = "ATH" }) @@ -88,10 +88,10 @@ namespace Microsoft.AspNet.Mvc.Razor { new[] { - CreateCodeTree( + CreateChunkTree( new LiteralChunk { Text = "Hello world" }, new AddTagHelperChunk { LookupText = "ATH" }), - CreateCodeTree(new RemoveTagHelperChunk { LookupText = "RTH" }) + CreateChunkTree(new RemoveTagHelperChunk { LookupText = "RTH" }) }, new[] { @@ -102,11 +102,11 @@ namespace Microsoft.AspNet.Mvc.Razor { new[] { - CreateCodeTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP" }), - CreateCodeTree( + CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP" }), + CreateChunkTree( new LiteralChunk { Text = "Hello world" }, new AddTagHelperChunk { LookupText = "ATH" }), - CreateCodeTree(new RemoveTagHelperChunk { LookupText = "RTH" }) + CreateChunkTree(new RemoveTagHelperChunk { LookupText = "RTH" }) }, new[] { @@ -118,10 +118,10 @@ namespace Microsoft.AspNet.Mvc.Razor { new[] { - CreateCodeTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP1" }), - CreateCodeTree(new AddTagHelperChunk { LookupText = "ATH" }), - CreateCodeTree(new RemoveTagHelperChunk { LookupText = "RTH" }), - CreateCodeTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP2" }), + CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP1" }), + CreateChunkTree(new AddTagHelperChunk { LookupText = "ATH" }), + CreateChunkTree(new RemoveTagHelperChunk { LookupText = "RTH" }), + CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP2" }), }, new[] { @@ -137,7 +137,7 @@ namespace Microsoft.AspNet.Mvc.Razor [Theory] [MemberData(nameof(ViewImportsData))] public void GetTagHelperDescriptors_ReturnsExpectedDirectiveDescriptors( - CodeTree[] codeTrees, + ChunkTree[] chunkTrees, TagHelperDirectiveDescriptor[] expectedDirectiveDescriptors) { // Arrange @@ -158,7 +158,7 @@ namespace Microsoft.AspNet.Mvc.Razor new CSharpCodeParser(), new HtmlMarkupParser(), tagHelperDescriptorResolver: resolver.Object); - var parser = new TestableMvcRazorParser(baseParser, codeTrees, defaultInheritedChunks: new Chunk[0]); + var parser = new TestableMvcRazorParser(baseParser, chunkTrees, defaultInheritedChunks: new Chunk[0]); // Act parser.GetTagHelperDescriptorsPublic(block, errorSink: new ErrorSink()).ToArray(); @@ -211,9 +211,9 @@ namespace Microsoft.AspNet.Mvc.Razor Assert.Equal(expectedOutput, output, StringComparer.Ordinal); } - private static CodeTree CreateCodeTree(params Chunk[] chunks) + private static ChunkTree CreateChunkTree(params Chunk[] chunks) { - return new CodeTree + return new ChunkTree { Chunks = chunks }; @@ -229,9 +229,9 @@ namespace Microsoft.AspNet.Mvc.Razor private class TestableMvcRazorParser : MvcRazorParser { public TestableMvcRazorParser(RazorParser parser, - IReadOnlyList codeTrees, + IReadOnlyList chunkTrees, IReadOnlyList defaultInheritedChunks) - : base(parser, codeTrees, defaultInheritedChunks, typeof(ModelExpression).FullName) + : base(parser, chunkTrees, defaultInheritedChunks, typeof(ModelExpression).FullName) { } diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcTagHelperAttributeValueCodeRendererTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcTagHelperAttributeValueCodeRendererTest.cs index 5b0728404d..5dbf4ff1c5 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcTagHelperAttributeValueCodeRendererTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcTagHelperAttributeValueCodeRendererTest.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Razor; -using Microsoft.AspNet.Razor.Generator; -using Microsoft.AspNet.Razor.Generator.Compiler.CSharp; +using Microsoft.AspNet.Razor.Chunks.Generators; +using Microsoft.AspNet.Razor.CodeGenerators; using Microsoft.AspNet.Razor.TagHelpers; using Xunit; @@ -31,13 +31,14 @@ namespace Microsoft.AspNet.Mvc.Razor typeName: propertyType, isIndexer: false); var writer = new CSharpCodeWriter(); - var generatorContext = new CodeGeneratorContext(host: null, - className: string.Empty, - rootNamespace: string.Empty, - sourceFile: string.Empty, - shouldGenerateLinePragmas: true); + var generatorContext = new ChunkGeneratorContext( + host: null, + className: string.Empty, + rootNamespace: string.Empty, + sourceFile: string.Empty, + shouldGenerateLinePragmas: true); var errorSink = new ErrorSink(); - var context = new CodeBuilderContext(generatorContext, errorSink); + var context = new CodeGeneratorContext(generatorContext, errorSink); // Act renderer.RenderAttributeValue(attributeDescriptor, writer, context, diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/SpanFactory/SpanConstructor.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/SpanFactory/SpanConstructor.cs index 45f3257652..2c8e22b274 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/SpanFactory/SpanConstructor.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/SpanFactory/SpanConstructor.cs @@ -4,8 +4,8 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Razor; +using Microsoft.AspNet.Razor.Chunks.Generators; using Microsoft.AspNet.Razor.Editor; -using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Tokenizer.Symbols; @@ -36,9 +36,9 @@ namespace Microsoft.AspNet.Mvc.Razor return Builder.Build(); } - public SpanConstructor With(ISpanCodeGenerator generator) + public SpanConstructor With(ISpanChunkGenerator generator) { - Builder.CodeGenerator = generator; + Builder.ChunkGenerator = generator; return this; } @@ -48,9 +48,9 @@ namespace Microsoft.AspNet.Mvc.Razor return this; } - public SpanConstructor With(Action generatorConfigurer) + public SpanConstructor With(Action generatorConfigurer) { - generatorConfigurer(Builder.CodeGenerator); + generatorConfigurer(Builder.ChunkGenerator); return this; } @@ -67,7 +67,7 @@ namespace Microsoft.AspNet.Mvc.Razor public SpanConstructor Hidden() { - Builder.CodeGenerator = SpanCodeGenerator.Null; + Builder.ChunkGenerator = SpanChunkGenerator.Null; return this; } diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/SpanFactory/SpanFactoryExtensions.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/SpanFactory/SpanFactoryExtensions.cs index d276c62487..c3257e1eaf 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/SpanFactory/SpanFactoryExtensions.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/SpanFactory/SpanFactoryExtensions.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Razor; -using Microsoft.AspNet.Razor.Generator; +using Microsoft.AspNet.Razor.Chunks.Generators; using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Text; @@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Mvc.Razor { var symbol = new HtmlSymbol(self.LocationTracker.CurrentLocation, string.Empty, HtmlSymbolType.Unknown); return self.Span(SpanKind.Markup, symbol) - .With(new MarkupCodeGenerator()); + .With(new MarkupChunkGenerator()); } public static UnclassifiedCodeSpanConstructor Code(this SpanFactory self, string content) @@ -107,12 +107,12 @@ namespace Microsoft.AspNet.Mvc.Razor public static SpanConstructor Markup(this SpanFactory self, string content) { - return self.Span(SpanKind.Markup, content, markup: true).With(new MarkupCodeGenerator()); + return self.Span(SpanKind.Markup, content, markup: true).With(new MarkupChunkGenerator()); } public static SpanConstructor Markup(this SpanFactory self, params string[] content) { - return self.Span(SpanKind.Markup, content, markup: true).With(new MarkupCodeGenerator()); + return self.Span(SpanKind.Markup, content, markup: true).With(new MarkupChunkGenerator()); } public static SourceLocation GetLocationAndAdvance(this SourceLocationTracker self, string content) diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/SpanFactory/UnclassifiedCodeSpanConstructor.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/SpanFactory/UnclassifiedCodeSpanConstructor.cs index 21c393054f..5d07c02248 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/SpanFactory/UnclassifiedCodeSpanConstructor.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/SpanFactory/UnclassifiedCodeSpanConstructor.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Razor.Generator; +using Microsoft.AspNet.Razor.Chunks.Generators; namespace Microsoft.AspNet.Mvc.Razor { @@ -14,7 +14,7 @@ namespace Microsoft.AspNet.Mvc.Razor _self = self; } - public SpanConstructor As(ISpanCodeGenerator codeGenerator) + public SpanConstructor As(ISpanChunkGenerator codeGenerator) { return _self.With(codeGenerator); } diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/RazorCompilationServiceTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/RazorCompilationServiceTest.cs index b1cf4a0c57..c718617958 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/RazorCompilationServiceTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/RazorCompilationServiceTest.cs @@ -5,7 +5,8 @@ using System.IO; using System.Linq; using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Razor; -using Microsoft.AspNet.Razor.Generator.Compiler; +using Microsoft.AspNet.Razor.Chunks; +using Microsoft.AspNet.Razor.CodeGenerators; using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.Framework.OptionsModel; @@ -56,8 +57,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation new Block(new BlockBuilder { Type = BlockType.Comment }), Enumerable.Empty(), errorSink, - new CodeBuilderResult("", new LineMapping[0]), - new CodeTree()); + new CodeGeneratorResult("", new LineMapping[0]), + new ChunkTree()); var host = new Mock(); host.Setup(h => h.GenerateCode(It.IsAny(), It.IsAny())) .Returns(generatorResult) @@ -94,8 +95,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation new Block(new BlockBuilder { Type = BlockType.Comment }), Enumerable.Empty(), new ErrorSink(), - new CodeBuilderResult(code, new LineMapping[0]), - new CodeTree()); + new CodeGeneratorResult(code, new LineMapping[0]), + new ChunkTree()); var host = new Mock(); host.Setup(h => h.GenerateCode(It.IsAny(), It.IsAny())) .Returns(generatorResult); @@ -206,8 +207,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation new Block(new BlockBuilder { Type = BlockType.Comment }), Enumerable.Empty(), new ErrorSink(), - new CodeBuilderResult("", new LineMapping[0]), - new CodeTree()); + new CodeGeneratorResult("", new LineMapping[0]), + new ChunkTree()); } private static IOptions GetOptions(IFileProvider fileProvider = null) diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/MvcRazorCodeParserTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/MvcRazorCodeParserTest.cs index 1bd9b14f57..d7ee5fa208 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Test/MvcRazorCodeParserTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Test/MvcRazorCodeParserTest.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Razor; +using Microsoft.AspNet.Razor.Chunks.Generators; using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser.SyntaxTree; @@ -42,7 +43,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code(" Foo") - .As(new ModelCodeGenerator(DefaultBaseType, "Foo")) + .As(new ModelChunkGenerator(DefaultBaseType, "Foo")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml() }; @@ -66,10 +67,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code("Foo?\r\n") - .As(new ModelCodeGenerator(DefaultBaseType, "Foo?")) + .As(new ModelChunkGenerator(DefaultBaseType, "Foo?")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.Markup("Bar") - .With(new MarkupCodeGenerator()) + .With(new MarkupChunkGenerator()) }; Assert.Equal(expectedSpans, spans.ToArray()); } @@ -91,10 +92,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code("Foo[[]][]\r\n") - .As(new ModelCodeGenerator(DefaultBaseType, "Foo[[]][]")) + .As(new ModelChunkGenerator(DefaultBaseType, "Foo[[]][]")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.Markup("Bar") - .With(new MarkupCodeGenerator()) + .With(new MarkupChunkGenerator()) }; Assert.Equal(expectedSpans, spans.ToArray()); } @@ -116,7 +117,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code("$rootnamespace$.MyModel") - .As(new ModelCodeGenerator(DefaultBaseType, "$rootnamespace$.MyModel")) + .As(new ModelChunkGenerator(DefaultBaseType, "$rootnamespace$.MyModel")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml() }; @@ -141,7 +142,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code(" ") - .As(new ModelCodeGenerator(DefaultBaseType, string.Empty)) + .As(new ModelChunkGenerator(DefaultBaseType, string.Empty)) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml() }; @@ -173,7 +174,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code("Foo\r\n") - .As(new ModelCodeGenerator(DefaultBaseType, "Foo")) + .As(new ModelChunkGenerator(DefaultBaseType, "Foo")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml(), factory.CodeTransition(SyntaxConstants.TransitionString) @@ -181,7 +182,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code("Bar") - .As(new ModelCodeGenerator(DefaultBaseType, "Bar")) + .As(new ModelChunkGenerator(DefaultBaseType, "Bar")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml() }; @@ -215,7 +216,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code("Foo\r\n") - .As(new ModelCodeGenerator(DefaultBaseType, "Foo")) + .As(new ModelChunkGenerator(DefaultBaseType, "Foo")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml(), factory.CodeTransition(SyntaxConstants.TransitionString) @@ -223,7 +224,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test factory.MetaCode("inherits ") .Accepts(AcceptedCharacters.None), factory.Code("Bar") - .As(new SetBaseTypeCodeGenerator("Bar")) + .As(new SetBaseTypeChunkGenerator("Bar")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml() }; @@ -257,7 +258,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test factory.MetaCode("inherits ") .Accepts(AcceptedCharacters.None), factory.Code("Bar" + Environment.NewLine) - .As(new SetBaseTypeCodeGenerator("Bar")) + .As(new SetBaseTypeChunkGenerator("Bar")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml(), factory.CodeTransition(SyntaxConstants.TransitionString) @@ -265,7 +266,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code("Foo") - .As(new ModelCodeGenerator(DefaultBaseType, "Foo")) + .As(new ModelChunkGenerator(DefaultBaseType, "Foo")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml() }; diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/SpanFactory.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/SpanFactory.cs index 4973f71604..604fff876e 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Test/SpanFactory.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Test/SpanFactory.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using Microsoft.AspNet.Razor; +using Microsoft.AspNet.Razor.Chunks.Generators; using Microsoft.AspNet.Razor.Editor; using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Parser.SyntaxTree; @@ -20,7 +21,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test public static SpanConstructor EmptyHtml(this SpanFactory self) { return self.Span(SpanKind.Markup, new HtmlSymbol(self.LocationTracker.CurrentLocation, String.Empty, HtmlSymbolType.Unknown)) - .With(new MarkupCodeGenerator()); + .With(new MarkupChunkGenerator()); } public static UnclassifiedCodeSpanConstructor Code(this SpanFactory self, string content) @@ -40,7 +41,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test } public static SpanConstructor Markup(this SpanFactory self, string content) { - return self.Span(SpanKind.Markup, content, markup: true).With(new MarkupCodeGenerator()); + return self.Span(SpanKind.Markup, content, markup: true).With(new MarkupChunkGenerator()); } } @@ -129,7 +130,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test _self = self; } - public SpanConstructor As(ISpanCodeGenerator codeGenerator) + public SpanConstructor As(ISpanChunkGenerator codeGenerator) { return _self.With(codeGenerator); } @@ -160,9 +161,9 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test return Builder.Build(); } - public SpanConstructor With(ISpanCodeGenerator generator) + public SpanConstructor With(ISpanChunkGenerator generator) { - Builder.CodeGenerator = generator; + Builder.ChunkGenerator = generator; return this; }