- ICodeTreeCache => IChunkTreeCache
- ModelCodeGenerator => ModelChunkGenerator
- MvcCSharpCodeBuilder => MvcCSharpCodeGenerator
- Updated files that used Razor resources that are now in different namespaces.
- Updated variable names to account for Razor renames.

aspnet/Razor#140
This commit is contained in:
N. Taylor Mullen 2015-05-28 12:47:32 -07:00
parent 70b56f157c
commit 94553703a2
44 changed files with 493 additions and 467 deletions

View File

@ -4,7 +4,7 @@
using System; using System;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Mvc.Razor.Host; using Microsoft.AspNet.Mvc.Razor.Host;
using Microsoft.AspNet.Razor.Generator.Compiler; using Microsoft.AspNet.Razor.Chunks;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Razor.Directives namespace Microsoft.AspNet.Mvc.Razor.Directives
@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
/// </summary> /// </summary>
/// <typeparam name="TChunk">The type to cast to.</typeparam> /// <typeparam name="TChunk">The type to cast to.</typeparam>
/// <param name="chunk">The chunk to cast.</param> /// <param name="chunk">The chunk to cast.</param>
/// <returns>The <paramref name="Chunk"/> cast to <typeparamref name="TChunk"/>.</returns> /// <returns>The <paramref name="chunk"/> cast to <typeparamref name="TChunk"/>.</returns>
/// <exception cref="ArgumentException"><paramref name="chunk"/> is not an instance of /// <exception cref="ArgumentException"><paramref name="chunk"/> is not an instance of
/// <typeparamref name="TChunk"/>.</exception> /// <typeparamref name="TChunk"/>.</exception>
public static TChunk EnsureChunk<TChunk>([NotNull] Chunk chunk) public static TChunk EnsureChunk<TChunk>([NotNull] Chunk chunk)
@ -40,31 +40,32 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
/// <summary> /// <summary>
/// Returns the <see cref="ModelChunk"/> used to determine the model name for the page generated /// Returns the <see cref="ModelChunk"/> used to determine the model name for the page generated
/// using the specified <paramref name="codeTree"/> /// using the specified <paramref name="chunkTree"/>
/// </summary> /// </summary>
/// <param name="codeTree">The <see cref="CodeTree"/> to scan for <see cref="ModelChunk"/>s in.</param> /// <param name="chunkTree">The <see cref="ChunkTree"/> to scan for <see cref="ModelChunk"/>s in.</param>
/// <returns>The last <see cref="ModelChunk"/> in the <see cref="CodeTree"/> if found, null otherwise. /// <returns>The last <see cref="ModelChunk"/> in the <see cref="ChunkTree"/> if found, <c>null</c> otherwise.
/// </returns> /// </returns>
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 // 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. // the current model chunk that the user is typing.
return codeTree.Chunks return chunkTree.Chunks
.OfType<ModelChunk>() .OfType<ModelChunk>()
.LastOrDefault(); .LastOrDefault();
} }
/// <summary> /// <summary>
/// Returns the type name of the Model specified via a <see cref="ModelChunk"/> in the /// Returns the type name of the Model specified via a <see cref="ModelChunk"/> in the
/// <paramref name="codeTree"/> if specified or the default model type. /// <paramref name="chunkTree"/> if specified or the default model type.
/// </summary> /// </summary>
/// <param name="codeTree">The <see cref="CodeTree"/> to scan for <see cref="ModelChunk"/>s in.</param> /// <param name="chunkTree">The <see cref="ChunkTree"/> to scan for <see cref="ModelChunk"/>s in.</param>
/// <param name="defaultModelName">The <see cref="Type"/> name of the default model.</param> /// <param name="defaultModelName">The <see cref="Type"/> name of the default model.</param>
/// <returns>The model type name for the generated page.</returns> /// <returns>The model type name for the generated page.</returns>
public static string GetModelTypeName([NotNull] CodeTree codeTree, public static string GetModelTypeName(
[NotNull] string defaultModelName) [NotNull] ChunkTree chunkTree,
[NotNull] string defaultModelName)
{ {
var modelChunk = GetModelChunk(codeTree); var modelChunk = GetModelChunk(chunkTree);
return modelChunk != null ? modelChunk.ModelType : defaultModelName; return modelChunk != null ? modelChunk.ModelType : defaultModelName;
} }

View File

@ -7,7 +7,7 @@ using System.IO;
using System.Linq; using System.Linq;
using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Razor; 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;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
@ -20,36 +20,37 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
{ {
private readonly MvcRazorHost _razorHost; private readonly MvcRazorHost _razorHost;
private readonly IReadOnlyList<Chunk> _defaultInheritedChunks; private readonly IReadOnlyList<Chunk> _defaultInheritedChunks;
private readonly ICodeTreeCache _codeTreeCache; private readonly IChunkTreeCache _chunkTreeCache;
/// <summary> /// <summary>
/// Initializes a new instance of <see cref="ChunkInheritanceUtility"/>. /// Initializes a new instance of <see cref="ChunkInheritanceUtility"/>.
/// </summary> /// </summary>
/// <param name="razorHost">The <see cref="MvcRazorHost"/> used to parse <c>_ViewImports</c> pages.</param> /// <param name="razorHost">The <see cref="MvcRazorHost"/> used to parse <c>_ViewImports</c> pages.</param>
/// <param name="codeTreeCache"><see cref="ICodeTreeCache"/> that caches <see cref="CodeTree"/> instances. /// <param name="chunkTreeCache"><see cref="IChunkTreeCache"/> that caches <see cref="ChunkTree"/> instances.
/// </param> /// </param>
/// <param name="defaultInheritedChunks">Sequence of <see cref="Chunk"/>s inherited by default.</param> /// <param name="defaultInheritedChunks">Sequence of <see cref="Chunk"/>s inherited by default.</param>
public ChunkInheritanceUtility([NotNull] MvcRazorHost razorHost, public ChunkInheritanceUtility(
[NotNull] ICodeTreeCache codeTreeCache, [NotNull] MvcRazorHost razorHost,
[NotNull] IReadOnlyList<Chunk> defaultInheritedChunks) [NotNull] IChunkTreeCache chunkTreeCache,
[NotNull] IReadOnlyList<Chunk> defaultInheritedChunks)
{ {
_razorHost = razorHost; _razorHost = razorHost;
_defaultInheritedChunks = defaultInheritedChunks; _defaultInheritedChunks = defaultInheritedChunks;
_codeTreeCache = codeTreeCache; _chunkTreeCache = chunkTreeCache;
} }
/// <summary> /// <summary>
/// Gets an ordered <see cref="IReadOnlyList{T}"/> of parsed <see cref="CodeTree"/> for each /// Gets an ordered <see cref="IReadOnlyList{T}"/> of parsed <see cref="ChunkTree"/> for each
/// <c>_ViewImports</c> that is applicable to the page located at <paramref name="pagePath"/>. The list is /// <c>_ViewImports</c> that is applicable to the page located at <paramref name="pagePath"/>. The list is
/// ordered so that the <see cref="CodeTree"/> for the <c>_ViewImports</c> closest to the /// ordered so that the <see cref="ChunkTree"/> for the <c>_ViewImports</c> closest to the
/// <paramref name="pagePath"/> in the file system appears first. /// <paramref name="pagePath"/> in the file system appears first.
/// </summary> /// </summary>
/// <param name="pagePath">The path of the page to locate inherited chunks for.</param> /// <param name="pagePath">The path of the page to locate inherited chunks for.</param>
/// <returns>A <see cref="IReadOnlyList{CodeTree}"/> of parsed <c>_ViewImports</c> /// <returns>A <see cref="IReadOnlyList{ChunkTree}"/> of parsed <c>_ViewImports</c>
/// <see cref="CodeTree"/>s.</returns> /// <see cref="ChunkTree"/>s.</returns>
public virtual IReadOnlyList<CodeTree> GetInheritedCodeTrees([NotNull] string pagePath) public virtual IReadOnlyList<ChunkTree> GetInheritedChunkTrees([NotNull] string pagePath)
{ {
var inheritedCodeTrees = new List<CodeTree>(); var inheritedChunkTrees = new List<ChunkTree>();
var templateEngine = new RazorTemplateEngine(_razorHost); var templateEngine = new RazorTemplateEngine(_razorHost);
foreach (var viewImportsPath in ViewHierarchyUtility.GetViewImportsLocations(pagePath)) 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 // 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 // we need to ensure the paths are app-relative to allow the GetGlobalFileLocations
// for the current _ViewImports to succeed. // for the current _ViewImports to succeed.
var codeTree = _codeTreeCache.GetOrAdd(viewImportsPath, var chunkTree = _chunkTreeCache.GetOrAdd(
fileInfo => ParseViewFile(templateEngine, viewImportsPath,
fileInfo, fileInfo => ParseViewFile(
viewImportsPath)); templateEngine,
fileInfo,
viewImportsPath));
if (codeTree != null) if (chunkTree != null)
{ {
inheritedCodeTrees.Add(codeTree); inheritedChunkTrees.Add(chunkTree);
} }
} }
return inheritedCodeTrees; return inheritedChunkTrees;
} }
/// <summary> /// <summary>
/// Merges <see cref="Chunk"/> inherited by default and <see cref="CodeTree"/> instances produced by parsing /// Merges <see cref="Chunk"/> inherited by default and <see cref="ChunkTree"/> instances produced by parsing
/// <c>_ViewImports</c> files into the specified <paramref name="codeTree"/>. /// <c>_ViewImports</c> files into the specified <paramref name="chunkTree"/>.
/// </summary> /// </summary>
/// <param name="codeTree">The <see cref="CodeTree"/> to merge in to.</param> /// <param name="chunkTree">The <see cref="ChunkTree"/> to merge in to.</param>
/// <param name="inheritedCodeTrees"><see cref="IReadOnlyList{CodeTree}"/> inherited from <c>_ViewImports</c> /// <param name="inheritedChunkTrees"><see cref="IReadOnlyList{ChunkTree}"/> inherited from <c>_ViewImports</c>
/// files.</param> /// files.</param>
/// <param name="defaultModel">The list of chunks to merge.</param> /// <param name="defaultModel">The list of chunks to merge.</param>
public void MergeInheritedCodeTrees([NotNull] CodeTree codeTree, public void MergeInheritedChunkTrees(
[NotNull] IReadOnlyList<CodeTree> inheritedCodeTrees, [NotNull] ChunkTree chunkTree,
string defaultModel) [NotNull] IReadOnlyList<ChunkTree> inheritedChunkTrees,
string defaultModel)
{ {
var mergerMappings = GetMergerMappings(codeTree, defaultModel); var mergerMappings = GetMergerMappings(chunkTree, defaultModel);
IChunkMerger merger; 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. // 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)) 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. // 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. // rules.
// Read the chunks outside in - that is chunks from the _ViewImports closest to the page get merged in first // 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 // and the furthest one last. This allows the merger to ignore a directive like @model that was previously
// seen. // seen.
var chunksToMerge = inheritedCodeTrees.SelectMany(tree => tree.Chunks) var chunksToMerge = inheritedChunkTrees.SelectMany(tree => tree.Chunks)
.Concat(_defaultInheritedChunks); .Concat(_defaultInheritedChunks);
foreach (var chunk in chunksToMerge) foreach (var chunk in chunksToMerge)
{ {
if (mergerMappings.TryGetValue(chunk.GetType(), out merger)) if (mergerMappings.TryGetValue(chunk.GetType(), out merger))
{ {
merger.Merge(codeTree, chunk); merger.Merge(chunkTree, chunk);
} }
} }
} }
private static Dictionary<Type, IChunkMerger> GetMergerMappings(CodeTree codeTree, string defaultModel) private static Dictionary<Type, IChunkMerger> GetMergerMappings(ChunkTree chunkTree, string defaultModel)
{ {
var modelType = ChunkHelper.GetModelTypeName(codeTree, defaultModel); var modelType = ChunkHelper.GetModelTypeName(chunkTree, defaultModel);
return new Dictionary<Type, IChunkMerger> return new Dictionary<Type, IChunkMerger>
{ {
{ typeof(UsingChunk), new UsingChunkMerger() }, { typeof(UsingChunk), new UsingChunkMerger() },
@ -124,9 +128,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
}; };
} }
private static CodeTree ParseViewFile(RazorTemplateEngine engine, private static ChunkTree ParseViewFile(
IFileInfo fileInfo, RazorTemplateEngine engine,
string viewImportsPath) IFileInfo fileInfo,
string viewImportsPath)
{ {
using (var stream = fileInfo.CreateReadStream()) using (var stream = fileInfo.CreateReadStream())
{ {
@ -135,15 +140,16 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
var parseResults = engine.ParseTemplate(streamReader, viewImportsPath); var parseResults = engine.ParseTemplate(streamReader, viewImportsPath);
var className = ParserHelpers.SanitizeClassName(fileInfo.Name); var className = ParserHelpers.SanitizeClassName(fileInfo.Name);
var language = engine.Host.CodeLanguage; var language = engine.Host.CodeLanguage;
var codeGenerator = language.CreateCodeGenerator(className, var chunkGenerator = language.CreateChunkGenerator(
engine.Host.DefaultNamespace, className,
viewImportsPath, engine.Host.DefaultNamespace,
engine.Host); viewImportsPath,
codeGenerator.Visit(parseResults); engine.Host);
chunkGenerator.Visit(parseResults);
// Rewrite the location of inherited chunks so they point to the global import file. // Rewrite the location of inherited chunks so they point to the global import file.
var codeTree = codeGenerator.Context.CodeTreeBuilder.CodeTree; var chunkTree = chunkGenerator.Context.ChunkTreeBuilder.ChunkTree;
foreach (var chunk in codeTree.Chunks) foreach (var chunk in chunkTree.Chunks)
{ {
chunk.Start = new SourceLocation( chunk.Start = new SourceLocation(
viewImportsPath, viewImportsPath,
@ -152,7 +158,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
chunk.Start.CharacterIndex); chunk.Start.CharacterIndex);
} }
return codeTree; return chunkTree;
} }
} }
} }

View File

@ -3,16 +3,16 @@
using System; using System;
using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Razor.Generator.Compiler; using Microsoft.AspNet.Razor.Chunks;
using Microsoft.Framework.Caching.Memory; using Microsoft.Framework.Caching.Memory;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Razor.Directives namespace Microsoft.AspNet.Mvc.Razor.Directives
{ {
/// <summary> /// <summary>
/// Default implementation of <see cref="ICodeTreeCache"/>. /// Default implementation of <see cref="IChunkTreeCache"/>.
/// </summary> /// </summary>
public class DefaultCodeTreeCache : ICodeTreeCache public class DefaultChunkTreeCache : IChunkTreeCache
{ {
private static readonly MemoryCacheOptions MemoryCacheOptions = new MemoryCacheOptions 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 static readonly TimeSpan SlidingExpirationDuration = TimeSpan.FromMinutes(1);
private readonly IFileProvider _fileProvider; private readonly IFileProvider _fileProvider;
private readonly IMemoryCache _codeTreeCache; private readonly IMemoryCache _chunkTreeCache;
/// <summary> /// <summary>
/// Initializes a new instance of <see cref="DefaultCodeTreeCache"/>. /// Initializes a new instance of <see cref="DefaultChunkTreeCache"/>.
/// </summary> /// </summary>
/// <param name="fileProvider">The application's <see cref="IFileProvider"/>.</param> /// <param name="fileProvider">The application's <see cref="IFileProvider"/>.</param>
public DefaultCodeTreeCache(IFileProvider fileProvider) public DefaultChunkTreeCache(IFileProvider fileProvider)
: this(fileProvider, MemoryCacheOptions) : this(fileProvider, MemoryCacheOptions)
{ {
} }
// Internal for unit testing // Internal for unit testing
internal DefaultCodeTreeCache(IFileProvider fileProvider, internal DefaultChunkTreeCache(IFileProvider fileProvider,
MemoryCacheOptions options) MemoryCacheOptions options)
{ {
_fileProvider = fileProvider; _fileProvider = fileProvider;
_codeTreeCache = new MemoryCache(options); _chunkTreeCache = new MemoryCache(options);
} }
/// <inheritdoc /> /// <inheritdoc />
public CodeTree GetOrAdd([NotNull] string pagePath, public ChunkTree GetOrAdd(
[NotNull] Func<IFileInfo, CodeTree> getCodeTree) [NotNull] string pagePath,
[NotNull] Func<IFileInfo, ChunkTree> getChunkTree)
{ {
CodeTree codeTree; ChunkTree chunkTree;
if (!_codeTreeCache.TryGetValue(pagePath, out codeTree)) if (!_chunkTreeCache.TryGetValue(pagePath, out chunkTree))
{ {
// GetOrAdd is invoked for each _GlobalImport that might potentially exist in the path. // 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 // 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); .SetSlidingExpiration(SlidingExpirationDuration);
var file = _fileProvider.GetFileInfo(pagePath); 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;
} }
} }
} }

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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 namespace Microsoft.AspNet.Mvc.Razor.Directives
{ {
@ -11,16 +11,16 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
public interface IChunkMerger public interface IChunkMerger
{ {
/// <summary> /// <summary>
/// Visits a <see cref="Chunk"/> from the <see cref="CodeTree"/> to merge into. /// Visits a <see cref="Chunk"/> from the <see cref="ChunkTree"/> to merge into.
/// </summary> /// </summary>
/// <param name="chunk">A <see cref="Chunk"/> from the tree.</param> /// <param name="chunk">A <see cref="Chunk"/> from the tree.</param>
void VisitChunk(Chunk chunk); void VisitChunk(Chunk chunk);
/// <summary> /// <summary>
/// Merges an inherited <see cref="Chunk"/> into the <see cref="CodeTree"/>. /// Merges an inherited <see cref="Chunk"/> into the <see cref="ChunkTree"/>.
/// </summary> /// </summary>
/// <param name="codeTree">The <see cref="CodeTree"/> to merge into.</param> /// <param name="ChunkTree">The <see cref="ChunkTree"/> to merge into.</param>
/// <param name="chunk">The <see cref="Chunk"/> to merge.</param> /// <param name="chunk">The <see cref="Chunk"/> to merge.</param>
void Merge(CodeTree codeTree, Chunk chunk); void Merge(ChunkTree chunkTree, Chunk chunk);
} }
} }

View File

@ -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
{
/// <summary>
/// A cache for parsed <see cref="ChunkTree"/>s.
/// </summary>
public interface IChunkTreeCache
{
/// <summary>
/// Get an existing <see cref="ChunkTree"/>, or create and add a new one if it is
/// not available in the cache or is expired.
/// </summary>
/// <param name="pagePath">The application relative path of the Razor page.</param>
/// <param name="getChunkTree">A delegate that creates a new <see cref="ChunkTree"/>.</param>
/// <returns>The <see cref="ChunkTree"/> if a file exists at <paramref name="pagePath"/>,
/// <c>null</c> otherwise.</returns>
/// <remarks>The resulting <see cref="ChunkTree"/> does not contain inherited chunks from _ViewStart or
/// default inherited chunks.</remarks>
ChunkTree GetOrAdd(string pagePath, Func<IFileInfo, ChunkTree> getChunkTree);
}
}

View File

@ -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
{
/// <summary>
/// A cache for parsed <see cref="CodeTree"/>s.
/// </summary>
public interface ICodeTreeCache
{
/// <summary>
/// Get an existing <see cref="CodeTree"/>, or create and add a new one if it is
/// not available in the cache or is expired.
/// </summary>
/// <param name="pagePath">The application relative path of the Razor page.</param>
/// <param name="getCodeTree">A delegate that creates a new <see cref="CodeTree"/>.</param>
/// <returns>The <see cref="CodeTree"/> if a file exists at <paramref name="pagePath"/>,
/// <c>null</c> otherwise.</returns>
/// <remarks>The resulting <see cref="CodeTree"/> does not contain inherited chunks from _ViewStart or
/// default inherited chunks.</remarks>
CodeTree GetOrAdd(string pagePath, Func<IFileInfo, CodeTree> getCodeTree);
}
}

View File

@ -3,7 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Razor.Generator.Compiler; using Microsoft.AspNet.Razor.Chunks;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Razor.Directives namespace Microsoft.AspNet.Mvc.Razor.Directives
@ -34,13 +34,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
} }
/// <inheritdoc /> /// <inheritdoc />
public void Merge([NotNull] CodeTree codeTree, [NotNull] Chunk chunk) public void Merge([NotNull] ChunkTree chunkTree, [NotNull] Chunk chunk)
{ {
var injectChunk = ChunkHelper.EnsureChunk<InjectChunk>(chunk); var injectChunk = ChunkHelper.EnsureChunk<InjectChunk>(chunk);
if (!_addedMemberNames.Contains(injectChunk.MemberName)) if (!_addedMemberNames.Contains(injectChunk.MemberName))
{ {
_addedMemberNames.Add(injectChunk.MemberName); _addedMemberNames.Add(injectChunk.MemberName);
codeTree.Chunks.Add(TransformChunk(injectChunk)); chunkTree.Chunks.Add(TransformChunk(injectChunk));
} }
} }

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Razor.Directives namespace Microsoft.AspNet.Mvc.Razor.Directives
@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
} }
/// <inheritdoc /> /// <inheritdoc />
public void Merge([NotNull] CodeTree codeTree, [NotNull] Chunk chunk) public void Merge([NotNull] ChunkTree chunkTree, [NotNull] Chunk chunk)
{ {
if (!_isBaseTypeSet) 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. // The base type can set exactly once and the first one we encounter wins.
_isBaseTypeSet = true; _isBaseTypeSet = true;
codeTree.Chunks.Add(TransformChunk(baseTypeChunk)); chunkTree.Chunks.Add(TransformChunk(baseTypeChunk));
} }
} }

View File

@ -3,7 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Razor.Generator.Compiler; using Microsoft.AspNet.Razor.Chunks;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Razor.Directives namespace Microsoft.AspNet.Mvc.Razor.Directives
@ -23,14 +23,14 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
} }
/// <inheritdoc /> /// <inheritdoc />
public void Merge([NotNull] CodeTree codeTree, [NotNull] Chunk chunk) public void Merge([NotNull] ChunkTree chunkTree, [NotNull] Chunk chunk)
{ {
var namespaceChunk = ChunkHelper.EnsureChunk<UsingChunk>(chunk); var namespaceChunk = ChunkHelper.EnsureChunk<UsingChunk>(chunk);
if (!_currentUsings.Contains(namespaceChunk.Namespace)) if (!_currentUsings.Contains(namespaceChunk.Namespace))
{ {
_currentUsings.Add(namespaceChunk.Namespace); _currentUsings.Add(namespaceChunk.Namespace);
codeTree.Chunks.Add(namespaceChunk); chunkTree.Chunks.Add(namespaceChunk);
} }
} }
} }

View File

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO; using System.IO;
using Microsoft.AspNet.Razor; using Microsoft.AspNet.Razor.CodeGenerators;
namespace Microsoft.AspNet.Mvc.Razor namespace Microsoft.AspNet.Mvc.Razor
{ {

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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 namespace Microsoft.AspNet.Mvc.Razor
{ {
@ -12,8 +12,9 @@ namespace Microsoft.AspNet.Mvc.Razor
/// </summary> /// </summary>
/// <param name="typeName">The type name of the property to be injected</param> /// <param name="typeName">The type name of the property to be injected</param>
/// <param name="propertyName">The member name of the property to be injected.</param> /// <param name="propertyName">The member name of the property to be injected.</param>
public InjectChunk(string typeName, public InjectChunk(
string propertyName) string typeName,
string propertyName)
{ {
TypeName = typeName; TypeName = typeName;
MemberName = propertyName; MemberName = propertyName;

View File

@ -2,8 +2,8 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.CodeGenerators;
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp; using Microsoft.AspNet.Razor.CodeGenerators.Visitors;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Razor namespace Microsoft.AspNet.Mvc.Razor
@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Mvc.Razor
private readonly string _injectAttribute; private readonly string _injectAttribute;
public InjectChunkVisitor([NotNull] CSharpCodeWriter writer, public InjectChunkVisitor([NotNull] CSharpCodeWriter writer,
[NotNull] CodeBuilderContext context, [NotNull] CodeGeneratorContext context,
[NotNull] string injectAttributeName) [NotNull] string injectAttributeName)
: base(writer, context) : base(writer, context)
{ {

View File

@ -3,12 +3,12 @@
using System; using System;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Mvc.Razor namespace Microsoft.AspNet.Mvc.Razor
{ {
public class InjectParameterGenerator : SpanCodeGenerator public class InjectParameterGenerator : SpanChunkGenerator
{ {
public InjectParameterGenerator(string typeName, string propertyName) public InjectParameterGenerator(string typeName, string propertyName)
{ {
@ -20,10 +20,10 @@ namespace Microsoft.AspNet.Mvc.Razor
public string PropertyName { get; private set; } 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); var injectChunk = new InjectChunk(TypeName, PropertyName);
context.CodeTreeBuilder.AddChunk(injectChunk, target); context.ChunkTreeBuilder.AddChunk(injectChunk, target);
} }
public override string ToString() public override string ToString()

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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 namespace Microsoft.AspNet.Mvc.Razor
{ {

View File

@ -3,13 +3,14 @@
using System; using System;
using Microsoft.AspNet.Mvc.Razor; using Microsoft.AspNet.Mvc.Razor;
using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Generator 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; BaseType = baseType;
ModelType = modelType; ModelType = modelType;
@ -18,10 +19,10 @@ namespace Microsoft.AspNet.Razor.Generator
public string BaseType { get; private set; } public string BaseType { get; private set; }
public string ModelType { 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); var modelChunk = new ModelChunk(BaseType, ModelType);
context.CodeTreeBuilder.AddChunk(modelChunk, target, topLevel: true); context.ChunkTreeBuilder.AddChunk(modelChunk, target, topLevel: true);
} }
public override string ToString() public override string ToString()
@ -31,7 +32,7 @@ namespace Microsoft.AspNet.Razor.Generator
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
var other = obj as ModelCodeGenerator; var other = obj as ModelChunkGenerator;
return other != null && return other != null &&
string.Equals(ModelType, other.ModelType, StringComparison.Ordinal); string.Equals(ModelType, other.ModelType, StringComparison.Ordinal);
} }

View File

@ -1,16 +1,17 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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.CodeGenerators;
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp; using Microsoft.AspNet.Razor.CodeGenerators.Visitors;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Razor namespace Microsoft.AspNet.Mvc.Razor
{ {
public class ModelChunkVisitor : MvcCSharpCodeVisitor public class ModelChunkVisitor : MvcCSharpCodeVisitor
{ {
public ModelChunkVisitor([NotNull] CSharpCodeWriter writer, public ModelChunkVisitor(
[NotNull] CodeBuilderContext context) [NotNull] CSharpCodeWriter writer,
[NotNull] CodeGeneratorContext context)
: base(writer, context) : base(writer, context)
{ {
} }

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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;
using Microsoft.AspNet.Razor.Generator.Compiler; using Microsoft.AspNet.Razor.CodeGenerators;
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp; using Microsoft.AspNet.Razor.CodeGenerators.Visitors;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Razor namespace Microsoft.AspNet.Mvc.Razor
@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Mvc.Razor
public abstract class MvcCSharpChunkVisitor : CodeVisitor<CSharpCodeWriter> public abstract class MvcCSharpChunkVisitor : CodeVisitor<CSharpCodeWriter>
{ {
public MvcCSharpChunkVisitor([NotNull] CSharpCodeWriter writer, public MvcCSharpChunkVisitor([NotNull] CSharpCodeWriter writer,
[NotNull] CodeBuilderContext context) [NotNull] CodeGeneratorContext context)
: base(writer, context) : base(writer, context)
{ {
} }

View File

@ -3,23 +3,23 @@
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Mvc.Razor.Directives; using Microsoft.AspNet.Mvc.Razor.Directives;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.CodeGenerators;
using Microsoft.AspNet.Razor.Generator.Compiler; using Microsoft.AspNet.Razor.CodeGenerators.Visitors;
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Razor namespace Microsoft.AspNet.Mvc.Razor
{ {
public class MvcCSharpCodeBuilder : CSharpCodeBuilder public class MvcCSharpCodeGenerator : CSharpCodeGenerator
{ {
private readonly GeneratedTagHelperAttributeContext _tagHelperAttributeContext; private readonly GeneratedTagHelperAttributeContext _tagHelperAttributeContext;
private readonly string _defaultModel; private readonly string _defaultModel;
private readonly string _injectAttribute; private readonly string _injectAttribute;
public MvcCSharpCodeBuilder([NotNull] CodeBuilderContext context, public MvcCSharpCodeGenerator(
[NotNull] string defaultModel, [NotNull] CodeGeneratorContext context,
[NotNull] string injectAttribute, [NotNull] string defaultModel,
[NotNull] GeneratedTagHelperAttributeContext tagHelperAttributeContext) [NotNull] string injectAttribute,
[NotNull] GeneratedTagHelperAttributeContext tagHelperAttributeContext)
: base(context) : base(context)
{ {
_tagHelperAttributeContext = tagHelperAttributeContext; _tagHelperAttributeContext = tagHelperAttributeContext;
@ -29,8 +29,9 @@ namespace Microsoft.AspNet.Mvc.Razor
private string Model { get; set; } private string Model { get; set; }
protected override CSharpCodeVisitor CreateCSharpCodeVisitor([NotNull] CSharpCodeWriter writer, protected override CSharpCodeVisitor CreateCSharpCodeVisitor(
[NotNull] CodeBuilderContext context) [NotNull] CSharpCodeWriter writer,
[NotNull] CodeGeneratorContext context)
{ {
var csharpCodeVisitor = base.CreateCSharpCodeVisitor(writer, context); var csharpCodeVisitor = base.CreateCSharpCodeVisitor(writer, context);
@ -43,7 +44,7 @@ namespace Microsoft.AspNet.Mvc.Razor
protected override CSharpCodeWritingScope BuildClassDeclaration(CSharpCodeWriter writer) protected override CSharpCodeWritingScope BuildClassDeclaration(CSharpCodeWriter writer)
{ {
// Grab the last model chunk so it gets intellisense. // 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; Model = modelChunk != null ? modelChunk.ModelType : _defaultModel;
@ -73,7 +74,7 @@ namespace Microsoft.AspNet.Mvc.Razor
writer.WriteLineHiddenDirective(); writer.WriteLineHiddenDirective();
var injectVisitor = new InjectChunkVisitor(writer, Context, _injectAttribute); var injectVisitor = new InjectChunkVisitor(writer, Context, _injectAttribute);
injectVisitor.Accept(Context.CodeTreeBuilder.CodeTree.Chunks); injectVisitor.Accept(Context.ChunkTreeBuilder.ChunkTree.Chunks);
writer.WriteLine(); writer.WriteLine();
writer.WriteLineHiddenDirective(); writer.WriteLineHiddenDirective();

View File

@ -1,16 +1,16 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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.CodeGenerators;
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Razor namespace Microsoft.AspNet.Mvc.Razor
{ {
public abstract class MvcCSharpCodeVisitor : MvcCSharpChunkVisitor public abstract class MvcCSharpCodeVisitor : MvcCSharpChunkVisitor
{ {
public MvcCSharpCodeVisitor([NotNull] CSharpCodeWriter writer, public MvcCSharpCodeVisitor(
[NotNull] CodeBuilderContext context) [NotNull] CSharpCodeWriter writer,
[NotNull] CodeGeneratorContext context)
: base(writer, context) : base(writer, context)
{ {
} }

View File

@ -4,6 +4,7 @@
using System.Diagnostics; using System.Diagnostics;
using Microsoft.AspNet.Mvc.Razor.Host; using Microsoft.AspNet.Mvc.Razor.Host;
using Microsoft.AspNet.Razor; using Microsoft.AspNet.Razor;
using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Generator;
using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
@ -55,7 +56,7 @@ namespace Microsoft.AspNet.Mvc.Razor
BaseTypeDirective(Resources.FormatMvcRazorCodeParser_KeywordMustBeFollowedByTypeName(ModelKeyword), BaseTypeDirective(Resources.FormatMvcRazorCodeParser_KeywordMustBeFollowedByTypeName(ModelKeyword),
CreateModelCodeGenerator); CreateModelChunkGenerator);
if (_modelStatementFound) if (_modelStatementFound)
{ {
@ -136,16 +137,16 @@ namespace Microsoft.AspNet.Mvc.Razor
// ';' is optional // ';' is optional
propertyName = RemoveWhitespaceAndTrailingSemicolons(propertyName); propertyName = RemoveWhitespaceAndTrailingSemicolons(propertyName);
Span.CodeGenerator = new InjectParameterGenerator(typeName.Trim(), propertyName); Span.ChunkGenerator = new InjectParameterGenerator(typeName.Trim(), propertyName);
// Output the span and finish the block // Output the span and finish the block
CompleteBlock(); CompleteBlock();
Output(SpanKind.Code, AcceptedCharacters.AnyExceptNewline); 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 // Internal for unit testing

View File

@ -9,8 +9,8 @@ using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Mvc.Razor.Directives; using Microsoft.AspNet.Mvc.Razor.Directives;
using Microsoft.AspNet.Mvc.Razor.Internal; using Microsoft.AspNet.Mvc.Razor.Internal;
using Microsoft.AspNet.Razor; using Microsoft.AspNet.Razor;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks;
using Microsoft.AspNet.Razor.Generator.Compiler; using Microsoft.AspNet.Razor.CodeGenerators;
using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Runtime.TagHelpers; using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
@ -41,16 +41,16 @@ namespace Microsoft.AspNet.Mvc.Razor
// CodeGenerationContext.DefaultBaseClass is set to MyBaseType<dynamic>. // CodeGenerationContext.DefaultBaseClass is set to MyBaseType<dynamic>.
// This field holds the type name without the generic decoration (MyBaseType) // This field holds the type name without the generic decoration (MyBaseType)
private readonly string _baseType; private readonly string _baseType;
private readonly ICodeTreeCache _codeTreeCache; private readonly IChunkTreeCache _ChunkTreeCache;
private readonly RazorPathNormalizer _pathNormalizer; private readonly RazorPathNormalizer _pathNormalizer;
private ChunkInheritanceUtility _chunkInheritanceUtility; private ChunkInheritanceUtility _chunkInheritanceUtility;
internal MvcRazorHost(ICodeTreeCache codeTreeCache, RazorPathNormalizer pathNormalizer) internal MvcRazorHost(IChunkTreeCache ChunkTreeCache, RazorPathNormalizer pathNormalizer)
: base(new CSharpRazorCodeLanguage()) : base(new CSharpRazorCodeLanguage())
{ {
_pathNormalizer = pathNormalizer; _pathNormalizer = pathNormalizer;
_baseType = BaseType; _baseType = BaseType;
_codeTreeCache = codeTreeCache; _ChunkTreeCache = ChunkTreeCache;
TagHelperDescriptorResolver = new TagHelperDescriptorResolver(); TagHelperDescriptorResolver = new TagHelperDescriptorResolver();
DefaultBaseClass = BaseType + "<" + DefaultModel + ">"; DefaultBaseClass = BaseType + "<" + DefaultModel + ">";
@ -116,19 +116,19 @@ namespace Microsoft.AspNet.Mvc.Razor
/// <param name="root">The path to the application base.</param> /// <param name="root">The path to the application base.</param>
// Note: This constructor is used by tooling and is created once for each // 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 // 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. // is problematic to manage.
public MvcRazorHost(string root) public MvcRazorHost(string root)
: this(new DefaultCodeTreeCache(new PhysicalFileProvider(root)), new DesignTimeRazorPathNormalizer(root)) : this(new DefaultChunkTreeCache(new PhysicalFileProvider(root)), new DesignTimeRazorPathNormalizer(root))
{ {
} }
#endif #endif
/// <summary> /// <summary>
/// Initializes a new instance of <see cref="MvcRazorHost"/> using the specified <paramref name="codeTreeCache"/>. /// Initializes a new instance of <see cref="MvcRazorHost"/> using the specified <paramref name="ChunkTreeCache"/>.
/// </summary> /// </summary>
/// <param name="codeTreeCache">An <see cref="ICodeTreeCache"/> rooted at the application base path.</param> /// <param name="ChunkTreeCache">An <see cref="IChunkTreeCache"/> rooted at the application base path.</param>
public MvcRazorHost(ICodeTreeCache codeTreeCache) public MvcRazorHost(IChunkTreeCache ChunkTreeCache)
: this(codeTreeCache, new RazorPathNormalizer()) : this(ChunkTreeCache, new RazorPathNormalizer())
{ {
} }
@ -188,7 +188,7 @@ namespace Microsoft.AspNet.Mvc.Razor
if (_chunkInheritanceUtility == null) if (_chunkInheritanceUtility == null)
{ {
// This needs to be lazily evaluated to support DefaultInheritedChunks being virtual. // 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; return _chunkInheritanceUtility;
@ -213,8 +213,8 @@ namespace Microsoft.AspNet.Mvc.Razor
{ {
sourceFileName = _pathNormalizer.NormalizePath(sourceFileName); sourceFileName = _pathNormalizer.NormalizePath(sourceFileName);
var inheritedCodeTrees = ChunkInheritanceUtility.GetInheritedCodeTrees(sourceFileName); var inheritedChunkTrees = ChunkInheritanceUtility.GetInheritedChunkTrees(sourceFileName);
return new MvcRazorParser(razorParser, inheritedCodeTrees, DefaultInheritedChunks, ModelExpressionType); return new MvcRazorParser(razorParser, inheritedChunkTrees, DefaultInheritedChunks, ModelExpressionType);
} }
/// <inheritdoc /> /// <inheritdoc />
@ -224,26 +224,29 @@ namespace Microsoft.AspNet.Mvc.Razor
} }
/// <inheritdoc /> /// <inheritdoc />
public override CodeBuilder DecorateCodeBuilder([NotNull] CodeBuilder incomingBuilder, public override CodeGenerator DecorateCodeGenerator(
[NotNull] CodeBuilderContext context) [NotNull] CodeGenerator incomingGenerator,
[NotNull] CodeGeneratorContext context)
{ {
// Need the normalized path to resolve inherited chunks only. Full paths are needed for generated Razor // 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. // files checksum and line pragmas to enable DesignTime debugging.
var normalizedPath = _pathNormalizer.NormalizePath(context.SourceFile); var normalizedPath = _pathNormalizer.NormalizePath(context.SourceFile);
var inheritedChunks = ChunkInheritanceUtility.GetInheritedCodeTrees(normalizedPath); var inheritedChunks = ChunkInheritanceUtility.GetInheritedChunkTrees(normalizedPath);
ChunkInheritanceUtility.MergeInheritedCodeTrees(context.CodeTreeBuilder.CodeTree, ChunkInheritanceUtility.MergeInheritedChunkTrees(
inheritedChunks, context.ChunkTreeBuilder.ChunkTree,
DefaultModel); inheritedChunks,
DefaultModel);
return new MvcCSharpCodeBuilder(context, return new MvcCSharpCodeGenerator(
DefaultModel, context,
InjectAttribute, DefaultModel,
new GeneratedTagHelperAttributeContext InjectAttribute,
{ new GeneratedTagHelperAttributeContext
ModelExpressionTypeName = ModelExpressionType, {
CreateModelExpressionMethodName = CreateModelExpressionMethod ModelExpressionTypeName = ModelExpressionType,
}); CreateModelExpressionMethodName = CreateModelExpressionMethod
});
} }
} }
} }

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Mvc.Razor.Host; using Microsoft.AspNet.Mvc.Razor.Host;
using Microsoft.AspNet.Razor; 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;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Parser.TagHelpers; using Microsoft.AspNet.Razor.Parser.TagHelpers;
@ -28,20 +28,20 @@ namespace Microsoft.AspNet.Mvc.Razor
/// Initializes a new instance of <see cref="MvcRazorParser"/>. /// Initializes a new instance of <see cref="MvcRazorParser"/>.
/// </summary> /// </summary>
/// <param name="parser">The <see cref="RazorParser"/> to copy properties from.</param> /// <param name="parser">The <see cref="RazorParser"/> to copy properties from.</param>
/// <param name="inheritedCodeTrees">The <see cref="IReadOnlyList{CodeTree}"/>s that are inherited /// <param name="inheritedChunkTrees">The <see cref="IReadOnlyList{ChunkTree}"/>s that are inherited
/// from parsed pages from _ViewImports files.</param> /// from parsed pages from _ViewImports files.</param>
/// <param name="defaultInheritedChunks">The <see cref="IReadOnlyList{Chunk}"/> inherited by /// <param name="defaultInheritedChunks">The <see cref="IReadOnlyList{Chunk}"/> inherited by
/// default by all Razor pages in the application.</param> /// default by all Razor pages in the application.</param>
public MvcRazorParser( public MvcRazorParser(
[NotNull] RazorParser parser, [NotNull] RazorParser parser,
[NotNull] IReadOnlyList<CodeTree> inheritedCodeTrees, [NotNull] IReadOnlyList<ChunkTree> inheritedChunkTrees,
[NotNull] IReadOnlyList<Chunk> defaultInheritedChunks, [NotNull] IReadOnlyList<Chunk> defaultInheritedChunks,
[NotNull] string modelExpressionTypeName) [NotNull] string modelExpressionTypeName)
: base(parser) : base(parser)
{ {
// Construct tag helper descriptors from @addTagHelper, @removeTagHelper and @tagHelperPrefix chunks // Construct tag helper descriptors from @addTagHelper, @removeTagHelper and @tagHelperPrefix chunks
_viewImportsDirectiveDescriptors = GetTagHelperDirectiveDescriptors( _viewImportsDirectiveDescriptors = GetTagHelperDirectiveDescriptors(
inheritedCodeTrees, inheritedChunkTrees,
defaultInheritedChunks); defaultInheritedChunks);
_modelExpressionTypeName = modelExpressionTypeName; _modelExpressionTypeName = modelExpressionTypeName;
@ -80,7 +80,7 @@ namespace Microsoft.AspNet.Mvc.Razor
} }
private static IEnumerable<TagHelperDirectiveDescriptor> GetTagHelperDirectiveDescriptors( private static IEnumerable<TagHelperDirectiveDescriptor> GetTagHelperDirectiveDescriptors(
IReadOnlyList<CodeTree> inheritedCodeTrees, IReadOnlyList<ChunkTree> inheritedChunkTrees,
IReadOnlyList<Chunk> defaultInheritedChunks) IReadOnlyList<Chunk> defaultInheritedChunks)
{ {
var descriptors = new List<TagHelperDirectiveDescriptor>(); var descriptors = new List<TagHelperDirectiveDescriptor>();
@ -89,7 +89,7 @@ namespace Microsoft.AspNet.Mvc.Razor
// Consequently we must visit tag helpers outside-in - furthest _ViewImports first and nearest one last. // 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 // This is different from the behavior of chunk merging where we visit the nearest one first and ignore
// chunks that were previously visited. // chunks that were previously visited.
var chunksFromViewImports = inheritedCodeTrees var chunksFromViewImports = inheritedChunkTrees
.Reverse() .Reverse()
.SelectMany(tree => tree.Chunks); .SelectMany(tree => tree.Chunks);
var chunksInOrder = defaultInheritedChunks.Concat(chunksFromViewImports); var chunksInOrder = defaultInheritedChunks.Concat(chunksFromViewImports);

View File

@ -2,8 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.CodeGenerators;
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
@ -30,11 +29,12 @@ namespace Microsoft.AspNet.Mvc.Razor
/// <see cref="GeneratedTagHelperAttributeContext.ModelExpressionTypeName"/>, then a model expression will be /// <see cref="GeneratedTagHelperAttributeContext.ModelExpressionTypeName"/>, then a model expression will be
/// created by calling into <see cref="GeneratedTagHelperAttributeContext.CreateModelExpressionMethodName"/>. /// created by calling into <see cref="GeneratedTagHelperAttributeContext.CreateModelExpressionMethodName"/>.
/// </remarks> /// </remarks>
public override void RenderAttributeValue([NotNull] TagHelperAttributeDescriptor attributeDescriptor, public override void RenderAttributeValue(
[NotNull] CSharpCodeWriter writer, [NotNull] TagHelperAttributeDescriptor attributeDescriptor,
[NotNull] CodeBuilderContext codeBuilderContext, [NotNull] CSharpCodeWriter writer,
[NotNull] Action<CSharpCodeWriter> renderAttributeValue, [NotNull] CodeGeneratorContext CodeGeneratorContext,
bool complexValue) [NotNull] Action<CSharpCodeWriter> renderAttributeValue,
bool complexValue)
{ {
if (attributeDescriptor.TypeName.Equals(_context.ModelExpressionTypeName, StringComparison.Ordinal)) if (attributeDescriptor.TypeName.Equals(_context.ModelExpressionTypeName, StringComparison.Ordinal))
{ {
@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Mvc.Razor
base.RenderAttributeValue( base.RenderAttributeValue(
attributeDescriptor, attributeDescriptor,
writer, writer,
codeBuilderContext, CodeGeneratorContext,
renderAttributeValue, renderAttributeValue,
complexValue); complexValue);
} }

View File

@ -7,6 +7,7 @@ using System.IO;
using System.Linq; using System.Linq;
using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Razor; using Microsoft.AspNet.Razor;
using Microsoft.AspNet.Razor.CodeGenerators;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel; using Microsoft.Framework.OptionsModel;

View File

@ -3,7 +3,7 @@
using System; using System;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Razor; using Microsoft.AspNet.Razor.CodeGenerators;
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;

View File

@ -192,7 +192,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Precompilation
protected IMvcRazorHost GetRazorHost() protected IMvcRazorHost GetRazorHost()
{ {
var descriptorResolver = new TagHelperDescriptorResolver(TagHelperTypeResolver); var descriptorResolver = new TagHelperDescriptorResolver(TagHelperTypeResolver);
return new MvcRazorHost(new DefaultCodeTreeCache(FileProvider)) return new MvcRazorHost(new DefaultChunkTreeCache(FileProvider))
{ {
TagHelperDescriptorResolver = descriptorResolver TagHelperDescriptorResolver = descriptorResolver
}; };

View File

@ -117,10 +117,10 @@ namespace Microsoft.Framework.DependencyInjection
// Caches view locations that are valid for the lifetime of the application. // Caches view locations that are valid for the lifetime of the application.
services.TryAdd(ServiceDescriptor.Singleton<IViewLocationCache, DefaultViewLocationCache>()); services.TryAdd(ServiceDescriptor.Singleton<IViewLocationCache, DefaultViewLocationCache>());
services.TryAdd(ServiceDescriptor.Singleton<ICodeTreeCache>(serviceProvider => services.TryAdd(ServiceDescriptor.Singleton<IChunkTreeCache>(serviceProvider =>
{ {
var cachedFileProvider = serviceProvider.GetRequiredService<IOptions<RazorViewEngineOptions>>(); var cachedFileProvider = serviceProvider.GetRequiredService<IOptions<RazorViewEngineOptions>>();
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. // The host is designed to be discarded after consumption and is very inexpensive to initialize.

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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; using Xunit;
namespace Microsoft.AspNet.Mvc.Razor.Directives namespace Microsoft.AspNet.Mvc.Razor.Directives
@ -30,19 +30,19 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
new InjectChunk("MyTestHtmlHelper", "Html"), new InjectChunk("MyTestHtmlHelper", "Html"),
new UsingChunk { Namespace = "AppNamespace.Model" }, new UsingChunk { Namespace = "AppNamespace.Model" },
}; };
var cache = new DefaultCodeTreeCache(fileProvider); var cache = new DefaultChunkTreeCache(fileProvider);
var host = new MvcRazorHost(cache); var host = new MvcRazorHost(cache);
var utility = new ChunkInheritanceUtility(host, cache, defaultChunks); var utility = new ChunkInheritanceUtility(host, cache, defaultChunks);
// Act // Act
var codeTrees = utility.GetInheritedCodeTrees(@"Views\home\Index.cshtml"); var chunkTrees = utility.GetInheritedChunkTrees(@"Views\home\Index.cshtml");
// Assert // Assert
Assert.Collection(codeTrees, Assert.Collection(chunkTrees,
codeTree => ChunkTree =>
{ {
var viewImportsPath = @"Views\home\_ViewImports.cshtml"; var viewImportsPath = @"Views\home\_ViewImports.cshtml";
Assert.Collection(codeTree.Chunks, Assert.Collection(ChunkTree.Chunks,
chunk => chunk =>
{ {
Assert.IsType<LiteralChunk>(chunk); Assert.IsType<LiteralChunk>(chunk);
@ -60,10 +60,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
Assert.Equal(viewImportsPath, chunk.Start.FilePath); Assert.Equal(viewImportsPath, chunk.Start.FilePath);
}); });
}, },
codeTree => ChunkTree =>
{ {
var viewImportsPath = @"Views\_ViewImports.cshtml"; var viewImportsPath = @"Views\_ViewImports.cshtml";
Assert.Collection(codeTree.Chunks, Assert.Collection(ChunkTree.Chunks,
chunk => chunk =>
{ {
Assert.IsType<LiteralChunk>(chunk); Assert.IsType<LiteralChunk>(chunk);
@ -114,7 +114,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
fileProvider.AddFile(@"_ViewImports.cs", string.Empty); fileProvider.AddFile(@"_ViewImports.cs", string.Empty);
fileProvider.AddFile(@"Views\_Layout.cshtml", string.Empty); fileProvider.AddFile(@"Views\_Layout.cshtml", string.Empty);
fileProvider.AddFile(@"Views\home\_not-viewimports.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 host = new MvcRazorHost(cache);
var defaultChunks = new Chunk[] var defaultChunks = new Chunk[]
{ {
@ -124,10 +124,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
var utility = new ChunkInheritanceUtility(host, cache, defaultChunks); var utility = new ChunkInheritanceUtility(host, cache, defaultChunks);
// Act // Act
var codeTrees = utility.GetInheritedCodeTrees(@"Views\home\Index.cshtml"); var chunkTrees = utility.GetInheritedChunkTrees(@"Views\home\Index.cshtml");
// Assert // Assert
Assert.Empty(codeTrees); Assert.Empty(chunkTrees);
} }
[Fact] [Fact]
@ -137,16 +137,16 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
var fileProvider = new TestFileProvider(); var fileProvider = new TestFileProvider();
fileProvider.AddFile(@"Views\_ViewImports.cshtml", fileProvider.AddFile(@"Views\_ViewImports.cshtml",
"@inject DifferentHelper<TModel> Html"); "@inject DifferentHelper<TModel> Html");
var cache = new DefaultCodeTreeCache(fileProvider); var cache = new DefaultChunkTreeCache(fileProvider);
var host = new MvcRazorHost(cache); var host = new MvcRazorHost(cache);
var defaultChunks = new Chunk[] var defaultChunks = new Chunk[]
{ {
new InjectChunk("MyTestHtmlHelper", "Html"), new InjectChunk("MyTestHtmlHelper", "Html"),
new UsingChunk { Namespace = "AppNamespace.Model" }, new UsingChunk { Namespace = "AppNamespace.Model" },
}; };
var inheritedCodeTrees = new CodeTree[] var inheritedChunkTrees = new ChunkTree[]
{ {
new CodeTree new ChunkTree
{ {
Chunks = new Chunk[] Chunks = new Chunk[]
{ {
@ -154,7 +154,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
new LiteralChunk { Text = "some text" } new LiteralChunk { Text = "some text" }
} }
}, },
new CodeTree new ChunkTree
{ {
Chunks = new Chunk[] Chunks = new Chunk[]
{ {
@ -164,18 +164,18 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
}; };
var utility = new ChunkInheritanceUtility(host, cache, defaultChunks); var utility = new ChunkInheritanceUtility(host, cache, defaultChunks);
var codeTree = new CodeTree(); var chunkTree = new ChunkTree();
// Act // Act
utility.MergeInheritedCodeTrees(codeTree, utility.MergeInheritedChunkTrees(chunkTree,
inheritedCodeTrees, inheritedChunkTrees,
"dynamic"); "dynamic");
// Assert // Assert
Assert.Equal(3, codeTree.Chunks.Count); Assert.Equal(3, chunkTree.Chunks.Count);
Assert.Same(inheritedCodeTrees[0].Chunks[0], codeTree.Chunks[0]); Assert.Same(inheritedChunkTrees[0].Chunks[0], chunkTree.Chunks[0]);
Assert.Same(inheritedCodeTrees[1].Chunks[0], codeTree.Chunks[1]); Assert.Same(inheritedChunkTrees[1].Chunks[0], chunkTree.Chunks[1]);
Assert.Same(defaultChunks[0], codeTree.Chunks[2]); Assert.Same(defaultChunks[0], chunkTree.Chunks[2]);
} }
} }
} }

View File

@ -3,7 +3,7 @@
using System; using System;
using Microsoft.AspNet.Mvc.Razor.Directives; 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.Caching.Memory;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Moq; using Moq;
@ -11,7 +11,7 @@ using Xunit;
namespace Microsoft.AspNet.Mvc.Razor.Host.Directives namespace Microsoft.AspNet.Mvc.Razor.Host.Directives
{ {
public class CodeTreeCacheTest public class ChunkTreeCacheTest
{ {
[Fact] [Fact]
public void GetOrAdd_ReturnsCachedEntriesOnSubsequentCalls() public void GetOrAdd_ReturnsCachedEntriesOnSubsequentCalls()
@ -21,12 +21,12 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives
var mockFileProvider = new Mock<TestFileProvider> { CallBase = true }; var mockFileProvider = new Mock<TestFileProvider> { CallBase = true };
var fileProvider = mockFileProvider.Object; var fileProvider = mockFileProvider.Object;
fileProvider.AddFile(path, "test content"); fileProvider.AddFile(path, "test content");
var codeTreeCache = new DefaultCodeTreeCache(fileProvider); var chunkTreeCache = new DefaultChunkTreeCache(fileProvider);
var expected = new CodeTree(); var expected = new ChunkTree();
// Act // Act
var result1 = codeTreeCache.GetOrAdd(path, fileInfo => expected); var result1 = chunkTreeCache.GetOrAdd(path, fileInfo => expected);
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 // Assert
Assert.Same(expected, result1); Assert.Same(expected, result1);
@ -41,12 +41,12 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives
var path = @"Views\_ViewStart.cshtml"; var path = @"Views\_ViewStart.cshtml";
var mockFileProvider = new Mock<TestFileProvider> { CallBase = true }; var mockFileProvider = new Mock<TestFileProvider> { CallBase = true };
var fileProvider = mockFileProvider.Object; var fileProvider = mockFileProvider.Object;
var codeTreeCache = new DefaultCodeTreeCache(fileProvider); var chunkTreeCache = new DefaultChunkTreeCache(fileProvider);
var expected = new CodeTree(); var expected = new ChunkTree();
// Act // Act
var result1 = codeTreeCache.GetOrAdd(path, fileInfo => expected); var result1 = chunkTreeCache.GetOrAdd(path, fileInfo => expected);
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 // Assert
Assert.Null(result1); Assert.Null(result1);
@ -61,19 +61,19 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives
var path = @"Views\Home\_ViewStart.cshtml"; var path = @"Views\Home\_ViewStart.cshtml";
var fileProvider = new TestFileProvider(); var fileProvider = new TestFileProvider();
fileProvider.AddFile(path, "test content"); fileProvider.AddFile(path, "test content");
var codeTreeCache = new DefaultCodeTreeCache(fileProvider); var chunkTreeCache = new DefaultChunkTreeCache(fileProvider);
var expected1 = new CodeTree(); var expected1 = new ChunkTree();
var expected2 = new CodeTree(); var expected2 = new ChunkTree();
// Act 1 // Act 1
var result1 = codeTreeCache.GetOrAdd(path, fileInfo => expected1); var result1 = chunkTreeCache.GetOrAdd(path, fileInfo => expected1);
// Assert 1 // Assert 1
Assert.Same(expected1, result1); Assert.Same(expected1, result1);
// Act 2 // Act 2
fileProvider.GetTrigger(path).IsExpired = true; fileProvider.GetTrigger(path).IsExpired = true;
var result2 = codeTreeCache.GetOrAdd(path, fileInfo => expected2); var result2 = chunkTreeCache.GetOrAdd(path, fileInfo => expected2);
// Assert 2 // Assert 2
Assert.Same(expected2, result2); Assert.Same(expected2, result2);
@ -86,11 +86,11 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives
var path = @"Views\Home\_ViewStart.cshtml"; var path = @"Views\Home\_ViewStart.cshtml";
var fileProvider = new TestFileProvider(); var fileProvider = new TestFileProvider();
fileProvider.AddFile(path, "test content"); fileProvider.AddFile(path, "test content");
var codeTreeCache = new DefaultCodeTreeCache(fileProvider); var chunkTreeCache = new DefaultChunkTreeCache(fileProvider);
var expected1 = new CodeTree(); var expected1 = new ChunkTree();
// Act 1 // Act 1
var result1 = codeTreeCache.GetOrAdd(path, fileInfo => expected1); var result1 = chunkTreeCache.GetOrAdd(path, fileInfo => expected1);
// Assert 1 // Assert 1
Assert.Same(expected1, result1); Assert.Same(expected1, result1);
@ -98,7 +98,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives
// Act 2 // Act 2
fileProvider.DeleteFile(path); fileProvider.DeleteFile(path);
fileProvider.GetTrigger(path).IsExpired = true; 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 2
Assert.Null(result2); Assert.Null(result2);
@ -110,11 +110,11 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives
// Arrange // Arrange
var path = @"Views\Home\_ViewStart.cshtml"; var path = @"Views\Home\_ViewStart.cshtml";
var fileProvider = new TestFileProvider(); var fileProvider = new TestFileProvider();
var codeTreeCache = new DefaultCodeTreeCache(fileProvider); var chunkTreeCache = new DefaultChunkTreeCache(fileProvider);
var expected = new CodeTree(); var expected = new ChunkTree();
// Act 1 // 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 1
Assert.Null(result1); Assert.Null(result1);
@ -122,7 +122,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives
// Act 2 // Act 2
fileProvider.AddFile(path, "test content"); fileProvider.AddFile(path, "test content");
fileProvider.GetTrigger(path).IsExpired = true; fileProvider.GetTrigger(path).IsExpired = true;
var result2 = codeTreeCache.GetOrAdd(path, fileInfo => expected); var result2 = chunkTreeCache.GetOrAdd(path, fileInfo => expected);
// Assert 2 // Assert 2
Assert.Same(expected, result2); Assert.Same(expected, result2);
@ -140,29 +140,29 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives
clock.SetupGet(c => c.UtcNow) clock.SetupGet(c => c.UtcNow)
.Returns(() => utcNow); .Returns(() => utcNow);
var options = new MemoryCacheOptions { Clock = clock.Object }; var options = new MemoryCacheOptions { Clock = clock.Object };
var codeTreeCache = new DefaultCodeTreeCache(fileProvider, options); var chunkTreeCache = new DefaultChunkTreeCache(fileProvider, options);
var codeTree1 = new CodeTree(); var chunkTree1 = new ChunkTree();
var codeTree2 = new CodeTree(); var chunkTree2 = new ChunkTree();
// Act 1 // Act 1
var result1 = codeTreeCache.GetOrAdd(path, fileInfo => codeTree1); var result1 = chunkTreeCache.GetOrAdd(path, fileInfo => chunkTree1);
// Assert 1 // Assert 1
Assert.Same(codeTree1, result1); Assert.Same(chunkTree1, result1);
// Act 2 // Act 2
utcNow = utcNow.AddSeconds(59); 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 2
Assert.Same(codeTree1, result2); Assert.Same(chunkTree1, result2);
// Act 3 // Act 3
utcNow = utcNow.AddSeconds(65); utcNow = utcNow.AddSeconds(65);
var result3 = codeTreeCache.GetOrAdd(path, fileInfo => codeTree2); var result3 = chunkTreeCache.GetOrAdd(path, fileInfo => chunkTree2);
// Assert 3 // Assert 3
Assert.Same(codeTree2, result3); Assert.Same(chunkTree2, result3);
} }
} }
} }

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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 Microsoft.AspNet.Testing;
using Xunit; using Xunit;
@ -45,41 +45,41 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
var merger = new InjectChunkMerger("dynamic"); var merger = new InjectChunkMerger("dynamic");
// Act and Assert // Act and Assert
ExceptionAssert.ThrowsArgument(() => merger.Merge(new CodeTree(), new LiteralChunk()), "chunk", expected); ExceptionAssert.ThrowsArgument(() => merger.Merge(new ChunkTree(), new LiteralChunk()), "chunk", expected);
} }
[Fact] [Fact]
public void Merge_AddsChunkIfChunkWithMatchingPropertyNameWasNotVisitedInCodeTree() public void Merge_AddsChunkIfChunkWithMatchingPropertyNameWasNotVisitedInChunkTree()
{ {
// Arrange // Arrange
var expectedType = "MyApp.MyHelperType"; var expectedType = "MyApp.MyHelperType";
var expectedProperty = "MyHelper"; var expectedProperty = "MyHelper";
var merger = new InjectChunkMerger("dynamic"); var merger = new InjectChunkMerger("dynamic");
var codeTree = new CodeTree(); var chunkTree = new ChunkTree();
// Act // Act
merger.Merge(codeTree, new InjectChunk(expectedType, expectedProperty)); merger.Merge(chunkTree, new InjectChunk(expectedType, expectedProperty));
// Assert // Assert
var chunk = Assert.Single(codeTree.Chunks); var chunk = Assert.Single(chunkTree.Chunks);
var injectChunk = Assert.IsType<InjectChunk>(chunk); var injectChunk = Assert.IsType<InjectChunk>(chunk);
Assert.Equal(expectedType, injectChunk.TypeName); Assert.Equal(expectedType, injectChunk.TypeName);
Assert.Equal(expectedProperty, injectChunk.MemberName); Assert.Equal(expectedProperty, injectChunk.MemberName);
} }
[Fact] [Fact]
public void Merge_IgnoresChunkIfChunkWithMatchingPropertyNameWasVisitedInCodeTree() public void Merge_IgnoresChunkIfChunkWithMatchingPropertyNameWasVisitedInChunkTree()
{ {
// Arrange // Arrange
var merger = new InjectChunkMerger("dynamic"); var merger = new InjectChunkMerger("dynamic");
var codeTree = new CodeTree(); var chunkTree = new ChunkTree();
// Act // Act
merger.VisitChunk(new InjectChunk("MyTypeA", "MyProperty")); merger.VisitChunk(new InjectChunk("MyTypeA", "MyProperty"));
merger.Merge(codeTree, new InjectChunk("MyTypeB", "MyProperty")); merger.Merge(chunkTree, new InjectChunk("MyTypeB", "MyProperty"));
// Assert // Assert
Assert.Empty(codeTree.Chunks); Assert.Empty(chunkTree.Chunks);
} }
[Fact] [Fact]
@ -87,20 +87,20 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
{ {
// Arrange // Arrange
var merger = new InjectChunkMerger("dynamic"); var merger = new InjectChunkMerger("dynamic");
var codeTree = new CodeTree(); var chunkTree = new ChunkTree();
// Act // Act
merger.VisitChunk(new InjectChunk("MyType", "MyProperty")); merger.VisitChunk(new InjectChunk("MyType", "MyProperty"));
merger.Merge(codeTree, new InjectChunk("MyType", "myproperty")); merger.Merge(chunkTree, new InjectChunk("MyType", "myproperty"));
merger.Merge(codeTree, new InjectChunk("MyTypeB", "different-property")); merger.Merge(chunkTree, new InjectChunk("MyTypeB", "different-property"));
// Assert // Assert
Assert.Equal(2, codeTree.Chunks.Count); Assert.Equal(2, chunkTree.Chunks.Count);
var injectChunk = Assert.IsType<InjectChunk>(codeTree.Chunks[0]); var injectChunk = Assert.IsType<InjectChunk>(chunkTree.Chunks[0]);
Assert.Equal("MyType", injectChunk.TypeName); Assert.Equal("MyType", injectChunk.TypeName);
Assert.Equal("myproperty", injectChunk.MemberName); Assert.Equal("myproperty", injectChunk.MemberName);
injectChunk = Assert.IsType<InjectChunk>(codeTree.Chunks[1]); injectChunk = Assert.IsType<InjectChunk>(chunkTree.Chunks[1]);
Assert.Equal("MyTypeB", injectChunk.TypeName); Assert.Equal("MyTypeB", injectChunk.TypeName);
Assert.Equal("different-property", injectChunk.MemberName); Assert.Equal("different-property", injectChunk.MemberName);
} }
@ -110,13 +110,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
{ {
// Arrange // Arrange
var merger = new InjectChunkMerger("dynamic"); var merger = new InjectChunkMerger("dynamic");
var codeTree = new CodeTree(); var chunkTree = new ChunkTree();
// Act // Act
merger.Merge(codeTree, new InjectChunk("MyHelper<TModel>", "MyProperty")); merger.Merge(chunkTree, new InjectChunk("MyHelper<TModel>", "MyProperty"));
// Assert // Assert
var chunk = Assert.Single(codeTree.Chunks); var chunk = Assert.Single(chunkTree.Chunks);
var injectChunk = Assert.IsType<InjectChunk>(chunk); var injectChunk = Assert.IsType<InjectChunk>(chunk);
Assert.Equal("MyHelper<dynamic>", injectChunk.TypeName); Assert.Equal("MyHelper<dynamic>", injectChunk.TypeName);
Assert.Equal("MyProperty", injectChunk.MemberName); Assert.Equal("MyProperty", injectChunk.MemberName);
@ -127,13 +127,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
{ {
// Arrange // Arrange
var merger = new InjectChunkMerger("MyTestModel2"); var merger = new InjectChunkMerger("MyTestModel2");
var codeTree = new CodeTree(); var chunkTree = new ChunkTree();
// Act // Act
merger.Merge(codeTree, new InjectChunk("MyHelper<TModel>", "MyProperty")); merger.Merge(chunkTree, new InjectChunk("MyHelper<TModel>", "MyProperty"));
// Assert // Assert
var chunk = Assert.Single(codeTree.Chunks); var chunk = Assert.Single(chunkTree.Chunks);
var injectChunk = Assert.IsType<InjectChunk>(chunk); var injectChunk = Assert.IsType<InjectChunk>(chunk);
Assert.Equal("MyHelper<MyTestModel2>", injectChunk.TypeName); Assert.Equal("MyHelper<MyTestModel2>", injectChunk.TypeName);
Assert.Equal("MyProperty", injectChunk.MemberName); Assert.Equal("MyProperty", injectChunk.MemberName);
@ -144,14 +144,14 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
{ {
// Arrange // Arrange
var merger = new InjectChunkMerger("dynamic"); var merger = new InjectChunkMerger("dynamic");
var codeTree = new CodeTree(); var chunkTree = new ChunkTree();
// Act // Act
merger.Merge(codeTree, new InjectChunk("SomeType", "Property")); merger.Merge(chunkTree, new InjectChunk("SomeType", "Property"));
merger.Merge(codeTree, new InjectChunk("SomeOtherType", "Property")); merger.Merge(chunkTree, new InjectChunk("SomeOtherType", "Property"));
// Assert // Assert
var chunk = Assert.Single(codeTree.Chunks); var chunk = Assert.Single(chunkTree.Chunks);
var injectChunk = Assert.IsType<InjectChunk>(chunk); var injectChunk = Assert.IsType<InjectChunk>(chunk);
Assert.Equal("SomeType", injectChunk.TypeName); Assert.Equal("SomeType", injectChunk.TypeName);
Assert.Equal("Property", injectChunk.MemberName); Assert.Equal("Property", injectChunk.MemberName);

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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 Microsoft.AspNet.Testing;
using Xunit; using Xunit;
@ -14,7 +14,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
{ {
// Arrange // Arrange
var expected = "Argument must be an instance of " + var expected = "Argument must be an instance of " +
"'Microsoft.AspNet.Razor.Generator.Compiler.SetBaseTypeChunk'."; "'Microsoft.AspNet.Razor.Chunks.SetBaseTypeChunk'.";
var merger = new SetBaseTypeChunkMerger("dynamic"); var merger = new SetBaseTypeChunkMerger("dynamic");
// Act and Assert // Act and Assert
@ -45,43 +45,43 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
{ {
// Arrange // Arrange
var expected = "Argument must be an instance of " + var expected = "Argument must be an instance of " +
"'Microsoft.AspNet.Razor.Generator.Compiler.SetBaseTypeChunk'."; "'Microsoft.AspNet.Razor.Chunks.SetBaseTypeChunk'.";
var merger = new SetBaseTypeChunkMerger("dynamic"); var merger = new SetBaseTypeChunkMerger("dynamic");
// Act and Assert // Act and Assert
ExceptionAssert.ThrowsArgument(() => merger.Merge(new CodeTree(), new LiteralChunk()), "chunk", expected); ExceptionAssert.ThrowsArgument(() => merger.Merge(new ChunkTree(), new LiteralChunk()), "chunk", expected);
} }
[Fact] [Fact]
public void Merge_SetsBaseTypeIfItHasNotBeenSetInCodeTree() public void Merge_SetsBaseTypeIfItHasNotBeenSetInChunkTree()
{ {
// Arrange // Arrange
var expected = "MyApp.Razor.MyBaseType"; var expected = "MyApp.Razor.MyBaseType";
var merger = new SetBaseTypeChunkMerger("dynamic"); var merger = new SetBaseTypeChunkMerger("dynamic");
var codeTree = new CodeTree(); var chunkTree = new ChunkTree();
// Act // Act
merger.Merge(codeTree, new SetBaseTypeChunk { TypeName = expected }); merger.Merge(chunkTree, new SetBaseTypeChunk { TypeName = expected });
// Assert // Assert
var chunk = Assert.Single(codeTree.Chunks); var chunk = Assert.Single(chunkTree.Chunks);
var setBaseTypeChunk = Assert.IsType<SetBaseTypeChunk>(chunk); var setBaseTypeChunk = Assert.IsType<SetBaseTypeChunk>(chunk);
Assert.Equal(expected, setBaseTypeChunk.TypeName); Assert.Equal(expected, setBaseTypeChunk.TypeName);
} }
[Fact] [Fact]
public void Merge_IgnoresSetBaseTypeChunksIfCodeTreeContainsOne() public void Merge_IgnoresSetBaseTypeChunksIfChunkTreeContainsOne()
{ {
// Arrange // Arrange
var merger = new SetBaseTypeChunkMerger("dynamic"); var merger = new SetBaseTypeChunkMerger("dynamic");
var codeTree = new CodeTree(); var chunkTree = new ChunkTree();
// Act // Act
merger.VisitChunk(new SetBaseTypeChunk { TypeName = "MyBaseType1" }); merger.VisitChunk(new SetBaseTypeChunk { TypeName = "MyBaseType1" });
merger.Merge(codeTree, new SetBaseTypeChunk { TypeName = "MyBaseType2" }); merger.Merge(chunkTree, new SetBaseTypeChunk { TypeName = "MyBaseType2" });
// Assert // Assert
Assert.Empty(codeTree.Chunks); Assert.Empty(chunkTree.Chunks);
} }
[Fact] [Fact]
@ -89,14 +89,14 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
{ {
// Arrange // Arrange
var merger = new SetBaseTypeChunkMerger("dynamic"); var merger = new SetBaseTypeChunkMerger("dynamic");
var codeTree = new CodeTree(); var chunkTree = new ChunkTree();
// Act // Act
merger.Merge(codeTree, new SetBaseTypeChunk { TypeName = "MyBase1" }); merger.Merge(chunkTree, new SetBaseTypeChunk { TypeName = "MyBase1" });
merger.Merge(codeTree, new SetBaseTypeChunk { TypeName = "MyBase2" }); merger.Merge(chunkTree, new SetBaseTypeChunk { TypeName = "MyBase2" });
// Assert // Assert
var chunk = Assert.Single(codeTree.Chunks); var chunk = Assert.Single(chunkTree.Chunks);
var setBaseTypeChunk = Assert.IsType<SetBaseTypeChunk>(chunk); var setBaseTypeChunk = Assert.IsType<SetBaseTypeChunk>(chunk);
Assert.Equal("MyBase1", setBaseTypeChunk.TypeName); Assert.Equal("MyBase1", setBaseTypeChunk.TypeName);
} }

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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 Microsoft.AspNet.Testing;
using Xunit; using Xunit;
@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
public void Visit_ThrowsIfThePassedInChunkIsNotAUsingChunk() public void Visit_ThrowsIfThePassedInChunkIsNotAUsingChunk()
{ {
// Arrange // 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(); var merger = new UsingChunkMerger();
// Act and Assert // Act and Assert
@ -24,44 +24,44 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
public void Merge_ThrowsIfThePassedInChunkIsNotAUsingChunk() public void Merge_ThrowsIfThePassedInChunkIsNotAUsingChunk()
{ {
// Arrange // 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(); var merger = new UsingChunkMerger();
// Act and Assert // Act and Assert
ExceptionAssert.ThrowsArgument(() => merger.Merge(new CodeTree(), new LiteralChunk()), "chunk", expected); ExceptionAssert.ThrowsArgument(() => merger.Merge(new ChunkTree(), new LiteralChunk()), "chunk", expected);
} }
[Fact] [Fact]
public void Merge_AddsNamespacesThatHaveNotBeenVisitedInCodeTree() public void Merge_AddsNamespacesThatHaveNotBeenVisitedInChunkTree()
{ {
// Arrange // Arrange
var expected = "MyApp.Models"; var expected = "MyApp.Models";
var merger = new UsingChunkMerger(); var merger = new UsingChunkMerger();
var codeTree = new CodeTree(); var chunkTree = new ChunkTree();
// Act // Act
merger.VisitChunk(new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }); merger.VisitChunk(new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" });
merger.Merge(codeTree, new UsingChunk { Namespace = expected }); merger.Merge(chunkTree, new UsingChunk { Namespace = expected });
// Assert // Assert
var chunk = Assert.Single(codeTree.Chunks); var chunk = Assert.Single(chunkTree.Chunks);
var usingChunk = Assert.IsType<UsingChunk>(chunk); var usingChunk = Assert.IsType<UsingChunk>(chunk);
Assert.Equal(expected, usingChunk.Namespace); Assert.Equal(expected, usingChunk.Namespace);
} }
[Fact] [Fact]
public void Merge_IgnoresNamespacesThatHaveBeenVisitedInCodeTree() public void Merge_IgnoresNamespacesThatHaveBeenVisitedInChunkTree()
{ {
// Arrange // Arrange
var merger = new UsingChunkMerger(); var merger = new UsingChunkMerger();
var codeTree = new CodeTree(); var chunkTree = new ChunkTree();
// Act // Act
merger.VisitChunk(new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }); 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
Assert.Empty(codeTree.Chunks); Assert.Empty(chunkTree.Chunks);
} }
[Fact] [Fact]
@ -69,18 +69,18 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
{ {
// Arrange // Arrange
var merger = new UsingChunkMerger(); var merger = new UsingChunkMerger();
var codeTree = new CodeTree(); var chunkTree = new ChunkTree();
// Act // Act
merger.Merge(codeTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }); merger.Merge(chunkTree, 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(codeTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc.Razor" }); merger.Merge(chunkTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc.Razor" });
// Assert // Assert
Assert.Equal(2, codeTree.Chunks.Count); Assert.Equal(2, chunkTree.Chunks.Count);
var chunk = Assert.IsType<UsingChunk>(codeTree.Chunks[0]); var chunk = Assert.IsType<UsingChunk>(chunkTree.Chunks[0]);
Assert.Equal("Microsoft.AspNet.Mvc", chunk.Namespace); Assert.Equal("Microsoft.AspNet.Mvc", chunk.Namespace);
chunk = Assert.IsType<UsingChunk>(codeTree.Chunks[1]); chunk = Assert.IsType<UsingChunk>(chunkTree.Chunks[1]);
Assert.Equal("Microsoft.AspNet.Mvc.Razor", chunk.Namespace); Assert.Equal("Microsoft.AspNet.Mvc.Razor", chunk.Namespace);
} }
@ -89,17 +89,17 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
{ {
// Arrange // Arrange
var merger = new UsingChunkMerger(); var merger = new UsingChunkMerger();
var codeTree = new CodeTree(); var chunkTree = new ChunkTree();
// Act // Act
merger.Merge(codeTree, new UsingChunk { Namespace = "Microsoft.AspNet.Mvc" }); merger.Merge(chunkTree, 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
Assert.Equal(2, codeTree.Chunks.Count); Assert.Equal(2, chunkTree.Chunks.Count);
var chunk = Assert.IsType<UsingChunk>(codeTree.Chunks[0]); var chunk = Assert.IsType<UsingChunk>(chunkTree.Chunks[0]);
Assert.Equal("Microsoft.AspNet.Mvc", chunk.Namespace); Assert.Equal("Microsoft.AspNet.Mvc", chunk.Namespace);
chunk = Assert.IsType<UsingChunk>(codeTree.Chunks[1]); chunk = Assert.IsType<UsingChunk>(chunkTree.Chunks[1]);
Assert.Equal("Microsoft.AspNet.mvc", chunk.Namespace); Assert.Equal("Microsoft.AspNet.mvc", chunk.Namespace);
} }
} }

View File

@ -4,9 +4,9 @@
using System; using System;
using Microsoft.AspNet.Mvc.Razor.Directives; using Microsoft.AspNet.Mvc.Razor.Directives;
using Microsoft.AspNet.Razor; using Microsoft.AspNet.Razor;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks;
using Microsoft.AspNet.Razor.Generator.Compiler; using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp; using Microsoft.AspNet.Razor.CodeGenerators;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Xunit; using Xunit;
@ -144,15 +144,16 @@ MyType1
Assert.Equal(expected, code); Assert.Equal(expected, code);
} }
private static CodeBuilderContext CreateContext() private static CodeGeneratorContext CreateContext()
{ {
var codeTreeCache = new DefaultCodeTreeCache(new TestFileProvider()); var chunkTreeCache = new DefaultChunkTreeCache(new TestFileProvider());
return new CodeBuilderContext( return new CodeGeneratorContext(
new CodeGeneratorContext(new MvcRazorHost(codeTreeCache), new ChunkGeneratorContext(
"MyClass", new MvcRazorHost(chunkTreeCache),
"MyNamespace", "MyClass",
string.Empty, "MyNamespace",
shouldGenerateLinePragmas: true), string.Empty,
shouldGenerateLinePragmas: true),
new ErrorSink()); new ErrorSink());
} }
} }

View File

@ -4,9 +4,10 @@
using System; using System;
using Microsoft.AspNet.Mvc.Razor.Directives; using Microsoft.AspNet.Mvc.Razor.Directives;
using Microsoft.AspNet.Razor; 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;
using Microsoft.AspNet.Razor.Generator.Compiler;
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Xunit; using Xunit;
@ -53,7 +54,7 @@ Environment.NewLine +
var visitor = new ModelChunkVisitor(writer, context); var visitor = new ModelChunkVisitor(writer, context);
var factory = SpanFactory.CreateCsHtml(); var factory = SpanFactory.CreateCsHtml();
var node = (Span)factory.Code("Some code") var node = (Span)factory.Code("Some code")
.As(new ModelCodeGenerator("MyBase", "MyGeneric")); .As(new ModelChunkGenerator("MyBase", "MyGeneric"));
// Act // Act
visitor.Accept(new Chunk[] visitor.Accept(new Chunk[]
@ -86,7 +87,7 @@ Environment.NewLine +
var visitor = new ModelChunkVisitor(writer, context); var visitor = new ModelChunkVisitor(writer, context);
var factory = SpanFactory.CreateCsHtml(); var factory = SpanFactory.CreateCsHtml();
var node = (Span)factory.Code("Some code") var node = (Span)factory.Code("Some code")
.As(new ModelCodeGenerator("MyType", "MyPropertyName")); .As(new ModelChunkGenerator("MyType", "MyPropertyName"));
// Act // Act
visitor.Accept(new Chunk[] visitor.Accept(new Chunk[]
@ -100,15 +101,16 @@ Environment.NewLine +
Assert.Equal(expected, code); Assert.Equal(expected, code);
} }
private static CodeBuilderContext CreateContext() private static CodeGeneratorContext CreateContext()
{ {
var fileProvider = new TestFileProvider(); var fileProvider = new TestFileProvider();
return new CodeBuilderContext( return new CodeGeneratorContext(
new CodeGeneratorContext(new MvcRazorHost(new DefaultCodeTreeCache(fileProvider)), new ChunkGeneratorContext(
"MyClass", new MvcRazorHost(new DefaultChunkTreeCache(fileProvider)),
"MyNamespace", "MyClass",
string.Empty, "MyNamespace",
shouldGenerateLinePragmas: true), string.Empty,
shouldGenerateLinePragmas: true),
new ErrorSink()); new ErrorSink());
} }
} }

View File

@ -5,8 +5,9 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Razor; 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;
using Microsoft.AspNet.Razor.Generator.Compiler;
using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Text;
@ -46,7 +47,7 @@ namespace Microsoft.AspNet.Mvc.Razor
factory.MetaCode("model ") factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None), .Accepts(AcceptedCharacters.None),
factory.Code(" Foo") factory.Code(" Foo")
.As(new ModelCodeGenerator("RazorView", "Foo")) .As(new ModelChunkGenerator("RazorView", "Foo"))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.EmptyHtml() factory.EmptyHtml()
}; };
@ -78,10 +79,10 @@ namespace Microsoft.AspNet.Mvc.Razor
factory.MetaCode("model ") factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None), .Accepts(AcceptedCharacters.None),
factory.Code(modelName + "\r\n") factory.Code(modelName + "\r\n")
.As(new ModelCodeGenerator("RazorView", expectedModel)) .As(new ModelChunkGenerator("RazorView", expectedModel))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.Markup("Bar") factory.Markup("Bar")
.With(new MarkupCodeGenerator()) .With(new MarkupChunkGenerator())
}; };
// Act // Act
@ -110,7 +111,7 @@ namespace Microsoft.AspNet.Mvc.Razor
factory.MetaCode("model ") factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None), .Accepts(AcceptedCharacters.None),
factory.Code(" ") factory.Code(" ")
.As(new ModelCodeGenerator("RazorView", string.Empty)) .As(new ModelChunkGenerator("RazorView", string.Empty))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.EmptyHtml(), factory.EmptyHtml(),
}; };
@ -141,7 +142,7 @@ namespace Microsoft.AspNet.Mvc.Razor
factory.MetaCode("model ") factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None), .Accepts(AcceptedCharacters.None),
factory.Code("Foo\r\n") factory.Code("Foo\r\n")
.As(new ModelCodeGenerator("RazorView", "Foo")) .As(new ModelChunkGenerator("RazorView", "Foo"))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.EmptyHtml(), factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString) factory.CodeTransition(SyntaxConstants.TransitionString)
@ -149,7 +150,7 @@ namespace Microsoft.AspNet.Mvc.Razor
factory.MetaCode("model ") factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None), .Accepts(AcceptedCharacters.None),
factory.Code("Bar") factory.Code("Bar")
.As(new ModelCodeGenerator("RazorView", "Bar")) .As(new ModelChunkGenerator("RazorView", "Bar"))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.EmptyHtml() factory.EmptyHtml()
}; };
@ -186,7 +187,7 @@ namespace Microsoft.AspNet.Mvc.Razor
factory.MetaCode("model ") factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None), .Accepts(AcceptedCharacters.None),
factory.Code("Foo\r\n") factory.Code("Foo\r\n")
.As(new ModelCodeGenerator("RazorView", "Foo")) .As(new ModelChunkGenerator("RazorView", "Foo"))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.EmptyHtml(), factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString) factory.CodeTransition(SyntaxConstants.TransitionString)
@ -194,7 +195,7 @@ namespace Microsoft.AspNet.Mvc.Razor
factory.MetaCode("inherits ") factory.MetaCode("inherits ")
.Accepts(AcceptedCharacters.None), .Accepts(AcceptedCharacters.None),
factory.Code("Bar") factory.Code("Bar")
.As(new SetBaseTypeCodeGenerator("Bar")) .As(new SetBaseTypeChunkGenerator("Bar"))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.EmptyHtml() factory.EmptyHtml()
}; };
@ -231,7 +232,7 @@ namespace Microsoft.AspNet.Mvc.Razor
factory.MetaCode("inherits ") factory.MetaCode("inherits ")
.Accepts(AcceptedCharacters.None), .Accepts(AcceptedCharacters.None),
factory.Code("Bar" + Environment.NewLine) factory.Code("Bar" + Environment.NewLine)
.As(new SetBaseTypeCodeGenerator("Bar")) .As(new SetBaseTypeChunkGenerator("Bar"))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.EmptyHtml(), factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString) factory.CodeTransition(SyntaxConstants.TransitionString)
@ -239,7 +240,7 @@ namespace Microsoft.AspNet.Mvc.Razor
factory.MetaCode("model ") factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None), .Accepts(AcceptedCharacters.None),
factory.Code("Foo") factory.Code("Foo")
.As(new ModelCodeGenerator("RazorView", "Foo")) .As(new ModelChunkGenerator("RazorView", "Foo"))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.EmptyHtml() factory.EmptyHtml()
}; };
@ -360,7 +361,7 @@ namespace Microsoft.AspNet.Mvc.Razor
.As(new InjectParameterGenerator(expectedService, expectedPropertyName)) .As(new InjectParameterGenerator(expectedService, expectedPropertyName))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.Markup("Bar") factory.Markup("Bar")
.With(new MarkupCodeGenerator()) .With(new MarkupChunkGenerator())
}; };
// Act // Act
@ -389,7 +390,7 @@ namespace Microsoft.AspNet.Mvc.Razor
.As(new InjectParameterGenerator(string.Empty, string.Empty)) .As(new InjectParameterGenerator(string.Empty, string.Empty))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.Markup("Bar") factory.Markup("Bar")
.With(new MarkupCodeGenerator()) .With(new MarkupChunkGenerator())
}; };
var expectedErrors = new[] var expectedErrors = new[]
{ {
@ -456,7 +457,7 @@ namespace Microsoft.AspNet.Mvc.Razor
.As(new InjectParameterGenerator("IMyService", string.Empty)) .As(new InjectParameterGenerator("IMyService", string.Empty))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.Markup("Bar") factory.Markup("Bar")
.With(new MarkupCodeGenerator()) .With(new MarkupChunkGenerator())
}; };
var expectedErrors = new[] var expectedErrors = new[]
{ {

View File

@ -7,9 +7,10 @@ using System.IO;
using Microsoft.AspNet.Mvc.Razor.Directives; using Microsoft.AspNet.Mvc.Razor.Directives;
using Microsoft.AspNet.Mvc.Razor.Internal; using Microsoft.AspNet.Mvc.Razor.Internal;
using Microsoft.AspNet.Razor; using Microsoft.AspNet.Razor;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks;
using Microsoft.AspNet.Razor.Generator.Compiler; using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp; using Microsoft.AspNet.Razor.CodeGenerators;
using Microsoft.AspNet.Razor.CodeGenerators.Visitors;
using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Xunit; using Xunit;
@ -30,7 +31,7 @@ namespace Microsoft.AspNet.Mvc.Razor
var rootedAppPath = $"{rootPrefix}SomeComputer/Location/Project/"; var rootedAppPath = $"{rootPrefix}SomeComputer/Location/Project/";
var rootedFilePath = $"{rootPrefix}SomeComputer/Location/Project/src/file.cshtml"; var rootedFilePath = $"{rootPrefix}SomeComputer/Location/Project/src/file.cshtml";
var host = new MvcRazorHost( var host = new MvcRazorHost(
codeTreeCache: null, ChunkTreeCache: null,
pathNormalizer: new DesignTimeRazorPathNormalizer(rootedAppPath)); pathNormalizer: new DesignTimeRazorPathNormalizer(rootedAppPath));
var parser = new RazorParser( var parser = new RazorParser(
host.CodeLanguage.CreateCodeParser(), host.CodeLanguage.CreateCodeParser(),
@ -43,7 +44,7 @@ namespace Microsoft.AspNet.Mvc.Razor
host.DecorateRazorParser(parser, rootedFilePath); host.DecorateRazorParser(parser, rootedFilePath);
// Assert // Assert
Assert.Equal("src/file.cshtml", chunkInheritanceUtility.InheritedCodeTreePagePath, StringComparer.Ordinal); Assert.Equal("src/file.cshtml", chunkInheritanceUtility.InheritedChunkTreePagePath, StringComparer.Ordinal);
} }
[Theory] [Theory]
@ -51,32 +52,32 @@ namespace Microsoft.AspNet.Mvc.Razor
[InlineData("C:/")] [InlineData("C:/")]
[InlineData(@"\\")] [InlineData(@"\\")]
[InlineData(@"C:\")] [InlineData(@"C:\")]
public void DecorateCodeBuilder_DesignTimeRazorPathNormalizer_NormalizesChunkInheritanceUtilityPaths( public void DecorateCodeGenerator_DesignTimeRazorPathNormalizer_NormalizesChunkInheritanceUtilityPaths(
string rootPrefix) string rootPrefix)
{ {
// Arrange // Arrange
var rootedAppPath = $"{rootPrefix}SomeComputer/Location/Project/"; var rootedAppPath = $"{rootPrefix}SomeComputer/Location/Project/";
var rootedFilePath = $"{rootPrefix}SomeComputer/Location/Project/src/file.cshtml"; var rootedFilePath = $"{rootPrefix}SomeComputer/Location/Project/src/file.cshtml";
var host = new MvcRazorHost( var host = new MvcRazorHost(
codeTreeCache: null, ChunkTreeCache: null,
pathNormalizer: new DesignTimeRazorPathNormalizer(rootedAppPath)); pathNormalizer: new DesignTimeRazorPathNormalizer(rootedAppPath));
var chunkInheritanceUtility = new PathValidatingChunkInheritanceUtility(host); var chunkInheritanceUtility = new PathValidatingChunkInheritanceUtility(host);
var codeBuilderContext = new CodeBuilderContext( var CodeGeneratorContext = new CodeGeneratorContext(
new CodeGeneratorContext( new ChunkGeneratorContext(
host, host,
host.DefaultClassName, host.DefaultClassName,
host.DefaultNamespace, host.DefaultNamespace,
rootedFilePath, rootedFilePath,
shouldGenerateLinePragmas: true), shouldGenerateLinePragmas: true),
new ErrorSink()); new ErrorSink());
var codeBuilder = new CSharpCodeBuilder(codeBuilderContext); var codeGenerator = new CSharpCodeGenerator(CodeGeneratorContext);
host.ChunkInheritanceUtility = chunkInheritanceUtility; host.ChunkInheritanceUtility = chunkInheritanceUtility;
// Act // Act
host.DecorateCodeBuilder(codeBuilder, codeBuilderContext); host.DecorateCodeGenerator(codeGenerator, CodeGeneratorContext);
// Assert // Assert
Assert.Equal("src/file.cshtml", chunkInheritanceUtility.InheritedCodeTreePagePath, StringComparer.Ordinal); Assert.Equal("src/file.cshtml", chunkInheritanceUtility.InheritedChunkTreePagePath, StringComparer.Ordinal);
} }
[Fact] [Fact]
@ -84,7 +85,7 @@ namespace Microsoft.AspNet.Mvc.Razor
{ {
// Arrange // Arrange
var fileProvider = new TestFileProvider(); var fileProvider = new TestFileProvider();
var host = new MvcRazorHost(new DefaultCodeTreeCache(fileProvider)); var host = new MvcRazorHost(new DefaultChunkTreeCache(fileProvider));
// Act // Act
var instrumented = host.EnableInstrumentation; var instrumented = host.EnableInstrumentation;
@ -98,7 +99,7 @@ namespace Microsoft.AspNet.Mvc.Razor
{ {
// Arrange // Arrange
var fileProvider = new TestFileProvider(); var fileProvider = new TestFileProvider();
var host = new MvcRazorHost(new DefaultCodeTreeCache(fileProvider)) var host = new MvcRazorHost(new DefaultChunkTreeCache(fileProvider))
{ {
DesignTimeMode = true DesignTimeMode = true
}; };
@ -152,7 +153,7 @@ namespace Microsoft.AspNet.Mvc.Razor
{ {
// Arrange // Arrange
var fileProvider = new TestFileProvider(); var fileProvider = new TestFileProvider();
var host = new TestMvcRazorHost(new DefaultCodeTreeCache(fileProvider)); var host = new TestMvcRazorHost(new DefaultChunkTreeCache(fileProvider));
// Act and Assert // Act and Assert
RunRuntimeTest(host, scenarioName); RunRuntimeTest(host, scenarioName);
@ -163,7 +164,7 @@ namespace Microsoft.AspNet.Mvc.Razor
{ {
// Arrange // Arrange
var fileProvider = new TestFileProvider(); var fileProvider = new TestFileProvider();
var host = new MvcRazorHost(new DefaultCodeTreeCache(fileProvider)) var host = new MvcRazorHost(new DefaultChunkTreeCache(fileProvider))
{ {
DesignTimeMode = true DesignTimeMode = true
}; };
@ -183,7 +184,7 @@ namespace Microsoft.AspNet.Mvc.Razor
{ {
// Arrange // Arrange
var fileProvider = new TestFileProvider(); var fileProvider = new TestFileProvider();
var host = new MvcRazorHost(new DefaultCodeTreeCache(fileProvider)) var host = new MvcRazorHost(new DefaultChunkTreeCache(fileProvider))
{ {
DesignTimeMode = true DesignTimeMode = true
}; };
@ -204,12 +205,12 @@ namespace Microsoft.AspNet.Mvc.Razor
{ {
// Arrange // Arrange
var fileProvider = new TestFileProvider(); var fileProvider = new TestFileProvider();
var host = new MvcRazorHost(new DefaultCodeTreeCache(fileProvider)) var host = new MvcRazorHost(new DefaultChunkTreeCache(fileProvider))
{ {
DesignTimeMode = true DesignTimeMode = true
}; };
host.NamespaceImports.Clear(); host.NamespaceImports.Clear();
var expectedLineMappings = new [] var expectedLineMappings = new[]
{ {
BuildLineMapping(7, 0, 7, 222, 6, 7, 7), BuildLineMapping(7, 0, 7, 222, 6, 7, 7),
BuildLineMapping(24, 1, 8, 747, 26, 8, 20), BuildLineMapping(24, 1, 8, 747, 26, 8, 20),
@ -227,7 +228,7 @@ namespace Microsoft.AspNet.Mvc.Razor
{ {
// Arrange // Arrange
var fileProvider = new TestFileProvider(); var fileProvider = new TestFileProvider();
var host = new MvcRazorHost(new DefaultCodeTreeCache(fileProvider)) var host = new MvcRazorHost(new DefaultChunkTreeCache(fileProvider))
{ {
DesignTimeMode = true DesignTimeMode = true
}; };
@ -323,17 +324,17 @@ namespace Microsoft.AspNet.Mvc.Razor
private class PathValidatingChunkInheritanceUtility : ChunkInheritanceUtility private class PathValidatingChunkInheritanceUtility : ChunkInheritanceUtility
{ {
public PathValidatingChunkInheritanceUtility(MvcRazorHost razorHost) 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<CodeTree> GetInheritedCodeTrees([NotNull] string pagePath) public override IReadOnlyList<ChunkTree> 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
/// </summary> /// </summary>
private class TestMvcRazorHost : MvcRazorHost private class TestMvcRazorHost : MvcRazorHost
{ {
public TestMvcRazorHost(ICodeTreeCache codeTreeCache) public TestMvcRazorHost(IChunkTreeCache ChunkTreeCache)
: base(codeTreeCache) : 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, DefaultModel,
"Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute", "Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute",
new GeneratedTagHelperAttributeContext new GeneratedTagHelperAttributeContext
@ -360,11 +361,11 @@ namespace Microsoft.AspNet.Mvc.Razor
}); });
} }
protected class TestCSharpCodeBuilder : MvcCSharpCodeBuilder protected class TestCSharpCodeGenerator : MvcCSharpCodeGenerator
{ {
private readonly GeneratedTagHelperAttributeContext _tagHelperAttributeContext; private readonly GeneratedTagHelperAttributeContext _tagHelperAttributeContext;
public TestCSharpCodeBuilder(CodeBuilderContext context, public TestCSharpCodeGenerator(CodeGeneratorContext context,
string defaultModel, string defaultModel,
string activateAttribute, string activateAttribute,
GeneratedTagHelperAttributeContext tagHelperAttributeContext) GeneratedTagHelperAttributeContext tagHelperAttributeContext)
@ -373,7 +374,7 @@ namespace Microsoft.AspNet.Mvc.Razor
_tagHelperAttributeContext = tagHelperAttributeContext; _tagHelperAttributeContext = tagHelperAttributeContext;
} }
protected override CSharpCodeVisitor CreateCSharpCodeVisitor(CSharpCodeWriter writer, CodeBuilderContext context) protected override CSharpCodeVisitor CreateCSharpCodeVisitor(CSharpCodeWriter writer, CodeGeneratorContext context)
{ {
var visitor = base.CreateCSharpCodeVisitor(writer, context); var visitor = base.CreateCSharpCodeVisitor(writer, context);
visitor.TagHelperRenderer = new NoUniqueIdsTagHelperCodeRenderer(visitor, writer, context) visitor.TagHelperRenderer = new NoUniqueIdsTagHelperCodeRenderer(visitor, writer, context)
@ -388,7 +389,7 @@ namespace Microsoft.AspNet.Mvc.Razor
{ {
public NoUniqueIdsTagHelperCodeRenderer(IChunkVisitor bodyVisitor, public NoUniqueIdsTagHelperCodeRenderer(IChunkVisitor bodyVisitor,
CSharpCodeWriter writer, CSharpCodeWriter writer,
CodeBuilderContext context) CodeGeneratorContext context)
: base(bodyVisitor, writer, context) : base(bodyVisitor, writer, context)
{ } { }

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Razor; 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;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.AspNet.Razor.TagHelpers;
@ -21,21 +21,21 @@ namespace Microsoft.AspNet.Mvc.Razor
{ {
get get
{ {
// codeTrees, expectedDirectiveDescriptors // chunkTrees, expectedDirectiveDescriptors
return new TheoryData<CodeTree[], TagHelperDirectiveDescriptor[]> return new TheoryData<ChunkTree[], TagHelperDirectiveDescriptor[]>
{ {
{ {
new[] { CreateCodeTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP" }) }, new[] { CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP" }) },
new[] { CreateDirectiveDescriptor("THP", TagHelperDirectiveType.TagHelperPrefix) } new[] { CreateDirectiveDescriptor("THP", TagHelperDirectiveType.TagHelperPrefix) }
}, },
{ {
new[] { CreateCodeTree(new AddTagHelperChunk { LookupText = "ATH" }) }, new[] { CreateChunkTree(new AddTagHelperChunk { LookupText = "ATH" }) },
new[] { CreateDirectiveDescriptor("ATH", TagHelperDirectiveType.AddTagHelper) } new[] { CreateDirectiveDescriptor("ATH", TagHelperDirectiveType.AddTagHelper) }
}, },
{ {
new[] new[]
{ {
CreateCodeTree( CreateChunkTree(
new AddTagHelperChunk { LookupText = "ATH1" }, new AddTagHelperChunk { LookupText = "ATH1" },
new AddTagHelperChunk { LookupText = "ATH2" }) 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[] { CreateDirectiveDescriptor("RTH", TagHelperDirectiveType.RemoveTagHelper) }
}, },
{ {
new[] new[]
{ {
CreateCodeTree( CreateChunkTree(
new RemoveTagHelperChunk { LookupText = "RTH1" }, new RemoveTagHelperChunk { LookupText = "RTH1" },
new RemoveTagHelperChunk { LookupText = "RTH2" }) new RemoveTagHelperChunk { LookupText = "RTH2" })
}, },
@ -65,15 +65,15 @@ namespace Microsoft.AspNet.Mvc.Razor
{ {
new[] new[]
{ {
CreateCodeTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP1" }), CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP1" }),
CreateCodeTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP2" }), CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP2" }),
}, },
new[] { CreateDirectiveDescriptor("THP1", TagHelperDirectiveType.TagHelperPrefix) } new[] { CreateDirectiveDescriptor("THP1", TagHelperDirectiveType.TagHelperPrefix) }
}, },
{ {
new[] new[]
{ {
CreateCodeTree( CreateChunkTree(
new TagHelperPrefixDirectiveChunk { Prefix = "THP" }, new TagHelperPrefixDirectiveChunk { Prefix = "THP" },
new RemoveTagHelperChunk { LookupText = "RTH" }, new RemoveTagHelperChunk { LookupText = "RTH" },
new AddTagHelperChunk { LookupText = "ATH" }) new AddTagHelperChunk { LookupText = "ATH" })
@ -88,10 +88,10 @@ namespace Microsoft.AspNet.Mvc.Razor
{ {
new[] new[]
{ {
CreateCodeTree( CreateChunkTree(
new LiteralChunk { Text = "Hello world" }, new LiteralChunk { Text = "Hello world" },
new AddTagHelperChunk { LookupText = "ATH" }), new AddTagHelperChunk { LookupText = "ATH" }),
CreateCodeTree(new RemoveTagHelperChunk { LookupText = "RTH" }) CreateChunkTree(new RemoveTagHelperChunk { LookupText = "RTH" })
}, },
new[] new[]
{ {
@ -102,11 +102,11 @@ namespace Microsoft.AspNet.Mvc.Razor
{ {
new[] new[]
{ {
CreateCodeTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP" }), CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP" }),
CreateCodeTree( CreateChunkTree(
new LiteralChunk { Text = "Hello world" }, new LiteralChunk { Text = "Hello world" },
new AddTagHelperChunk { LookupText = "ATH" }), new AddTagHelperChunk { LookupText = "ATH" }),
CreateCodeTree(new RemoveTagHelperChunk { LookupText = "RTH" }) CreateChunkTree(new RemoveTagHelperChunk { LookupText = "RTH" })
}, },
new[] new[]
{ {
@ -118,10 +118,10 @@ namespace Microsoft.AspNet.Mvc.Razor
{ {
new[] new[]
{ {
CreateCodeTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP1" }), CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP1" }),
CreateCodeTree(new AddTagHelperChunk { LookupText = "ATH" }), CreateChunkTree(new AddTagHelperChunk { LookupText = "ATH" }),
CreateCodeTree(new RemoveTagHelperChunk { LookupText = "RTH" }), CreateChunkTree(new RemoveTagHelperChunk { LookupText = "RTH" }),
CreateCodeTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP2" }), CreateChunkTree(new TagHelperPrefixDirectiveChunk { Prefix = "THP2" }),
}, },
new[] new[]
{ {
@ -137,7 +137,7 @@ namespace Microsoft.AspNet.Mvc.Razor
[Theory] [Theory]
[MemberData(nameof(ViewImportsData))] [MemberData(nameof(ViewImportsData))]
public void GetTagHelperDescriptors_ReturnsExpectedDirectiveDescriptors( public void GetTagHelperDescriptors_ReturnsExpectedDirectiveDescriptors(
CodeTree[] codeTrees, ChunkTree[] chunkTrees,
TagHelperDirectiveDescriptor[] expectedDirectiveDescriptors) TagHelperDirectiveDescriptor[] expectedDirectiveDescriptors)
{ {
// Arrange // Arrange
@ -158,7 +158,7 @@ namespace Microsoft.AspNet.Mvc.Razor
new CSharpCodeParser(), new CSharpCodeParser(),
new HtmlMarkupParser(), new HtmlMarkupParser(),
tagHelperDescriptorResolver: resolver.Object); tagHelperDescriptorResolver: resolver.Object);
var parser = new TestableMvcRazorParser(baseParser, codeTrees, defaultInheritedChunks: new Chunk[0]); var parser = new TestableMvcRazorParser(baseParser, chunkTrees, defaultInheritedChunks: new Chunk[0]);
// Act // Act
parser.GetTagHelperDescriptorsPublic(block, errorSink: new ErrorSink()).ToArray(); parser.GetTagHelperDescriptorsPublic(block, errorSink: new ErrorSink()).ToArray();
@ -211,9 +211,9 @@ namespace Microsoft.AspNet.Mvc.Razor
Assert.Equal(expectedOutput, output, StringComparer.Ordinal); 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 Chunks = chunks
}; };
@ -229,9 +229,9 @@ namespace Microsoft.AspNet.Mvc.Razor
private class TestableMvcRazorParser : MvcRazorParser private class TestableMvcRazorParser : MvcRazorParser
{ {
public TestableMvcRazorParser(RazorParser parser, public TestableMvcRazorParser(RazorParser parser,
IReadOnlyList<CodeTree> codeTrees, IReadOnlyList<ChunkTree> chunkTrees,
IReadOnlyList<Chunk> defaultInheritedChunks) IReadOnlyList<Chunk> defaultInheritedChunks)
: base(parser, codeTrees, defaultInheritedChunks, typeof(ModelExpression).FullName) : base(parser, chunkTrees, defaultInheritedChunks, typeof(ModelExpression).FullName)
{ {
} }

View File

@ -2,8 +2,8 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // 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;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp; using Microsoft.AspNet.Razor.CodeGenerators;
using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.AspNet.Razor.TagHelpers;
using Xunit; using Xunit;
@ -31,13 +31,14 @@ namespace Microsoft.AspNet.Mvc.Razor
typeName: propertyType, typeName: propertyType,
isIndexer: false); isIndexer: false);
var writer = new CSharpCodeWriter(); var writer = new CSharpCodeWriter();
var generatorContext = new CodeGeneratorContext(host: null, var generatorContext = new ChunkGeneratorContext(
className: string.Empty, host: null,
rootNamespace: string.Empty, className: string.Empty,
sourceFile: string.Empty, rootNamespace: string.Empty,
shouldGenerateLinePragmas: true); sourceFile: string.Empty,
shouldGenerateLinePragmas: true);
var errorSink = new ErrorSink(); var errorSink = new ErrorSink();
var context = new CodeBuilderContext(generatorContext, errorSink); var context = new CodeGeneratorContext(generatorContext, errorSink);
// Act // Act
renderer.RenderAttributeValue(attributeDescriptor, writer, context, renderer.RenderAttributeValue(attributeDescriptor, writer, context,

View File

@ -4,8 +4,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Razor; using Microsoft.AspNet.Razor;
using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Editor; using Microsoft.AspNet.Razor.Editor;
using Microsoft.AspNet.Razor.Generator;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Tokenizer.Symbols; using Microsoft.AspNet.Razor.Tokenizer.Symbols;
@ -36,9 +36,9 @@ namespace Microsoft.AspNet.Mvc.Razor
return Builder.Build(); return Builder.Build();
} }
public SpanConstructor With(ISpanCodeGenerator generator) public SpanConstructor With(ISpanChunkGenerator generator)
{ {
Builder.CodeGenerator = generator; Builder.ChunkGenerator = generator;
return this; return this;
} }
@ -48,9 +48,9 @@ namespace Microsoft.AspNet.Mvc.Razor
return this; return this;
} }
public SpanConstructor With(Action<ISpanCodeGenerator> generatorConfigurer) public SpanConstructor With(Action<ISpanChunkGenerator> generatorConfigurer)
{ {
generatorConfigurer(Builder.CodeGenerator); generatorConfigurer(Builder.ChunkGenerator);
return this; return this;
} }
@ -67,7 +67,7 @@ namespace Microsoft.AspNet.Mvc.Razor
public SpanConstructor Hidden() public SpanConstructor Hidden()
{ {
Builder.CodeGenerator = SpanCodeGenerator.Null; Builder.ChunkGenerator = SpanChunkGenerator.Null;
return this; return this;
} }

View File

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // 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;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Text; 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); var symbol = new HtmlSymbol(self.LocationTracker.CurrentLocation, string.Empty, HtmlSymbolType.Unknown);
return self.Span(SpanKind.Markup, symbol) return self.Span(SpanKind.Markup, symbol)
.With(new MarkupCodeGenerator()); .With(new MarkupChunkGenerator());
} }
public static UnclassifiedCodeSpanConstructor Code(this SpanFactory self, string content) 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) 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) 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) public static SourceLocation GetLocationAndAdvance(this SourceLocationTracker self, string content)

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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 namespace Microsoft.AspNet.Mvc.Razor
{ {
@ -14,7 +14,7 @@ namespace Microsoft.AspNet.Mvc.Razor
_self = self; _self = self;
} }
public SpanConstructor As(ISpanCodeGenerator codeGenerator) public SpanConstructor As(ISpanChunkGenerator codeGenerator)
{ {
return _self.With(codeGenerator); return _self.With(codeGenerator);
} }

View File

@ -5,7 +5,8 @@ using System.IO;
using System.Linq; using System.Linq;
using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Razor; 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.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.Framework.OptionsModel; using Microsoft.Framework.OptionsModel;
@ -56,8 +57,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
new Block(new BlockBuilder { Type = BlockType.Comment }), new Block(new BlockBuilder { Type = BlockType.Comment }),
Enumerable.Empty<TagHelperDescriptor>(), Enumerable.Empty<TagHelperDescriptor>(),
errorSink, errorSink,
new CodeBuilderResult("", new LineMapping[0]), new CodeGeneratorResult("", new LineMapping[0]),
new CodeTree()); new ChunkTree());
var host = new Mock<IMvcRazorHost>(); var host = new Mock<IMvcRazorHost>();
host.Setup(h => h.GenerateCode(It.IsAny<string>(), It.IsAny<Stream>())) host.Setup(h => h.GenerateCode(It.IsAny<string>(), It.IsAny<Stream>()))
.Returns(generatorResult) .Returns(generatorResult)
@ -94,8 +95,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
new Block(new BlockBuilder { Type = BlockType.Comment }), new Block(new BlockBuilder { Type = BlockType.Comment }),
Enumerable.Empty<TagHelperDescriptor>(), Enumerable.Empty<TagHelperDescriptor>(),
new ErrorSink(), new ErrorSink(),
new CodeBuilderResult(code, new LineMapping[0]), new CodeGeneratorResult(code, new LineMapping[0]),
new CodeTree()); new ChunkTree());
var host = new Mock<IMvcRazorHost>(); var host = new Mock<IMvcRazorHost>();
host.Setup(h => h.GenerateCode(It.IsAny<string>(), It.IsAny<Stream>())) host.Setup(h => h.GenerateCode(It.IsAny<string>(), It.IsAny<Stream>()))
.Returns(generatorResult); .Returns(generatorResult);
@ -206,8 +207,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
new Block(new BlockBuilder { Type = BlockType.Comment }), new Block(new BlockBuilder { Type = BlockType.Comment }),
Enumerable.Empty<TagHelperDescriptor>(), Enumerable.Empty<TagHelperDescriptor>(),
new ErrorSink(), new ErrorSink(),
new CodeBuilderResult("", new LineMapping[0]), new CodeGeneratorResult("", new LineMapping[0]),
new CodeTree()); new ChunkTree());
} }
private static IOptions<RazorViewEngineOptions> GetOptions(IFileProvider fileProvider = null) private static IOptions<RazorViewEngineOptions> GetOptions(IFileProvider fileProvider = null)

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Razor; using Microsoft.AspNet.Razor;
using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Generator;
using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
@ -42,7 +43,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
factory.MetaCode("model ") factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None), .Accepts(AcceptedCharacters.None),
factory.Code(" Foo") factory.Code(" Foo")
.As(new ModelCodeGenerator(DefaultBaseType, "Foo")) .As(new ModelChunkGenerator(DefaultBaseType, "Foo"))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.EmptyHtml() factory.EmptyHtml()
}; };
@ -66,10 +67,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
factory.MetaCode("model ") factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None), .Accepts(AcceptedCharacters.None),
factory.Code("Foo?\r\n") factory.Code("Foo?\r\n")
.As(new ModelCodeGenerator(DefaultBaseType, "Foo?")) .As(new ModelChunkGenerator(DefaultBaseType, "Foo?"))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.Markup("Bar") factory.Markup("Bar")
.With(new MarkupCodeGenerator()) .With(new MarkupChunkGenerator())
}; };
Assert.Equal(expectedSpans, spans.ToArray()); Assert.Equal(expectedSpans, spans.ToArray());
} }
@ -91,10 +92,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
factory.MetaCode("model ") factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None), .Accepts(AcceptedCharacters.None),
factory.Code("Foo[[]][]\r\n") factory.Code("Foo[[]][]\r\n")
.As(new ModelCodeGenerator(DefaultBaseType, "Foo[[]][]")) .As(new ModelChunkGenerator(DefaultBaseType, "Foo[[]][]"))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.Markup("Bar") factory.Markup("Bar")
.With(new MarkupCodeGenerator()) .With(new MarkupChunkGenerator())
}; };
Assert.Equal(expectedSpans, spans.ToArray()); Assert.Equal(expectedSpans, spans.ToArray());
} }
@ -116,7 +117,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
factory.MetaCode("model ") factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None), .Accepts(AcceptedCharacters.None),
factory.Code("$rootnamespace$.MyModel") factory.Code("$rootnamespace$.MyModel")
.As(new ModelCodeGenerator(DefaultBaseType, "$rootnamespace$.MyModel")) .As(new ModelChunkGenerator(DefaultBaseType, "$rootnamespace$.MyModel"))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.EmptyHtml() factory.EmptyHtml()
}; };
@ -141,7 +142,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
factory.MetaCode("model ") factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None), .Accepts(AcceptedCharacters.None),
factory.Code(" ") factory.Code(" ")
.As(new ModelCodeGenerator(DefaultBaseType, string.Empty)) .As(new ModelChunkGenerator(DefaultBaseType, string.Empty))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.EmptyHtml() factory.EmptyHtml()
}; };
@ -173,7 +174,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
factory.MetaCode("model ") factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None), .Accepts(AcceptedCharacters.None),
factory.Code("Foo\r\n") factory.Code("Foo\r\n")
.As(new ModelCodeGenerator(DefaultBaseType, "Foo")) .As(new ModelChunkGenerator(DefaultBaseType, "Foo"))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.EmptyHtml(), factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString) factory.CodeTransition(SyntaxConstants.TransitionString)
@ -181,7 +182,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
factory.MetaCode("model ") factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None), .Accepts(AcceptedCharacters.None),
factory.Code("Bar") factory.Code("Bar")
.As(new ModelCodeGenerator(DefaultBaseType, "Bar")) .As(new ModelChunkGenerator(DefaultBaseType, "Bar"))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.EmptyHtml() factory.EmptyHtml()
}; };
@ -215,7 +216,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
factory.MetaCode("model ") factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None), .Accepts(AcceptedCharacters.None),
factory.Code("Foo\r\n") factory.Code("Foo\r\n")
.As(new ModelCodeGenerator(DefaultBaseType, "Foo")) .As(new ModelChunkGenerator(DefaultBaseType, "Foo"))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.EmptyHtml(), factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString) factory.CodeTransition(SyntaxConstants.TransitionString)
@ -223,7 +224,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
factory.MetaCode("inherits ") factory.MetaCode("inherits ")
.Accepts(AcceptedCharacters.None), .Accepts(AcceptedCharacters.None),
factory.Code("Bar") factory.Code("Bar")
.As(new SetBaseTypeCodeGenerator("Bar")) .As(new SetBaseTypeChunkGenerator("Bar"))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.EmptyHtml() factory.EmptyHtml()
}; };
@ -257,7 +258,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
factory.MetaCode("inherits ") factory.MetaCode("inherits ")
.Accepts(AcceptedCharacters.None), .Accepts(AcceptedCharacters.None),
factory.Code("Bar" + Environment.NewLine) factory.Code("Bar" + Environment.NewLine)
.As(new SetBaseTypeCodeGenerator("Bar")) .As(new SetBaseTypeChunkGenerator("Bar"))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.EmptyHtml(), factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString) factory.CodeTransition(SyntaxConstants.TransitionString)
@ -265,7 +266,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
factory.MetaCode("model ") factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None), .Accepts(AcceptedCharacters.None),
factory.Code("Foo") factory.Code("Foo")
.As(new ModelCodeGenerator(DefaultBaseType, "Foo")) .As(new ModelChunkGenerator(DefaultBaseType, "Foo"))
.Accepts(AcceptedCharacters.AnyExceptNewline), .Accepts(AcceptedCharacters.AnyExceptNewline),
factory.EmptyHtml() factory.EmptyHtml()
}; };

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Razor; using Microsoft.AspNet.Razor;
using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Editor; using Microsoft.AspNet.Razor.Editor;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Generator;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
@ -20,7 +21,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
public static SpanConstructor EmptyHtml(this SpanFactory self) public static SpanConstructor EmptyHtml(this SpanFactory self)
{ {
return self.Span(SpanKind.Markup, new HtmlSymbol(self.LocationTracker.CurrentLocation, String.Empty, HtmlSymbolType.Unknown)) 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) 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) 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; _self = self;
} }
public SpanConstructor As(ISpanCodeGenerator codeGenerator) public SpanConstructor As(ISpanChunkGenerator codeGenerator)
{ {
return _self.With(codeGenerator); return _self.With(codeGenerator);
} }
@ -160,9 +161,9 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Test
return Builder.Build(); return Builder.Build();
} }
public SpanConstructor With(ISpanCodeGenerator generator) public SpanConstructor With(ISpanChunkGenerator generator)
{ {
Builder.CodeGenerator = generator; Builder.ChunkGenerator = generator;
return this; return this;
} }