Renamed and moved several Razor classes for clarity.

- Renamed CodeGenerators to ChunkGenerators.
- Updated location of TestFiles from TestFiles/CodeGenerator/CS/{Output|Source} => TestFiles/CodeGenerator/{Output|Source}.
- Removed ChunkTree test; it was a legacy test used to experiment with Razor rendering (not a real test).
- Removed CSharpRazorCodeGenerator; it's now replaced with RazorCodeGenerator. It was an empty class that did nothing.
- Updated ChunkBlock => ParentChunk. Also updated several patterns throughout the code base that referenced these blocks as blocks and not parents.
- Moved Chunks and ChunkGenerators into the Chunks/Chunks.Generators namespace/folder structure. Updated test project to reflect the same.
- Moved CodeBuilders and CodeVisitors to the CodeGeneration/CodeGeneration.Visitors namespace/folder structure. Updated test project to reflect the same.
- Moved several TagHelper assets outside of their own namespaces and into Razors more general structures; such as CodeGeneration and Chunks/Chunks.Generators.

#140
This commit is contained in:
N. Taylor Mullen 2015-05-21 16:39:17 -07:00
parent b33bff1866
commit 5df9b52afe
279 changed files with 1569 additions and 1622 deletions

View File

@ -1,9 +1,8 @@
// 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;
using Microsoft.AspNet.Razor.Generator.Compiler; using Microsoft.AspNet.Razor.CodeGeneration;
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser;
#if NET45 #if NET45
@ -35,11 +34,11 @@ namespace Microsoft.AspNet.Razor
} }
/// <summary> /// <summary>
/// Constructs a new instance of the code generator for this language with the specified settings /// Constructs a new instance of the chunk generator for this language with the specified settings
/// </summary> /// </summary>
public override RazorCodeGenerator CreateCodeGenerator(string className, string rootNamespaceName, string sourceFileName, RazorEngineHost host) public override RazorChunkGenerator CreateChunkGenerator(string className, string rootNamespaceName, string sourceFileName, RazorEngineHost host)
{ {
return new CSharpRazorCodeGenerator(className, rootNamespaceName, sourceFileName, host); return new RazorChunkGenerator(className, rootNamespaceName, sourceFileName, host);
} }
public override CodeBuilder CreateCodeBuilder(CodeBuilderContext context) public override CodeBuilder CreateCodeBuilder(CodeBuilderContext context)

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.
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
/// <summary> /// <summary>
/// A <see cref="Chunk"/> used to look up <see cref="TagHelpers.TagHelperDescriptor"/>s. /// A <see cref="Chunk"/> used to look up <see cref="TagHelpers.TagHelperDescriptor"/>s.

View File

@ -3,7 +3,7 @@
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
public class Chunk public class Chunk
{ {

View File

@ -3,11 +3,11 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
public class CodeTree public class ChunkTree
{ {
public CodeTree() public ChunkTree()
{ {
Chunks = new List<Chunk>(); Chunks = new List<Chunk>();
} }

View File

@ -4,20 +4,20 @@
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
public class CodeTreeBuilder public class ChunkTreeBuilder
{ {
private readonly Stack<ChunkBlock> _blockChain; private readonly Stack<ParentChunk> _parentChain;
private Chunk _lastChunk; private Chunk _lastChunk;
public CodeTreeBuilder() public ChunkTreeBuilder()
{ {
CodeTree = new CodeTree(); ChunkTree = new ChunkTree();
_blockChain = new Stack<ChunkBlock>(); _parentChain = new Stack<ParentChunk>();
} }
public CodeTree CodeTree { get; private set; } public ChunkTree ChunkTree { get; private set; }
public void AddChunk(Chunk chunk, SyntaxTreeNode association, bool topLevel = false) public void AddChunk(Chunk chunk, SyntaxTreeNode association, bool topLevel = false)
{ {
@ -27,13 +27,13 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
chunk.Association = association; chunk.Association = association;
// If we're not in the middle of a chunk block // If we're not in the middle of a chunk block
if (_blockChain.Count == 0 || topLevel == true) if (_parentChain.Count == 0 || topLevel == true)
{ {
CodeTree.Chunks.Add(chunk); ChunkTree.Chunks.Add(chunk);
} }
else else
{ {
_blockChain.Peek().Children.Add(chunk); _parentChain.Peek().Children.Add(chunk);
} }
} }
@ -148,30 +148,30 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
}, association, topLevel: true); }, association, topLevel: true);
} }
public T StartChunkBlock<T>(SyntaxTreeNode association) where T : ChunkBlock, new() public T StartParentChunk<T>(SyntaxTreeNode association) where T : ParentChunk, new()
{ {
return StartChunkBlock<T>(association, topLevel: false); return StartParentChunk<T>(association, topLevel: false);
} }
public T StartChunkBlock<T>(SyntaxTreeNode association, bool topLevel) where T : ChunkBlock, new() public T StartParentChunk<T>(SyntaxTreeNode association, bool topLevel) where T : ParentChunk, new()
{ {
var chunkBlock = new T(); var parentChunk = new T();
return StartChunkBlock<T>(chunkBlock, association, topLevel); return StartParentChunk<T>(parentChunk, association, topLevel);
} }
public T StartChunkBlock<T>(T chunkBlock, SyntaxTreeNode association, bool topLevel) where T : ChunkBlock public T StartParentChunk<T>(T parentChunk, SyntaxTreeNode association, bool topLevel) where T : ParentChunk
{ {
AddChunk(chunkBlock, association, topLevel); AddChunk(parentChunk, association, topLevel);
_blockChain.Push(chunkBlock); _parentChain.Push(parentChunk);
return chunkBlock; return parentChunk;
} }
public void EndChunkBlock() public void EndParentChunk()
{ {
_lastChunk = _blockChain.Pop(); _lastChunk = _parentChain.Pop();
} }
} }
} }

View File

@ -3,9 +3,9 @@
using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Text;
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
public class CodeAttributeChunk : ChunkBlock public class CodeAttributeChunk : ParentChunk
{ {
public string Attribute { get; set; } public string Attribute { get; set; }
public LocationTagged<string> Prefix { get; set; } public LocationTagged<string> Prefix { get; set; }

View File

@ -3,9 +3,9 @@
using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Text;
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
public class DynamicCodeAttributeChunk : ChunkBlock public class DynamicCodeAttributeChunk : ParentChunk
{ {
public LocationTagged<string> Prefix { get; set; } public LocationTagged<string> Prefix { get; set; }
} }

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.
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
public class ExpressionBlockChunk : ChunkBlock public class ExpressionBlockChunk : ParentChunk
{ {
} }
} }

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.
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
public class ExpressionChunk : Chunk public class ExpressionChunk : Chunk
{ {

View File

@ -4,18 +4,18 @@
using System; using System;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.Chunks.Generators
{ {
public class AddImportCodeGenerator : SpanCodeGenerator public class AddImportChunkGenerator : SpanChunkGenerator
{ {
public AddImportCodeGenerator(string ns) public AddImportChunkGenerator(string ns)
{ {
Namespace = ns; Namespace = ns;
} }
public string Namespace { get; } public string Namespace { get; }
public override void GenerateCode(Span target, CodeGeneratorContext context) public override void GenerateChunk(Span target, ChunkGeneratorContext context)
{ {
var ns = Namespace; var ns = Namespace;
@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Razor.Generator
ns = ns.Substring(1); ns = ns.Substring(1);
} }
context.CodeTreeBuilder.AddUsingChunk(ns, target); context.ChunkTreeBuilder.AddUsingChunk(ns, target);
} }
public override string ToString() public override string ToString()
@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Razor.Generator
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
var other = obj as AddImportCodeGenerator; var other = obj as AddImportChunkGenerator;
return other != null && return other != null &&
string.Equals(Namespace, other.Namespace, StringComparison.Ordinal); string.Equals(Namespace, other.Namespace, StringComparison.Ordinal);
} }

View File

@ -3,21 +3,21 @@
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.Chunks.Generators
{ {
/// <summary> /// <summary>
/// A <see cref="SpanCodeGenerator"/> responsible for generating <see cref="Compiler.AddTagHelperChunk"/>s and /// A <see cref="SpanChunkGenerator"/> responsible for generating <see cref="AddTagHelperChunk"/>s and
/// <see cref="Compiler.RemoveTagHelperChunk"/>s. /// <see cref="RemoveTagHelperChunk"/>s.
/// </summary> /// </summary>
public class AddOrRemoveTagHelperCodeGenerator : SpanCodeGenerator public class AddOrRemoveTagHelperChunkGenerator : SpanChunkGenerator
{ {
/// <summary> /// <summary>
/// Instantiates a new <see cref="AddOrRemoveTagHelperCodeGenerator"/>. /// Instantiates a new <see cref="AddOrRemoveTagHelperChunkGenerator"/>.
/// </summary> /// </summary>
/// <param name="lookupText"> /// <param name="lookupText">
/// Text used to look up <see cref="TagHelpers.TagHelperDescriptor"/>s that should be added or removed. /// Text used to look up <see cref="TagHelpers.TagHelperDescriptor"/>s that should be added or removed.
/// </param> /// </param>
public AddOrRemoveTagHelperCodeGenerator(bool removeTagHelperDescriptors, string lookupText) public AddOrRemoveTagHelperChunkGenerator(bool removeTagHelperDescriptors, string lookupText)
{ {
RemoveTagHelperDescriptors = removeTagHelperDescriptors; RemoveTagHelperDescriptors = removeTagHelperDescriptors;
LookupText = lookupText; LookupText = lookupText;
@ -32,28 +32,28 @@ namespace Microsoft.AspNet.Razor.Generator
/// <summary> /// <summary>
/// Whether we want to remove <see cref="TagHelpers.TagHelperDescriptor"/>s from the Razor page. /// Whether we want to remove <see cref="TagHelpers.TagHelperDescriptor"/>s from the Razor page.
/// </summary> /// </summary>
/// <remarks>If <c>true</c> <see cref="GenerateCode"/> generates <see cref="Compiler.AddTagHelperChunk"/>s, /// <remarks>If <c>true</c> <see cref="GenerateChunk"/> generates <see cref="AddTagHelperChunk"/>s,
/// <see cref="Compiler.RemoveTagHelperChunk"/>s otherwise.</remarks> /// <see cref="RemoveTagHelperChunk"/>s otherwise.</remarks>
public bool RemoveTagHelperDescriptors { get; } public bool RemoveTagHelperDescriptors { get; }
/// <summary> /// <summary>
/// Generates <see cref="Compiler.AddTagHelperChunk"/>s if <see cref="RemoveTagHelperDescriptors"/> is /// Generates <see cref="AddTagHelperChunk"/>s if <see cref="RemoveTagHelperDescriptors"/> is
/// <c>true</c>, otherwise <see cref="Compiler.RemoveTagHelperChunk"/>s are generated. /// <c>true</c>, otherwise <see cref="RemoveTagHelperChunk"/>s are generated.
/// </summary> /// </summary>
/// <param name="target"> /// <param name="target">
/// The <see cref="Span"/> responsible for this <see cref="AddOrRemoveTagHelperCodeGenerator"/>. /// The <see cref="Span"/> responsible for this <see cref="AddOrRemoveTagHelperChunkGenerator"/>.
/// </param> /// </param>
/// <param name="context">A <see cref="CodeGeneratorContext"/> instance that contains information about /// <param name="context">A <see cref="ChunkGeneratorContext"/> instance that contains information about
/// the current code generation process.</param> /// the current chunk generation process.</param>
public override void GenerateCode(Span target, CodeGeneratorContext context) public override void GenerateChunk(Span target, ChunkGeneratorContext context)
{ {
if (RemoveTagHelperDescriptors) if (RemoveTagHelperDescriptors)
{ {
context.CodeTreeBuilder.AddRemoveTagHelperChunk(LookupText, target); context.ChunkTreeBuilder.AddRemoveTagHelperChunk(LookupText, target);
} }
else else
{ {
context.CodeTreeBuilder.AddAddTagHelperChunk(LookupText, target); context.ChunkTreeBuilder.AddAddTagHelperChunk(LookupText, target);
} }
} }
} }

View File

@ -3,16 +3,15 @@
using System; using System;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Razor.Generator.Compiler;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Text;
using Microsoft.Internal.Web.Utils; using Microsoft.Internal.Web.Utils;
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.Chunks.Generators
{ {
public class AttributeBlockCodeGenerator : BlockCodeGenerator public class AttributeBlockChunkGenerator : ParentChunkGenerator
{ {
public AttributeBlockCodeGenerator(string name, LocationTagged<string> prefix, LocationTagged<string> suffix) public AttributeBlockChunkGenerator(string name, LocationTagged<string> prefix, LocationTagged<string> suffix)
{ {
Name = name; Name = name;
Prefix = prefix; Prefix = prefix;
@ -25,18 +24,18 @@ namespace Microsoft.AspNet.Razor.Generator
public LocationTagged<string> Suffix { get; } public LocationTagged<string> Suffix { get; }
public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context) public override void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
{ {
var chunk = context.CodeTreeBuilder.StartChunkBlock<CodeAttributeChunk>(target); var chunk = context.ChunkTreeBuilder.StartParentChunk<CodeAttributeChunk>(target);
chunk.Attribute = Name; chunk.Attribute = Name;
chunk.Prefix = Prefix; chunk.Prefix = Prefix;
chunk.Suffix = Suffix; chunk.Suffix = Suffix;
} }
public override void GenerateEndBlockCode(Block target, CodeGeneratorContext context) public override void GenerateEndParentChunk(Block target, ChunkGeneratorContext context)
{ {
context.CodeTreeBuilder.EndChunkBlock(); context.ChunkTreeBuilder.EndParentChunk();
} }
public override string ToString() public override string ToString()
@ -46,7 +45,7 @@ namespace Microsoft.AspNet.Razor.Generator
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
var other = obj as AttributeBlockCodeGenerator; var other = obj as AttributeBlockChunkGenerator;
return other != null && return other != null &&
string.Equals(other.Name, Name, StringComparison.Ordinal) && string.Equals(other.Name, Name, StringComparison.Ordinal) &&
Equals(other.Prefix, Prefix) && Equals(other.Prefix, Prefix) &&

View File

@ -0,0 +1,44 @@
// 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.
namespace Microsoft.AspNet.Razor.Chunks.Generators
{
public class ChunkGeneratorContext
{
protected ChunkGeneratorContext(ChunkGeneratorContext context)
: this(
context.Host,
context.ClassName,
context.RootNamespace,
context.SourceFile,
// True because we're pulling from the provided context's source file.
shouldGenerateLinePragmas: true)
{
ChunkTreeBuilder = context.ChunkTreeBuilder;
}
public ChunkGeneratorContext(
RazorEngineHost host,
string className,
string rootNamespace,
string sourceFile,
bool shouldGenerateLinePragmas)
{
ChunkTreeBuilder = new ChunkTreeBuilder();
Host = host;
SourceFile = shouldGenerateLinePragmas ? sourceFile : null;
RootNamespace = rootNamespace;
ClassName = className;
}
public string SourceFile { get; internal set; }
public string RootNamespace { get; private set; }
public string ClassName { get; private set; }
public RazorEngineHost Host { get; private set; }
public ChunkTreeBuilder ChunkTreeBuilder { get; set; }
}
}

View File

@ -2,20 +2,19 @@
// 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.Globalization; using System.Globalization;
using Microsoft.AspNet.Razor.Generator.Compiler;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Text;
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.Chunks.Generators
{ {
public class DynamicAttributeBlockCodeGenerator : BlockCodeGenerator public class DynamicAttributeBlockChunkGenerator : ParentChunkGenerator
{ {
public DynamicAttributeBlockCodeGenerator(LocationTagged<string> prefix, int offset, int line, int col) public DynamicAttributeBlockChunkGenerator(LocationTagged<string> prefix, int offset, int line, int col)
: this(prefix, new SourceLocation(offset, line, col)) : this(prefix, new SourceLocation(offset, line, col))
{ {
} }
public DynamicAttributeBlockCodeGenerator(LocationTagged<string> prefix, SourceLocation valueStart) public DynamicAttributeBlockChunkGenerator(LocationTagged<string> prefix, SourceLocation valueStart)
{ {
Prefix = prefix; Prefix = prefix;
ValueStart = valueStart; ValueStart = valueStart;
@ -25,16 +24,16 @@ namespace Microsoft.AspNet.Razor.Generator
public SourceLocation ValueStart { get; } public SourceLocation ValueStart { get; }
public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context) public override void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
{ {
var chunk = context.CodeTreeBuilder.StartChunkBlock<DynamicCodeAttributeChunk>(target); var chunk = context.ChunkTreeBuilder.StartParentChunk<DynamicCodeAttributeChunk>(target);
chunk.Start = ValueStart; chunk.Start = ValueStart;
chunk.Prefix = Prefix; chunk.Prefix = Prefix;
} }
public override void GenerateEndBlockCode(Block target, CodeGeneratorContext context) public override void GenerateEndParentChunk(Block target, ChunkGeneratorContext context)
{ {
context.CodeTreeBuilder.EndChunkBlock(); context.ChunkTreeBuilder.EndParentChunk();
} }
public override string ToString() public override string ToString()
@ -44,7 +43,7 @@ namespace Microsoft.AspNet.Razor.Generator
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
var other = obj as DynamicAttributeBlockCodeGenerator; var other = obj as DynamicAttributeBlockChunkGenerator;
return other != null && return other != null &&
Equals(other.Prefix, Prefix); Equals(other.Prefix, Prefix);
} }

View File

@ -1,28 +1,27 @@
// 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.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.Chunks.Generators
{ {
public class ExpressionCodeGenerator : HybridCodeGenerator public class ExpressionChunkGenerator : HybridChunkGenerator
{ {
private static readonly int TypeHashCode = typeof(ExpressionCodeGenerator).GetHashCode(); private static readonly int TypeHashCode = typeof(ExpressionChunkGenerator).GetHashCode();
public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context) public override void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
{ {
context.CodeTreeBuilder.StartChunkBlock<ExpressionBlockChunk>(target); context.ChunkTreeBuilder.StartParentChunk<ExpressionBlockChunk>(target);
} }
public override void GenerateCode(Span target, CodeGeneratorContext context) public override void GenerateChunk(Span target, ChunkGeneratorContext context)
{ {
context.CodeTreeBuilder.AddExpressionChunk(target.Content, target); context.ChunkTreeBuilder.AddExpressionChunk(target.Content, target);
} }
public override void GenerateEndBlockCode(Block target, CodeGeneratorContext context) public override void GenerateEndParentChunk(Block target, ChunkGeneratorContext context)
{ {
context.CodeTreeBuilder.EndChunkBlock(); context.ChunkTreeBuilder.EndParentChunk();
} }
public override string ToString() public override string ToString()

View File

@ -0,0 +1,22 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Chunks.Generators
{
public abstract class HybridChunkGenerator : ISpanChunkGenerator, IParentChunkGenerator
{
public virtual void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
{
}
public virtual void GenerateEndParentChunk(Block target, ChunkGeneratorContext context)
{
}
public virtual void GenerateChunk(Span target, ChunkGeneratorContext context)
{
}
}
}

View File

@ -0,0 +1,13 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Chunks.Generators
{
public interface IParentChunkGenerator
{
void GenerateStartParentChunk(Block target, ChunkGeneratorContext context);
void GenerateEndParentChunk(Block target, ChunkGeneratorContext context);
}
}

View File

@ -3,10 +3,10 @@
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.Chunks.Generators
{ {
public interface ISpanCodeGenerator public interface ISpanChunkGenerator
{ {
void GenerateCode(Span target, CodeGeneratorContext context); void GenerateChunk(Span target, ChunkGeneratorContext context);
} }
} }

View File

@ -2,22 +2,21 @@
// 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.Globalization; using System.Globalization;
using Microsoft.AspNet.Razor.Generator.Compiler;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Text;
using Microsoft.Internal.Web.Utils; using Microsoft.Internal.Web.Utils;
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.Chunks.Generators
{ {
public class LiteralAttributeCodeGenerator : SpanCodeGenerator public class LiteralAttributeChunkGenerator : SpanChunkGenerator
{ {
public LiteralAttributeCodeGenerator(LocationTagged<string> prefix, LocationTagged<SpanCodeGenerator> valueGenerator) public LiteralAttributeChunkGenerator(LocationTagged<string> prefix, LocationTagged<SpanChunkGenerator> valueGenerator)
{ {
Prefix = prefix; Prefix = prefix;
ValueGenerator = valueGenerator; ValueGenerator = valueGenerator;
} }
public LiteralAttributeCodeGenerator(LocationTagged<string> prefix, LocationTagged<string> value) public LiteralAttributeChunkGenerator(LocationTagged<string> prefix, LocationTagged<string> value)
{ {
Prefix = prefix; Prefix = prefix;
Value = value; Value = value;
@ -27,11 +26,11 @@ namespace Microsoft.AspNet.Razor.Generator
public LocationTagged<string> Value { get; } public LocationTagged<string> Value { get; }
public LocationTagged<SpanCodeGenerator> ValueGenerator { get; } public LocationTagged<SpanChunkGenerator> ValueGenerator { get; }
public override void GenerateCode(Span target, CodeGeneratorContext context) public override void GenerateChunk(Span target, ChunkGeneratorContext context)
{ {
var chunk = context.CodeTreeBuilder.StartChunkBlock<LiteralCodeAttributeChunk>(target); var chunk = context.ChunkTreeBuilder.StartParentChunk<LiteralCodeAttributeChunk>(target);
chunk.Prefix = Prefix; chunk.Prefix = Prefix;
chunk.Value = Value; chunk.Value = Value;
@ -39,12 +38,12 @@ namespace Microsoft.AspNet.Razor.Generator
{ {
chunk.ValueLocation = ValueGenerator.Location; chunk.ValueLocation = ValueGenerator.Location;
ValueGenerator.Value.GenerateCode(target, context); ValueGenerator.Value.GenerateChunk(target, context);
chunk.ValueLocation = ValueGenerator.Location; chunk.ValueLocation = ValueGenerator.Location;
} }
context.CodeTreeBuilder.EndChunkBlock(); context.ChunkTreeBuilder.EndParentChunk();
} }
public override string ToString() public override string ToString()
@ -61,7 +60,7 @@ namespace Microsoft.AspNet.Razor.Generator
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
var other = obj as LiteralAttributeCodeGenerator; var other = obj as LiteralAttributeChunkGenerator;
return other != null && return other != null &&
Equals(other.Prefix, Prefix) && Equals(other.Prefix, Prefix) &&
Equals(other.Value, Value) && Equals(other.Value, Value) &&

View File

@ -3,13 +3,13 @@
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.Chunks.Generators
{ {
public class MarkupCodeGenerator : SpanCodeGenerator public class MarkupChunkGenerator : SpanChunkGenerator
{ {
public override void GenerateCode(Span target, CodeGeneratorContext context) public override void GenerateChunk(Span target, ChunkGeneratorContext context)
{ {
context.CodeTreeBuilder.AddLiteralChunk(target.Content, target); context.ChunkTreeBuilder.AddLiteralChunk(target.Content, target);
} }
public override string ToString() public override string ToString()

View File

@ -4,20 +4,20 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.Chunks.Generators
{ {
public abstract class BlockCodeGenerator : IBlockCodeGenerator public abstract class ParentChunkGenerator : IParentChunkGenerator
{ {
private static readonly int TypeHashCode = typeof(BlockCodeGenerator).GetHashCode(); private static readonly int TypeHashCode = typeof(ParentChunkGenerator).GetHashCode();
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "This class has no instance state")] [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "This class has no instance state")]
public static readonly IBlockCodeGenerator Null = new NullBlockCodeGenerator(); public static readonly IParentChunkGenerator Null = new NullParentChunkGenerator();
public virtual void GenerateStartBlockCode(Block target, CodeGeneratorContext context) public virtual void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
{ {
} }
public virtual void GenerateEndBlockCode(Block target, CodeGeneratorContext context) public virtual void GenerateEndParentChunk(Block target, ChunkGeneratorContext context)
{ {
} }
@ -32,13 +32,13 @@ namespace Microsoft.AspNet.Razor.Generator
return TypeHashCode; return TypeHashCode;
} }
private class NullBlockCodeGenerator : IBlockCodeGenerator private class NullParentChunkGenerator : IParentChunkGenerator
{ {
public void GenerateStartBlockCode(Block target, CodeGeneratorContext context) public void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
{ {
} }
public void GenerateEndBlockCode(Block target, CodeGeneratorContext context) public void GenerateEndParentChunk(Block target, ChunkGeneratorContext context)
{ {
} }

View File

@ -6,13 +6,13 @@ using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.Chunks.Generators
{ {
public abstract class RazorCodeGenerator : ParserVisitor public class RazorChunkGenerator : ParserVisitor
{ {
private CodeGeneratorContext _context; private ChunkGeneratorContext _context;
protected RazorCodeGenerator( public RazorChunkGenerator(
string className, string className,
[NotNull] string rootNamespaceName, [NotNull] string rootNamespaceName,
string sourceFileName, string sourceFileName,
@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Razor.Generator
public bool GenerateLinePragmas { get; set; } public bool GenerateLinePragmas { get; set; }
public bool DesignTimeMode { get; set; } public bool DesignTimeMode { get; set; }
public CodeGeneratorContext Context public ChunkGeneratorContext Context
{ {
get get
{ {
@ -51,24 +51,24 @@ namespace Microsoft.AspNet.Razor.Generator
public override void VisitStartBlock(Block block) public override void VisitStartBlock(Block block)
{ {
block.CodeGenerator.GenerateStartBlockCode(block, Context); block.ChunkGenerator.GenerateStartParentChunk(block, Context);
} }
public override void VisitEndBlock(Block block) public override void VisitEndBlock(Block block)
{ {
block.CodeGenerator.GenerateEndBlockCode(block, Context); block.ChunkGenerator.GenerateEndParentChunk(block, Context);
} }
public override void VisitSpan(Span span) public override void VisitSpan(Span span)
{ {
span.CodeGenerator.GenerateCode(span, Context); span.ChunkGenerator.GenerateChunk(span, Context);
} }
private void EnsureContextInitialized() private void EnsureContextInitialized()
{ {
if (_context == null) if (_context == null)
{ {
_context = new CodeGeneratorContext(Host, _context = new ChunkGeneratorContext(Host,
ClassName, ClassName,
RootNamespaceName, RootNamespaceName,
SourceFileName, SourceFileName,
@ -77,7 +77,7 @@ namespace Microsoft.AspNet.Razor.Generator
} }
} }
protected virtual void Initialize(CodeGeneratorContext context) protected virtual void Initialize(ChunkGeneratorContext context)
{ {
} }
} }

View File

@ -2,9 +2,9 @@
// 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.
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.Chunks.Generators
{ {
public class RazorCommentCodeGenerator : BlockCodeGenerator public class RazorCommentChunkGenerator : ParentChunkGenerator
{ {
} }
} }

View File

@ -3,21 +3,21 @@
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.Chunks.Generators
{ {
public class ResolveUrlCodeGenerator : SpanCodeGenerator public class ResolveUrlChunkGenerator : SpanChunkGenerator
{ {
public override void GenerateCode(Span target, CodeGeneratorContext context) public override void GenerateChunk(Span target, ChunkGeneratorContext context)
{ {
// Check if the host supports it // Check if the host supports it
if (string.IsNullOrEmpty(context.Host.GeneratedClassContext.ResolveUrlMethodName)) if (string.IsNullOrEmpty(context.Host.GeneratedClassContext.ResolveUrlMethodName))
{ {
// Nope, just use the default MarkupCodeGenerator behavior // Nope, just use the default MarkupChunkGenerator behavior
new MarkupCodeGenerator().GenerateCode(target, context); new MarkupChunkGenerator().GenerateChunk(target, context);
return; return;
} }
context.CodeTreeBuilder.AddResolveUrlChunk(target.Content, target); context.ChunkTreeBuilder.AddResolveUrlChunk(target.Content, target);
} }
public override string ToString() public override string ToString()

View File

@ -2,35 +2,34 @@
// 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.Compiler;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.Chunks.Generators
{ {
public class SectionCodeGenerator : BlockCodeGenerator public class SectionChunkGenerator : ParentChunkGenerator
{ {
public SectionCodeGenerator(string sectionName) public SectionChunkGenerator(string sectionName)
{ {
SectionName = sectionName; SectionName = sectionName;
} }
public string SectionName { get; } public string SectionName { get; }
public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context) public override void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
{ {
var chunk = context.CodeTreeBuilder.StartChunkBlock<SectionChunk>(target); var chunk = context.ChunkTreeBuilder.StartParentChunk<SectionChunk>(target);
chunk.Name = SectionName; chunk.Name = SectionName;
} }
public override void GenerateEndBlockCode(Block target, CodeGeneratorContext context) public override void GenerateEndParentChunk(Block target, ChunkGeneratorContext context)
{ {
context.CodeTreeBuilder.EndChunkBlock(); context.ChunkTreeBuilder.EndParentChunk();
} }
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
var other = obj as SectionCodeGenerator; var other = obj as SectionChunkGenerator;
return base.Equals(other) && return base.Equals(other) &&
string.Equals(SectionName, other.SectionName, StringComparison.Ordinal); string.Equals(SectionName, other.SectionName, StringComparison.Ordinal);
} }

View File

@ -4,20 +4,20 @@
using System; using System;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.Chunks.Generators
{ {
public class SetBaseTypeCodeGenerator : SpanCodeGenerator public class SetBaseTypeChunkGenerator : SpanChunkGenerator
{ {
public SetBaseTypeCodeGenerator(string baseType) public SetBaseTypeChunkGenerator(string baseType)
{ {
BaseType = baseType; BaseType = baseType;
} }
public string BaseType { get; } public string BaseType { get; }
public override void GenerateCode(Span target, CodeGeneratorContext context) public override void GenerateChunk(Span target, ChunkGeneratorContext context)
{ {
context.CodeTreeBuilder.AddSetBaseTypeChunk(BaseType, target); context.ChunkTreeBuilder.AddSetBaseTypeChunk(BaseType, target);
} }
public override string ToString() public override string ToString()
@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Razor.Generator
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
var other = obj as SetBaseTypeCodeGenerator; var other = obj as SetBaseTypeChunkGenerator;
return other != null && return other != null &&
string.Equals(BaseType, other.BaseType, StringComparison.Ordinal); string.Equals(BaseType, other.BaseType, StringComparison.Ordinal);
} }

View File

@ -4,16 +4,16 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.Chunks.Generators
{ {
public abstract class SpanCodeGenerator : ISpanCodeGenerator public abstract class SpanChunkGenerator : ISpanChunkGenerator
{ {
private static readonly int TypeHashCode = typeof(SpanCodeGenerator).GetHashCode(); private static readonly int TypeHashCode = typeof(SpanChunkGenerator).GetHashCode();
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "This class has no instance state")] [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "This class has no instance state")]
public static readonly ISpanCodeGenerator Null = new NullSpanCodeGenerator(); public static readonly ISpanChunkGenerator Null = new NullSpanChunkGenerator();
public virtual void GenerateCode(Span target, CodeGeneratorContext context) public virtual void GenerateChunk(Span target, ChunkGeneratorContext context)
{ {
} }
@ -28,9 +28,9 @@ namespace Microsoft.AspNet.Razor.Generator
return TypeHashCode; return TypeHashCode;
} }
private class NullSpanCodeGenerator : ISpanCodeGenerator private class NullSpanChunkGenerator : ISpanChunkGenerator
{ {
public void GenerateCode(Span target, CodeGeneratorContext context) public void GenerateChunk(Span target, ChunkGeneratorContext context)
{ {
} }

View File

@ -3,13 +3,13 @@
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.Chunks.Generators
{ {
public class StatementCodeGenerator : SpanCodeGenerator public class StatementChunkGenerator : SpanChunkGenerator
{ {
public override void GenerateCode(Span target, CodeGeneratorContext context) public override void GenerateChunk(Span target, ChunkGeneratorContext context)
{ {
context.CodeTreeBuilder.AddStatementChunk(target.Content, target); context.ChunkTreeBuilder.AddStatementChunk(target.Content, target);
} }
public override string ToString() public override string ToString()

View File

@ -4,27 +4,26 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Razor.Generator.Compiler;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Parser.TagHelpers; using Microsoft.AspNet.Razor.Parser.TagHelpers;
using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.AspNet.Razor.TagHelpers;
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.Chunks.Generators
{ {
/// <summary> /// <summary>
/// A <see cref="BlockCodeGenerator"/> that is responsible for generating valid <see cref="TagHelperChunk"/>s. /// A <see cref="ParentChunkGenerator"/> that is responsible for generating valid <see cref="TagHelperChunk"/>s.
/// </summary> /// </summary>
public class TagHelperCodeGenerator : BlockCodeGenerator public class TagHelperChunkGenerator : ParentChunkGenerator
{ {
private IEnumerable<TagHelperDescriptor> _tagHelperDescriptors; private IEnumerable<TagHelperDescriptor> _tagHelperDescriptors;
/// <summary> /// <summary>
/// Instantiates a new <see cref="TagHelperCodeGenerator"/>. /// Instantiates a new <see cref="TagHelperChunkGenerator"/>.
/// </summary> /// </summary>
/// <param name="tagHelperDescriptors"> /// <param name="tagHelperDescriptors">
/// <see cref="TagHelperDescriptor"/>s associated with the current HTML tag. /// <see cref="TagHelperDescriptor"/>s associated with the current HTML tag.
/// </param> /// </param>
public TagHelperCodeGenerator(IEnumerable<TagHelperDescriptor> tagHelperDescriptors) public TagHelperChunkGenerator(IEnumerable<TagHelperDescriptor> tagHelperDescriptors)
{ {
_tagHelperDescriptors = tagHelperDescriptors; _tagHelperDescriptors = tagHelperDescriptors;
} }
@ -33,11 +32,11 @@ namespace Microsoft.AspNet.Razor.Generator
/// Starts the generation of a <see cref="TagHelperChunk"/>. /// Starts the generation of a <see cref="TagHelperChunk"/>.
/// </summary> /// </summary>
/// <param name="target"> /// <param name="target">
/// The <see cref="Block"/> responsible for this <see cref="TagHelperCodeGenerator"/>. /// The <see cref="Block"/> responsible for this <see cref="TagHelperChunkGenerator"/>.
/// </param> /// </param>
/// <param name="context">A <see cref="CodeGeneratorContext"/> instance that contains information about /// <param name="context">A <see cref="ChunkGeneratorContext"/> instance that contains information about
/// the current code generation process.</param> /// the current chunk generation process.</param>
public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context) public override void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
{ {
var tagHelperBlock = target as TagHelperBlock; var tagHelperBlock = target as TagHelperBlock;
@ -49,25 +48,25 @@ namespace Microsoft.AspNet.Razor.Generator
var attributes = new List<KeyValuePair<string, Chunk>>(); var attributes = new List<KeyValuePair<string, Chunk>>();
// We need to create a code generator to create chunks for each of the attributes. // We need to create a chunk generator to create chunks for each of the attributes.
var codeGenerator = context.Host.CreateCodeGenerator( var chunkGenerator = context.Host.CreateChunkGenerator(
context.ClassName, context.ClassName,
context.RootNamespace, context.RootNamespace,
context.SourceFile); context.SourceFile);
foreach (var attribute in tagHelperBlock.Attributes) foreach (var attribute in tagHelperBlock.Attributes)
{ {
ChunkBlock attributeChunkValue = null; ParentChunk attributeChunkValue = null;
if (attribute.Value != null) if (attribute.Value != null)
{ {
// Populates the code tree with chunks associated with attributes // Populates the code tree with chunks associated with attributes
attribute.Value.Accept(codeGenerator); attribute.Value.Accept(chunkGenerator);
var chunks = codeGenerator.Context.CodeTreeBuilder.CodeTree.Chunks; var chunks = chunkGenerator.Context.ChunkTreeBuilder.ChunkTree.Chunks;
var first = chunks.FirstOrDefault(); var first = chunks.FirstOrDefault();
attributeChunkValue = new ChunkBlock attributeChunkValue = new ParentChunk
{ {
Association = first?.Association, Association = first?.Association,
Children = chunks, Children = chunks,
@ -78,12 +77,12 @@ namespace Microsoft.AspNet.Razor.Generator
attributes.Add(new KeyValuePair<string, Chunk>(attribute.Key, attributeChunkValue)); attributes.Add(new KeyValuePair<string, Chunk>(attribute.Key, attributeChunkValue));
// Reset the code tree builder so we can build a new one for the next attribute // Reset the code tree builder so we can build a new one for the next attribute
codeGenerator.Context.CodeTreeBuilder = new CodeTreeBuilder(); chunkGenerator.Context.ChunkTreeBuilder = new ChunkTreeBuilder();
} }
var unprefixedTagName = tagHelperBlock.TagName.Substring(_tagHelperDescriptors.First().Prefix.Length); var unprefixedTagName = tagHelperBlock.TagName.Substring(_tagHelperDescriptors.First().Prefix.Length);
context.CodeTreeBuilder.StartChunkBlock( context.ChunkTreeBuilder.StartParentChunk(
new TagHelperChunk( new TagHelperChunk(
unprefixedTagName, unprefixedTagName,
tagHelperBlock.SelfClosing, tagHelperBlock.SelfClosing,
@ -95,16 +94,16 @@ namespace Microsoft.AspNet.Razor.Generator
/// <summary> /// <summary>
/// Ends the generation of a <see cref="TagHelperChunk"/> capturing all previously visited children /// Ends the generation of a <see cref="TagHelperChunk"/> capturing all previously visited children
/// since the <see cref="GenerateStartBlockCode"/> method was called. /// since the <see cref="GenerateStartParentChunk"/> method was called.
/// </summary> /// </summary>
/// <param name="target"> /// <param name="target">
/// The <see cref="Block"/> responsible for this <see cref="TagHelperCodeGenerator"/>. /// The <see cref="Block"/> responsible for this <see cref="TagHelperChunkGenerator"/>.
/// </param> /// </param>
/// <param name="context">A <see cref="CodeGeneratorContext"/> instance that contains information about /// <param name="context">A <see cref="ChunkGeneratorContext"/> instance that contains information about
/// the current code generation process.</param> /// the current chunk generation process.</param>
public override void GenerateEndBlockCode(Block target, CodeGeneratorContext context) public override void GenerateEndParentChunk(Block target, ChunkGeneratorContext context)
{ {
context.CodeTreeBuilder.EndChunkBlock(); context.ChunkTreeBuilder.EndParentChunk();
} }
} }
} }

View File

@ -3,21 +3,21 @@
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.Chunks.Generators
{ {
/// <summary> /// <summary>
/// A <see cref="SpanCodeGenerator"/> responsible for generating /// A <see cref="SpanChunkGenerator"/> responsible for generating
/// <see cref="Compiler.TagHelperPrefixDirectiveChunk"/>s. /// <see cref="TagHelperPrefixDirectiveChunk"/>s.
/// </summary> /// </summary>
public class TagHelperPrefixDirectiveCodeGenerator : SpanCodeGenerator public class TagHelperPrefixDirectiveChunkGenerator : SpanChunkGenerator
{ {
/// <summary> /// <summary>
/// Instantiates a new <see cref="TagHelperPrefixDirectiveCodeGenerator"/>. /// Instantiates a new <see cref="TagHelperPrefixDirectiveChunkGenerator"/>.
/// </summary> /// </summary>
/// <param name="prefix"> /// <param name="prefix">
/// Text used as a required prefix when matching HTML. /// Text used as a required prefix when matching HTML.
/// </param> /// </param>
public TagHelperPrefixDirectiveCodeGenerator(string prefix) public TagHelperPrefixDirectiveChunkGenerator(string prefix)
{ {
Prefix = prefix; Prefix = prefix;
} }
@ -28,16 +28,16 @@ namespace Microsoft.AspNet.Razor.Generator
public string Prefix { get; } public string Prefix { get; }
/// <summary> /// <summary>
/// Generates <see cref="Compiler.TagHelperPrefixDirectiveChunk"/>s. /// Generates <see cref="TagHelperPrefixDirectiveChunk"/>s.
/// </summary> /// </summary>
/// <param name="target"> /// <param name="target">
/// The <see cref="Span"/> responsible for this <see cref="TagHelperPrefixDirectiveCodeGenerator"/>. /// The <see cref="Span"/> responsible for this <see cref="TagHelperPrefixDirectiveChunkGenerator"/>.
/// </param> /// </param>
/// <param name="context">A <see cref="CodeGeneratorContext"/> instance that contains information about /// <param name="context">A <see cref="ChunkGeneratorContext"/> instance that contains information about
/// the current code generation process.</param> /// the current chunk generation process.</param>
public override void GenerateCode(Span target, CodeGeneratorContext context) public override void GenerateChunk(Span target, ChunkGeneratorContext context)
{ {
context.CodeTreeBuilder.AddTagHelperPrefixDirectiveChunk(Prefix, target); context.ChunkTreeBuilder.AddTagHelperPrefixDirectiveChunk(Prefix, target);
} }
} }
} }

View File

@ -0,0 +1,20 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Chunks.Generators
{
public class TemplateBlockChunkGenerator : ParentChunkGenerator
{
public override void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
{
context.ChunkTreeBuilder.StartParentChunk<TemplateChunk>(target);
}
public override void GenerateEndParentChunk(Block target, ChunkGeneratorContext context)
{
context.ChunkTreeBuilder.EndParentChunk();
}
}
}

View File

@ -3,13 +3,13 @@
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.Chunks.Generators
{ {
public class TypeMemberCodeGenerator : SpanCodeGenerator public class TypeMemberChunkGenerator : SpanChunkGenerator
{ {
public override void GenerateCode(Span target, CodeGeneratorContext context) public override void GenerateChunk(Span target, ChunkGeneratorContext context)
{ {
context.CodeTreeBuilder.AddTypeMemberChunk(target.Content, target); context.ChunkTreeBuilder.AddTypeMemberChunk(target.Content, 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.
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
public class LiteralChunk : Chunk public class LiteralChunk : Chunk
{ {

View File

@ -3,9 +3,9 @@
using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Text;
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
public class LiteralCodeAttributeChunk : ChunkBlock public class LiteralCodeAttributeChunk : ParentChunk
{ {
public string Code { get; set; } public string Code { get; set; }
public LocationTagged<string> Prefix { get; set; } public LocationTagged<string> Prefix { get; set; }

View File

@ -3,11 +3,11 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
public class ChunkBlock : Chunk public class ParentChunk : Chunk
{ {
public ChunkBlock() public ParentChunk()
{ {
Children = new List<Chunk>(); Children = new List<Chunk>();
} }

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.
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
/// <summary> /// <summary>
/// A <see cref="Chunk"/> used to look up <see cref="TagHelpers.TagHelperDescriptor"/>s that should be ignored /// A <see cref="Chunk"/> used to look up <see cref="TagHelpers.TagHelperDescriptor"/>s that should be ignored

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.
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
public class ResolveUrlChunk : Chunk public class ResolveUrlChunk : Chunk
{ {

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.
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
public class SectionChunk : ChunkBlock public class SectionChunk : ParentChunk
{ {
public string Name { get; set; } public string Name { get; set; }
} }

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.
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
public class SetBaseTypeChunk : Chunk public class SetBaseTypeChunk : Chunk
{ {

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.
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
public class StatementChunk : Chunk public class StatementChunk : Chunk
{ {

View File

@ -4,12 +4,12 @@
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.AspNet.Razor.TagHelpers;
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
/// <summary> /// <summary>
/// A <see cref="ChunkBlock"/> that represents a special HTML tag. /// A <see cref="ParentChunk"/> that represents a special HTML tag.
/// </summary> /// </summary>
public class TagHelperChunk : ChunkBlock public class TagHelperChunk : ParentChunk
{ {
/// <summary> /// <summary>
/// Instantiates a new <see cref="TagHelperChunk"/>. /// Instantiates a new <see cref="TagHelperChunk"/>.

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.
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
/// <summary> /// <summary>
/// A <see cref="Chunk"/> for the <c>@tagHelperPrefix</c> directive. /// A <see cref="Chunk"/> for the <c>@tagHelperPrefix</c> directive.

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.
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
public class TemplateChunk : ChunkBlock public class TemplateChunk : ParentChunk
{ {
} }
} }

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.
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
public class TypeMemberChunk : Chunk public class TypeMemberChunk : Chunk
{ {

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.
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Chunks
{ {
public class UsingChunk : Chunk public class UsingChunk : Chunk
{ {

View File

@ -4,9 +4,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Razor.Chunks;
using Microsoft.AspNet.Razor.CodeGeneration.Visitors;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp namespace Microsoft.AspNet.Razor.CodeGeneration
{ {
public class CSharpCodeBuilder : CodeBuilder public class CSharpCodeBuilder : CodeBuilder
{ {
@ -19,7 +21,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
{ {
} }
private CodeTree Tree { get { return Context.CodeTreeBuilder.CodeTree; } } private ChunkTree Tree { get { return Context.ChunkTreeBuilder.ChunkTree; } }
public RazorEngineHost Host { get { return Context.Host; } } public RazorEngineHost Host { get { return Context.Host; } }
// Internal for testing // Internal for testing
@ -65,7 +67,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
BuildConstructor(writer); BuildConstructor(writer);
// Add space inbetween constructor and method body // Add space in-between constructor and method body
writer.WriteLine(); writer.WriteLine();
using (writer.BuildDisableWarningScope(DisableAsyncWarning)) using (writer.BuildDisableWarningScope(DisableAsyncWarning))
@ -109,7 +111,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
}; };
} }
private void AddImports(CodeTree codeTree, CSharpCodeWriter writer, IEnumerable<string> defaultImports) private void AddImports(ChunkTree chunkTree, CSharpCodeWriter writer, IEnumerable<string> defaultImports)
{ {
// Write out using directives // Write out using directives
var usingVisitor = new CSharpUsingVisitor(writer, Context); var usingVisitor = new CSharpUsingVisitor(writer, Context);

View File

@ -5,11 +5,12 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Text;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp namespace Microsoft.AspNet.Razor.CodeGeneration
{ {
public class CSharpCodeWriter : CodeWriter public class CSharpCodeWriter : CodeWriter
{ {
@ -463,7 +464,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
Write("\""); Write("\"");
} }
public void WriteStartInstrumentationContext(CodeGeneratorContext context, SyntaxTreeNode syntaxNode, bool isLiteral) public void WriteStartInstrumentationContext(ChunkGeneratorContext context, SyntaxTreeNode syntaxNode, bool isLiteral)
{ {
WriteStartMethodInvocation(context.Host.GeneratedClassContext.BeginContextMethodName); WriteStartMethodInvocation(context.Host.GeneratedClassContext.BeginContextMethodName);
Write(syntaxNode.Start.AbsoluteIndex.ToString(CultureInfo.InvariantCulture)); Write(syntaxNode.Start.AbsoluteIndex.ToString(CultureInfo.InvariantCulture));
@ -474,7 +475,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
WriteEndMethodInvocation(); WriteEndMethodInvocation();
} }
public void WriteEndInstrumentationContext(CodeGeneratorContext context) public void WriteEndInstrumentationContext(ChunkGeneratorContext context)
{ {
WriteMethodInvocation(context.Host.GeneratedClassContext.EndContextMethodName); WriteMethodInvocation(context.Host.GeneratedClassContext.EndContextMethodName);
} }

View File

@ -4,7 +4,7 @@
using System; using System;
using System.Linq; using System.Linq;
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.CodeGeneration
{ {
public struct CSharpCodeWritingScope : IDisposable public struct CSharpCodeWritingScope : IDisposable
{ {

View File

@ -3,7 +3,7 @@
using System; using System;
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp namespace Microsoft.AspNet.Razor.CodeGeneration
{ {
public struct CSharpDisableWarningScope : IDisposable public struct CSharpDisableWarningScope : IDisposable
{ {

View File

@ -4,7 +4,7 @@
using System; using System;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp namespace Microsoft.AspNet.Razor.CodeGeneration
{ {
public class CSharpLineMappingWriter : IDisposable public class CSharpLineMappingWriter : IDisposable
{ {

View File

@ -6,7 +6,7 @@ using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp namespace Microsoft.AspNet.Razor.CodeGeneration
{ {
public class CSharpPaddingBuilder public class CSharpPaddingBuilder
{ {

View File

@ -5,10 +5,12 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Razor.Chunks;
using Microsoft.AspNet.Razor.CodeGeneration.Visitors;
using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp namespace Microsoft.AspNet.Razor.CodeGeneration
{ {
/// <summary> /// <summary>
/// Renders tag helper rendering code. /// Renders tag helper rendering code.
@ -604,16 +606,16 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
private static bool TryGetPlainTextValue(Chunk chunk, out string plainText) private static bool TryGetPlainTextValue(Chunk chunk, out string plainText)
{ {
var chunkBlock = chunk as ChunkBlock; var parentChunk = chunk as ParentChunk;
plainText = null; plainText = null;
if (chunkBlock == null || chunkBlock.Children.Count != 1) if (parentChunk == null || parentChunk.Children.Count != 1)
{ {
return false; return false;
} }
var literalChildChunk = chunkBlock.Children[0] as LiteralChunk; var literalChildChunk = parentChunk.Children[0] as LiteralChunk;
if (literalChildChunk == null) if (literalChildChunk == null)
{ {

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.
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.CodeGeneration
{ {
public abstract class CodeBuilder public abstract class CodeBuilder
{ {

View File

@ -1,22 +1,24 @@
// 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.
namespace Microsoft.AspNet.Razor.Generator using Microsoft.AspNet.Razor.Chunks.Generators;
namespace Microsoft.AspNet.Razor.CodeGeneration
{ {
/// <summary> /// <summary>
/// Context object with information used to generate a Razor page. /// Context object with information used to generate a Razor page.
/// </summary> /// </summary>
public class CodeBuilderContext : CodeGeneratorContext public class CodeBuilderContext : ChunkGeneratorContext
{ {
/// <summary> /// <summary>
/// Instantiates a new instance of the <see cref="CodeBuilderContext"/> object. /// Instantiates a new instance of the <see cref="CodeBuilderContext"/> object.
/// </summary> /// </summary>
/// <param name="generatorContext">A <see cref="CodeGeneratorContext"/> to copy information from.</param> /// <param name="generatorContext">A <see cref="ChunkGeneratorContext"/> to copy information from.</param>
/// <param name="errorSink"> /// <param name="errorSink">
/// The <see cref="ErrorSink"/> used to collect <see cref="RazorError"/>s encountered /// The <see cref="ErrorSink"/> used to collect <see cref="RazorError"/>s encountered
/// when parsing the current Razor document. /// when parsing the current Razor document.
/// </param> /// </param>
public CodeBuilderContext(CodeGeneratorContext generatorContext, ErrorSink errorSink) public CodeBuilderContext(ChunkGeneratorContext generatorContext, ErrorSink errorSink)
: base(generatorContext) : base(generatorContext)
{ {
ErrorSink = errorSink; ErrorSink = errorSink;
@ -41,14 +43,14 @@ namespace Microsoft.AspNet.Razor.Generator
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// <see cref="ExpressionRenderingMode.WriteToOutput"/> forces C# generation to write /// <see cref="ExpressionRenderingMode.WriteToOutput"/> forces C# generation to write
/// <see cref="Compiler.Chunk"/>s to the output page, i.e. WriteLiteral("Hello World"). /// <see cref="Chunks.Chunk"/>s to the output page, i.e. WriteLiteral("Hello World").
/// <see cref="ExpressionRenderingMode.InjectCode"/> writes <see cref="Compiler.Chunk"/> values in their /// <see cref="ExpressionRenderingMode.InjectCode"/> writes <see cref="Chunks.Chunk"/> values in their
/// rawest form, i.g. "Hello World". /// rawest form, i.g. "Hello World".
/// </remarks> /// </remarks>
public ExpressionRenderingMode ExpressionRenderingMode { get; set; } public ExpressionRenderingMode ExpressionRenderingMode { get; set; }
/// <summary> /// <summary>
/// The C# writer to write <see cref="Compiler.Chunk"/> information to. /// The C# writer to write <see cref="Chunks.Chunk"/> information to.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// If <see cref="TargetWriterName"/> is <c>null</c> values will be written using a default write method /// If <see cref="TargetWriterName"/> is <c>null</c> values will be written using a default write method
@ -60,7 +62,7 @@ namespace Microsoft.AspNet.Razor.Generator
/// <summary> /// <summary>
/// Gets or sets the <c>SHA1</c> based checksum for the file whose location is defined by /// Gets or sets the <c>SHA1</c> based checksum for the file whose location is defined by
/// <see cref="CodeGeneratorContext.SourceFile"/>. /// <see cref="ChunkGeneratorContext.SourceFile"/>.
/// </summary> /// </summary>
public string Checksum { get; set; } public string Checksum { get; set; }

View File

@ -3,7 +3,7 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.CodeGeneration
{ {
public class CodeBuilderResult public class CodeBuilderResult
{ {

View File

@ -4,7 +4,7 @@
using System; using System;
using System.IO; using System.IO;
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.CodeGeneration
{ {
public class CodeWriter : IDisposable public class CodeWriter : IDisposable
{ {

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.
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.CodeGeneration
{ {
public enum ExpressionRenderingMode public enum ExpressionRenderingMode
{ {
@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Razor.Generator
/// Indicates that expressions should be written to the output stream /// Indicates that expressions should be written to the output stream
/// </summary> /// </summary>
/// <example> /// <example>
/// If @foo is rendered with WriteToOutput, the code generator would output the following code: /// If @foo is rendered with WriteToOutput, the code builder would output the following code:
/// ///
/// Write(foo); /// Write(foo);
/// </example> /// </example>
@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Razor.Generator
/// the code exists will be used to render it /// the code exists will be used to render it
/// </summary> /// </summary>
/// <example> /// <example>
/// If @foo is rendered with InjectCode, the code generator would output the following code: /// If @foo is rendered with InjectCode, the code builder would output the following code:
/// ///
/// foo /// foo
/// </example> /// </example>

View File

@ -6,7 +6,7 @@ using System.Diagnostics.CodeAnalysis;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Internal.Web.Utils; using Microsoft.Internal.Web.Utils;
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.CodeGeneration
{ {
public struct GeneratedClassContext public struct GeneratedClassContext
{ {

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.
namespace Microsoft.AspNet.Razor.Generator namespace Microsoft.AspNet.Razor.CodeGeneration
{ {
/// <summary> /// <summary>
/// Contains necessary information for the tag helper code generation process. /// Contains necessary information for the tag helper code generation process.

View File

@ -4,7 +4,7 @@
using System.Globalization; using System.Globalization;
using Microsoft.Internal.Web.Utils; using Microsoft.Internal.Web.Utils;
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.CodeGeneration
{ {
public class LineMapping public class LineMapping
{ {

View File

@ -3,7 +3,7 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.CodeGeneration
{ {
public class LineMappingManager public class LineMappingManager
{ {

View File

@ -4,7 +4,7 @@
using System.Globalization; using System.Globalization;
using Microsoft.Internal.Web.Utils; using Microsoft.Internal.Web.Utils;
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.CodeGeneration
{ {
public class MappingLocation public class MappingLocation
{ {

View File

@ -1,9 +1,10 @@
// 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.Chunks;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
{ {
public class CSharpBaseTypeVisitor : CodeVisitor<CSharpCodeWriter> public class CSharpBaseTypeVisitor : CodeVisitor<CSharpCodeWriter>
{ {

View File

@ -3,10 +3,11 @@
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Razor.Chunks;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
{ {
public class CSharpCodeVisitor : CodeVisitor<CSharpCodeWriter> public class CSharpCodeVisitor : CodeVisitor<CSharpCodeWriter>
{ {
@ -70,7 +71,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
TagHelperRenderer.RenderTagHelper(chunk); TagHelperRenderer.RenderTagHelper(chunk);
} }
protected override void Visit(ChunkBlock chunk) protected override void Visit(ParentChunk chunk)
{ {
Accept(chunk.Children); Accept(chunk.Children);
} }

View File

@ -3,9 +3,10 @@
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Razor.Chunks;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
{ {
public class CSharpDesignTimeHelpersVisitor : CodeVisitor<CSharpCodeWriter> public class CSharpDesignTimeHelpersVisitor : CodeVisitor<CSharpCodeWriter>
{ {
@ -28,7 +29,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
_csharpCodeVisitor = csharpCodeVisitor; _csharpCodeVisitor = csharpCodeVisitor;
} }
public void AcceptTree(CodeTree tree) public void AcceptTree(ChunkTree tree)
{ {
if (Context.Host.DesignTimeMode) if (Context.Host.DesignTimeMode)
{ {

View File

@ -1,11 +1,12 @@
// 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.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.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
{ {
/// <summary> /// <summary>
/// <see cref="CodeVisitor{CSharpCodeWriter}"/> that writes code for a non-<see langword="string"/> tag helper /// <see cref="CodeVisitor{CSharpCodeWriter}"/> that writes code for a non-<see langword="string"/> tag helper
@ -44,11 +45,11 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
/// <summary> /// <summary>
/// Writes code for the given <paramref name="chunk"/>. /// Writes code for the given <paramref name="chunk"/>.
/// </summary> /// </summary>
/// <param name="chunk">The <see cref="ChunkBlock"/> to render.</param> /// <param name="chunk">The <see cref="ParentChunk"/> to render.</param>
/// <remarks> /// <remarks>
/// Tracks code mappings for all children while writing. /// Tracks code mappings for all children while writing.
/// </remarks> /// </remarks>
protected override void Visit(ChunkBlock chunk) protected override void Visit(ParentChunk chunk)
{ {
// Line mappings are captured in RenderCode(), not this method. // Line mappings are captured in RenderCode(), not this method.
_firstChild = true; _firstChild = true;
@ -97,7 +98,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
/// <param name="chunk">The <see cref="ResolveUrlChunk"/> to render.</param> /// <param name="chunk">The <see cref="ResolveUrlChunk"/> to render.</param>
/// <remarks> /// <remarks>
/// Allowed to support future C# extensions. Likely "~/..." will lead to a C# compilation error but that is up /// Allowed to support future C# extensions. Likely "~/..." will lead to a C# compilation error but that is up
/// to the compiler. /// to the .
/// </remarks> /// </remarks>
protected override void Visit(ResolveUrlChunk chunk) protected override void Visit(ResolveUrlChunk chunk)
{ {

View File

@ -3,9 +3,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Razor.Chunks;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
{ {
public class CSharpTagHelperFieldDeclarationVisitor : CodeVisitor<CSharpCodeWriter> public class CSharpTagHelperFieldDeclarationVisitor : CodeVisitor<CSharpCodeWriter>
{ {
@ -80,20 +81,20 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
public override void Accept(Chunk chunk) public override void Accept(Chunk chunk)
{ {
var chunkBlock = chunk as ChunkBlock; var parentChunk = chunk as ParentChunk;
// If we're any ChunkBlock other than TagHelperChunk then we want to dive into its Children // If we're any ParentChunk other than TagHelperChunk then we want to dive into its Children
// to search for more TagHelperChunk chunks. This if-statement enables us to not override // to search for more TagHelperChunk chunks. This if-statement enables us to not override
// each of the special ChunkBlock types and then dive into their children. // each of the special ParentChunk types and then dive into their children.
if (chunkBlock != null && !(chunkBlock is TagHelperChunk)) if (parentChunk != null && !(parentChunk is TagHelperChunk))
{ {
Accept(chunkBlock.Children); Accept(parentChunk.Children);
} }
else else
{ {
// If we're a TagHelperChunk or any other non ChunkBlock we ".Accept" it. This ensures // If we're a TagHelperChunk or any other non ParentChunk we ".Accept" it. This ensures
// that our overriden Visit(TagHelperChunk) method gets called and is not skipped over. // that our overridden Visit(TagHelperChunk) method gets called and is not skipped over.
// If we're a non ChunkBlock or a TagHelperChunk then we want to just invoke the Visit // If we're a non ParentChunk or a TagHelperChunk then we want to just invoke the Visit
// method for that given chunk (base.Accept indirectly calls the Visit method). // method for that given chunk (base.Accept indirectly calls the Visit method).
base.Accept(chunk); base.Accept(chunk);
} }

View File

@ -1,9 +1,10 @@
// 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.Chunks;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
{ {
/// <summary> /// <summary>
/// The <see cref="CodeVisitor{T}"/> that generates the code to initialize the TagHelperRunner. /// The <see cref="CodeVisitor{T}"/> that generates the code to initialize the TagHelperRunner.

View File

@ -1,9 +1,10 @@
// 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.Chunks;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
{ {
public class CSharpTypeMemberVisitor : CodeVisitor<CSharpCodeWriter> public class CSharpTypeMemberVisitor : CodeVisitor<CSharpCodeWriter>
{ {

View File

@ -3,10 +3,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Razor.Chunks;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
{ {
public class CSharpUsingVisitor : CodeVisitor<CSharpCodeWriter> public class CSharpUsingVisitor : CodeVisitor<CSharpCodeWriter>
{ {

View File

@ -2,9 +2,10 @@
// 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.Chunks;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
{ {
public abstract class ChunkVisitor<TWriter> : IChunkVisitor public abstract class ChunkVisitor<TWriter> : IChunkVisitor
where TWriter : CodeWriter where TWriter : CodeWriter
@ -96,9 +97,9 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
{ {
Visit((TemplateChunk)chunk); Visit((TemplateChunk)chunk);
} }
else if (chunk is ChunkBlock) else if (chunk is ParentChunk)
{ {
Visit((ChunkBlock)chunk); Visit((ParentChunk)chunk);
} }
} }
@ -110,7 +111,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
protected abstract void Visit(AddTagHelperChunk chunk); protected abstract void Visit(AddTagHelperChunk chunk);
protected abstract void Visit(RemoveTagHelperChunk chunk); protected abstract void Visit(RemoveTagHelperChunk chunk);
protected abstract void Visit(UsingChunk chunk); protected abstract void Visit(UsingChunk chunk);
protected abstract void Visit(ChunkBlock chunk); protected abstract void Visit(ParentChunk chunk);
protected abstract void Visit(DynamicCodeAttributeChunk chunk); protected abstract void Visit(DynamicCodeAttributeChunk chunk);
protected abstract void Visit(LiteralCodeAttributeChunk chunk); protected abstract void Visit(LiteralCodeAttributeChunk chunk);
protected abstract void Visit(CodeAttributeChunk chunk); protected abstract void Visit(CodeAttributeChunk chunk);

View File

@ -1,9 +1,10 @@
// 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.Chunks;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
{ {
public class CodeVisitor<TWriter> : ChunkVisitor<TWriter> public class CodeVisitor<TWriter> : ChunkVisitor<TWriter>
where TWriter : CodeWriter where TWriter : CodeWriter
@ -28,7 +29,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
protected override void Visit(UsingChunk chunk) protected override void Visit(UsingChunk chunk)
{ {
} }
protected override void Visit(ChunkBlock chunk) protected override void Visit(ParentChunk chunk)
{ {
} }
protected override void Visit(DynamicCodeAttributeChunk chunk) protected override void Visit(DynamicCodeAttributeChunk chunk)

View File

@ -2,8 +2,9 @@
// 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.Chunks;
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
{ {
public interface IChunkVisitor public interface IChunkVisitor
{ {

View File

@ -12,17 +12,17 @@ namespace Microsoft.AspNet.Razor
public class DocumentParseCompleteEventArgs : EventArgs public class DocumentParseCompleteEventArgs : EventArgs
{ {
/// <summary> /// <summary>
/// Indicates if the tree structure has actually changed since the previous reparse. /// Indicates if the tree structure has actually changed since the previous re-parse.
/// </summary> /// </summary>
public bool TreeStructureChanged { get; set; } public bool TreeStructureChanged { get; set; }
/// <summary> /// <summary>
/// The results of the code generation and parsing /// The results of the chunk generation and parsing
/// </summary> /// </summary>
public GeneratorResults GeneratorResults { get; set; } public GeneratorResults GeneratorResults { get; set; }
/// <summary> /// <summary>
/// The TextChange which triggered the reparse /// The TextChange which triggered the re-parse
/// </summary> /// </summary>
public TextChange SourceChange { get; set; } public TextChange SourceChange { get; set; }
} }

View File

@ -1,24 +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 Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Generator
{
public class CSharpRazorCodeGenerator : RazorCodeGenerator
{
public CSharpRazorCodeGenerator(
string className,
[NotNull] string rootNamespaceName,
string sourceFileName,
[NotNull] RazorEngineHost host)
: base(className, rootNamespaceName, sourceFileName, host)
{
}
protected override void Initialize(CodeGeneratorContext context)
{
base.Initialize(context);
}
}
}

View File

@ -1,44 +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 Microsoft.AspNet.Razor.Generator.Compiler;
namespace Microsoft.AspNet.Razor.Generator
{
public class CodeGeneratorContext
{
protected CodeGeneratorContext(CodeGeneratorContext context)
: this(context.Host,
context.ClassName,
context.RootNamespace,
context.SourceFile,
// True because we're pulling from the provided context's source file.
shouldGenerateLinePragmas: true)
{
CodeTreeBuilder = context.CodeTreeBuilder;
}
public CodeGeneratorContext(RazorEngineHost host,
string className,
string rootNamespace,
string sourceFile,
bool shouldGenerateLinePragmas)
{
CodeTreeBuilder = new CodeTreeBuilder();
Host = host;
SourceFile = shouldGenerateLinePragmas ? sourceFile : null;
RootNamespace = rootNamespace;
ClassName = className;
}
public string SourceFile { get; internal set; }
public string RootNamespace { get; private set; }
public string ClassName { get; private set; }
public RazorEngineHost Host { get; private set; }
public CodeTreeBuilder CodeTreeBuilder { get; set; }
}
}

View File

@ -1,22 +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 Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Generator
{
public abstract class HybridCodeGenerator : ISpanCodeGenerator, IBlockCodeGenerator
{
public virtual void GenerateStartBlockCode(Block target, CodeGeneratorContext context)
{
}
public virtual void GenerateEndBlockCode(Block target, CodeGeneratorContext context)
{
}
public virtual void GenerateCode(Span target, CodeGeneratorContext context)
{
}
}
}

View File

@ -1,13 +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 Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Generator
{
public interface IBlockCodeGenerator
{
void GenerateStartBlockCode(Block target, CodeGeneratorContext context);
void GenerateEndBlockCode(Block target, CodeGeneratorContext context);
}
}

View File

@ -1,21 +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 Microsoft.AspNet.Razor.Generator.Compiler;
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Generator
{
public class TemplateBlockCodeGenerator : BlockCodeGenerator
{
public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context)
{
context.CodeTreeBuilder.StartChunkBlock<TemplateChunk>(target);
}
public override void GenerateEndBlockCode(Block target, CodeGeneratorContext context)
{
context.CodeTreeBuilder.EndChunkBlock();
}
}
}

View File

@ -2,7 +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.Compiler; using Microsoft.AspNet.Razor.Chunks;
using Microsoft.AspNet.Razor.CodeGeneration;
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.Internal; using Microsoft.Framework.Internal;
@ -19,15 +20,15 @@ namespace Microsoft.AspNet.Razor
/// </summary> /// </summary>
/// <param name="parserResults">The results of parsing a document.</param> /// <param name="parserResults">The results of parsing a document.</param>
/// <param name="codeBuilderResult">The results of generating code for the document.</param> /// <param name="codeBuilderResult">The results of generating code for the document.</param>
/// <param name="codeTree">A <see cref="CodeTree"/> for the document.</param> /// <param name="chunkTree">A <see cref="ChunkTree"/> for the document.</param>
public GeneratorResults([NotNull] ParserResults parserResults, public GeneratorResults([NotNull] ParserResults parserResults,
[NotNull] CodeBuilderResult codeBuilderResult, [NotNull] CodeBuilderResult codeBuilderResult,
[NotNull] CodeTree codeTree) [NotNull] ChunkTree chunkTree)
: this(parserResults.Document, : this(parserResults.Document,
parserResults.TagHelperDescriptors, parserResults.TagHelperDescriptors,
parserResults.ErrorSink, parserResults.ErrorSink,
codeBuilderResult, codeBuilderResult,
codeTree) chunkTree)
{ {
} }
@ -43,17 +44,17 @@ namespace Microsoft.AspNet.Razor
/// current Razor document. /// current Razor document.
/// </param> /// </param>
/// <param name="codeBuilderResult">The results of generating code for the document.</param> /// <param name="codeBuilderResult">The results of generating code for the document.</param>
/// <param name="codeTree">A <see cref="CodeTree"/> for the document.</param> /// <param name="chunkTree">A <see cref="ChunkTree"/> for the document.</param>
public GeneratorResults([NotNull] Block document, public GeneratorResults([NotNull] Block document,
[NotNull] IEnumerable<TagHelperDescriptor> tagHelperDescriptors, [NotNull] IEnumerable<TagHelperDescriptor> tagHelperDescriptors,
[NotNull] ErrorSink errorSink, [NotNull] ErrorSink errorSink,
[NotNull] CodeBuilderResult codeBuilderResult, [NotNull] CodeBuilderResult codeBuilderResult,
[NotNull] CodeTree codeTree) [NotNull] ChunkTree chunkTree)
: base(document, tagHelperDescriptors, errorSink) : base(document, tagHelperDescriptors, errorSink)
{ {
GeneratedCode = codeBuilderResult.Code; GeneratedCode = codeBuilderResult.Code;
DesignTimeLineMappings = codeBuilderResult.DesignTimeLineMappings; DesignTimeLineMappings = codeBuilderResult.DesignTimeLineMappings;
CodeTree = codeTree; ChunkTree = chunkTree;
} }
/// <summary> /// <summary>
@ -67,8 +68,8 @@ namespace Microsoft.AspNet.Razor
public IList<LineMapping> DesignTimeLineMappings { get; } public IList<LineMapping> DesignTimeLineMappings { get; }
/// <summary> /// <summary>
/// A <see cref="Generator.Compiler.CodeTree"/> for the document. /// A <see cref="Chunks.ChunkTree"/> for the document.
/// </summary> /// </summary>
public CodeTree CodeTree { get; } public ChunkTree ChunkTree { get; }
} }
} }

View File

@ -4,7 +4,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Tokenizer.Symbols; using Microsoft.AspNet.Razor.Tokenizer.Symbols;
@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Razor.Parser
{ {
TagHelperDirective( TagHelperDirective(
SyntaxConstants.CSharp.TagHelperPrefixKeyword, SyntaxConstants.CSharp.TagHelperPrefixKeyword,
prefix => new TagHelperPrefixDirectiveCodeGenerator(prefix)); prefix => new TagHelperPrefixDirectiveChunkGenerator(prefix));
} }
protected virtual void AddTagHelperDirective() protected virtual void AddTagHelperDirective()
@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Razor.Parser
TagHelperDirective( TagHelperDirective(
SyntaxConstants.CSharp.AddTagHelperKeyword, SyntaxConstants.CSharp.AddTagHelperKeyword,
lookupText => lookupText =>
new AddOrRemoveTagHelperCodeGenerator(removeTagHelperDescriptors: false, lookupText: lookupText)); new AddOrRemoveTagHelperChunkGenerator(removeTagHelperDescriptors: false, lookupText: lookupText));
} }
protected virtual void RemoveTagHelperDirective() protected virtual void RemoveTagHelperDirective()
@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Razor.Parser
TagHelperDirective( TagHelperDirective(
SyntaxConstants.CSharp.RemoveTagHelperKeyword, SyntaxConstants.CSharp.RemoveTagHelperKeyword,
lookupText => lookupText =>
new AddOrRemoveTagHelperCodeGenerator(removeTagHelperDescriptors: true, lookupText: lookupText)); new AddOrRemoveTagHelperChunkGenerator(removeTagHelperDescriptors: true, lookupText: lookupText));
} }
protected virtual void SectionDirective() protected virtual void SectionDirective()
@ -90,7 +90,7 @@ namespace Microsoft.AspNet.Razor.Parser
sectionName = CurrentSymbol.Content; sectionName = CurrentSymbol.Content;
AcceptAndMoveNext(); AcceptAndMoveNext();
} }
Context.CurrentBlock.CodeGenerator = new SectionCodeGenerator(sectionName); Context.CurrentBlock.ChunkGenerator = new SectionChunkGenerator(sectionName);
var errorLocation = CurrentLocation; var errorLocation = CurrentLocation;
whitespace = ReadWhile(IsSpacingToken(includeNewLines: true, includeComments: false)); whitespace = ReadWhile(IsSpacingToken(includeNewLines: true, includeComments: false));
@ -128,7 +128,7 @@ namespace Microsoft.AspNet.Razor.Parser
Output(SpanKind.MetaCode); Output(SpanKind.MetaCode);
SectionBlock("{", "}", caseSensitive: true); SectionBlock("{", "}", caseSensitive: true);
Span.CodeGenerator = SpanCodeGenerator.Null; Span.ChunkGenerator = SpanChunkGenerator.Null;
// Check for the terminating "}" // Check for the terminating "}"
if (!Optional(CSharpSymbolType.RightBrace)) if (!Optional(CSharpSymbolType.RightBrace))
{ {
@ -182,7 +182,7 @@ namespace Microsoft.AspNet.Razor.Parser
Span.EditHandler = editHandler; Span.EditHandler = editHandler;
Balance(BalancingModes.NoErrorOnFailure, CSharpSymbolType.LeftBrace, CSharpSymbolType.RightBrace, blockStart); Balance(BalancingModes.NoErrorOnFailure, CSharpSymbolType.LeftBrace, CSharpSymbolType.RightBrace, blockStart);
Span.CodeGenerator = new TypeMemberCodeGenerator(); Span.ChunkGenerator = new TypeMemberChunkGenerator();
if (!At(CSharpSymbolType.RightBrace)) if (!At(CSharpSymbolType.RightBrace))
{ {
editHandler.AutoCompleteString = "}"; editHandler.AutoCompleteString = "}";
@ -194,7 +194,7 @@ namespace Microsoft.AspNet.Razor.Parser
{ {
Output(SpanKind.Code); Output(SpanKind.Code);
Assert(CSharpSymbolType.RightBrace); Assert(CSharpSymbolType.RightBrace);
Span.CodeGenerator = SpanCodeGenerator.Null; Span.ChunkGenerator = SpanChunkGenerator.Null;
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None; Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None;
AcceptAndMoveNext(); AcceptAndMoveNext();
CompleteBlock(); CompleteBlock();
@ -222,10 +222,10 @@ namespace Microsoft.AspNet.Razor.Parser
protected void InheritsDirectiveCore() protected void InheritsDirectiveCore()
{ {
BaseTypeDirective(RazorResources.ParseError_InheritsKeyword_Must_Be_Followed_By_TypeName, baseType => new SetBaseTypeCodeGenerator(baseType)); BaseTypeDirective(RazorResources.ParseError_InheritsKeyword_Must_Be_Followed_By_TypeName, baseType => new SetBaseTypeChunkGenerator(baseType));
} }
protected void BaseTypeDirective(string noTypeNameError, Func<string, SpanCodeGenerator> createCodeGenerator) protected void BaseTypeDirective(string noTypeNameError, Func<string, SpanChunkGenerator> createChunkGenerator)
{ {
var keywordStartLocation = Span.Start; var keywordStartLocation = Span.Start;
@ -270,15 +270,15 @@ namespace Microsoft.AspNet.Razor.Parser
// Pull out the type name // Pull out the type name
string baseType = Span.GetContent(); string baseType = Span.GetContent();
// Set up code generation // Set up chunk generation
Span.CodeGenerator = createCodeGenerator(baseType.Trim()); Span.ChunkGenerator = createChunkGenerator(baseType.Trim());
// 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 void TagHelperDirective(string keyword, Func<string, ISpanCodeGenerator> buildCodeGenerator) private void TagHelperDirective(string keyword, Func<string, ISpanChunkGenerator> buildChunkGenerator)
{ {
AssertDirective(keyword); AssertDirective(keyword);
var keywordStartLocation = CurrentLocation; var keywordStartLocation = CurrentLocation;
@ -321,16 +321,16 @@ namespace Microsoft.AspNet.Razor.Parser
// If the value starts with a quote then we should generate appropriate C# code to colorize the value. // If the value starts with a quote then we should generate appropriate C# code to colorize the value.
if (startsWithQuote) if (startsWithQuote)
{ {
// Set up code generation // Set up chunk generation
// The generated chunk of this code generator is picked up by CSharpDesignTimeHelpersVisitor which // The generated chunk of this chunk generator is picked up by CSharpDesignTimeHelpersVisitor which
// renders the C# to colorize the user provided value. We trim the quotes around the user's value // renders the C# to colorize the user provided value. We trim the quotes around the user's value
// so when we render the code we can project the users value into double quotes to not invoke C# // so when we render the code we can project the users value into double quotes to not invoke C#
// IntelliSense. // IntelliSense.
Span.CodeGenerator = buildCodeGenerator(rawValue.Trim('"')); Span.ChunkGenerator = buildChunkGenerator(rawValue.Trim('"'));
} }
// We expect the directive to be surrounded in quotes. // We expect the directive to be surrounded in quotes.
// The format for taghelper directives are: @directivename "SomeValue" // The format for tag helper directives are: @directivename "SomeValue"
if (!startsWithQuote || if (!startsWithQuote ||
!rawValue.EndsWith("\"", StringComparison.OrdinalIgnoreCase)) !rawValue.EndsWith("\"", StringComparison.OrdinalIgnoreCase))
{ {

View File

@ -5,7 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Tokenizer.Symbols; using Microsoft.AspNet.Razor.Tokenizer.Symbols;
@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Razor.Parser
Context.OnError(CurrentLocation, RazorResources.FormatParseError_ReservedWord(CurrentSymbol.Content)); Context.OnError(CurrentLocation, RazorResources.FormatParseError_ReservedWord(CurrentSymbol.Content));
AcceptAndMoveNext(); AcceptAndMoveNext();
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None; Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None;
Span.CodeGenerator = SpanCodeGenerator.Null; Span.ChunkGenerator = SpanChunkGenerator.Null;
Context.CurrentBlock.Type = BlockType.Directive; Context.CurrentBlock.Type = BlockType.Directive;
CompleteBlock(); CompleteBlock();
Output(SpanKind.MetaCode); Output(SpanKind.MetaCode);
@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Razor.Parser
HandleKeyword(topLevel, () => HandleKeyword(topLevel, () =>
{ {
Context.CurrentBlock.Type = BlockType.Expression; Context.CurrentBlock.Type = BlockType.Expression;
Context.CurrentBlock.CodeGenerator = new ExpressionCodeGenerator(); Context.CurrentBlock.ChunkGenerator = new ExpressionChunkGenerator();
ImplicitExpression(); ImplicitExpression();
}); });
} }
@ -158,7 +158,7 @@ namespace Microsoft.AspNet.Razor.Parser
} }
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.AnyExceptNewline; Span.EditHandler.AcceptedCharacters = AcceptedCharacters.AnyExceptNewline;
Span.CodeGenerator = new AddImportCodeGenerator( Span.ChunkGenerator = new AddImportChunkGenerator(
Span.GetContent(symbols => symbols.Skip(1))); Span.GetContent(symbols => symbols.Skip(1)));
// Optional ";" // Optional ";"
@ -510,7 +510,7 @@ namespace Microsoft.AspNet.Razor.Parser
// Output "@" as hidden span // Output "@" as hidden span
Accept(transition); Accept(transition);
Span.CodeGenerator = SpanCodeGenerator.Null; Span.ChunkGenerator = SpanChunkGenerator.Null;
Output(SpanKind.Code); Output(SpanKind.Code);
Assert(CSharpSymbolType.Transition); Assert(CSharpSymbolType.Transition);

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNet.Razor.Editor; using Microsoft.AspNet.Razor.Editor;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Tokenizer; using Microsoft.AspNet.Razor.Tokenizer;
using Microsoft.AspNet.Razor.Tokenizer.Symbols; using Microsoft.AspNet.Razor.Tokenizer.Symbols;
@ -181,7 +181,7 @@ namespace Microsoft.AspNet.Razor.Parser
private void DefaultSpanConfig(SpanBuilder span) private void DefaultSpanConfig(SpanBuilder span)
{ {
span.EditHandler = SpanEditHandler.CreateDefault(Language.TokenizeString); span.EditHandler = SpanEditHandler.CreateDefault(Language.TokenizeString);
span.CodeGenerator = new StatementCodeGenerator(); span.ChunkGenerator = new StatementChunkGenerator();
} }
private void AtTransition(CSharpSymbol current) private void AtTransition(CSharpSymbol current)
@ -189,7 +189,7 @@ namespace Microsoft.AspNet.Razor.Parser
Debug.Assert(current.Type == CSharpSymbolType.Transition); Debug.Assert(current.Type == CSharpSymbolType.Transition);
Accept(current); Accept(current);
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None; Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None;
Span.CodeGenerator = SpanCodeGenerator.Null; Span.ChunkGenerator = SpanChunkGenerator.Null;
// Output the "@" span and continue here // Output the "@" span and continue here
Output(SpanKind.Transition); Output(SpanKind.Transition);
@ -209,7 +209,7 @@ namespace Microsoft.AspNet.Razor.Parser
if (CurrentSymbol.Type == CSharpSymbolType.LeftParenthesis) if (CurrentSymbol.Type == CSharpSymbolType.LeftParenthesis)
{ {
Context.CurrentBlock.Type = BlockType.Expression; Context.CurrentBlock.Type = BlockType.Expression;
Context.CurrentBlock.CodeGenerator = new ExpressionCodeGenerator(); Context.CurrentBlock.ChunkGenerator = new ExpressionChunkGenerator();
ExplicitExpression(); ExplicitExpression();
return; return;
} }
@ -218,14 +218,14 @@ namespace Microsoft.AspNet.Razor.Parser
Action handler; Action handler;
if (TryGetDirectiveHandler(CurrentSymbol.Content, out handler)) if (TryGetDirectiveHandler(CurrentSymbol.Content, out handler))
{ {
Span.CodeGenerator = SpanCodeGenerator.Null; Span.ChunkGenerator = SpanChunkGenerator.Null;
handler(); handler();
return; return;
} }
else else
{ {
Context.CurrentBlock.Type = BlockType.Expression; Context.CurrentBlock.Type = BlockType.Expression;
Context.CurrentBlock.CodeGenerator = new ExpressionCodeGenerator(); Context.CurrentBlock.ChunkGenerator = new ExpressionChunkGenerator();
ImplicitExpression(); ImplicitExpression();
return; return;
} }
@ -244,9 +244,9 @@ namespace Microsoft.AspNet.Razor.Parser
// Invalid character // Invalid character
Context.CurrentBlock.Type = BlockType.Expression; Context.CurrentBlock.Type = BlockType.Expression;
Context.CurrentBlock.CodeGenerator = new ExpressionCodeGenerator(); Context.CurrentBlock.ChunkGenerator = new ExpressionChunkGenerator();
AddMarkerSymbolIfNecessary(); AddMarkerSymbolIfNecessary();
Span.CodeGenerator = new ExpressionCodeGenerator(); Span.ChunkGenerator = new ExpressionChunkGenerator();
Span.EditHandler = new ImplicitExpressionEditHandler( Span.EditHandler = new ImplicitExpressionEditHandler(
Language.TokenizeString, Language.TokenizeString,
DefaultKeywords, DefaultKeywords,
@ -283,7 +283,7 @@ namespace Microsoft.AspNet.Razor.Parser
// Set up the "{" span and output // Set up the "{" span and output
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None; Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None;
Span.CodeGenerator = SpanCodeGenerator.Null; Span.ChunkGenerator = SpanChunkGenerator.Null;
Output(SpanKind.MetaCode); Output(SpanKind.MetaCode);
// Set up auto-complete and parse the code block // Set up auto-complete and parse the code block
@ -291,7 +291,7 @@ namespace Microsoft.AspNet.Razor.Parser
Span.EditHandler = editHandler; Span.EditHandler = editHandler;
CodeBlock(false, block); CodeBlock(false, block);
Span.CodeGenerator = new StatementCodeGenerator(); Span.ChunkGenerator = new StatementChunkGenerator();
AddMarkerSymbolIfNecessary(); AddMarkerSymbolIfNecessary();
if (!At(CSharpSymbolType.RightBrace)) if (!At(CSharpSymbolType.RightBrace))
{ {
@ -303,7 +303,7 @@ namespace Microsoft.AspNet.Razor.Parser
{ {
// Set up the "}" span // Set up the "}" span
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None; Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None;
Span.CodeGenerator = SpanCodeGenerator.Null; Span.ChunkGenerator = SpanChunkGenerator.Null;
} }
if (!At(CSharpSymbolType.WhiteSpace) && !At(CSharpSymbolType.NewLine)) if (!At(CSharpSymbolType.WhiteSpace) && !At(CSharpSymbolType.NewLine))
@ -330,13 +330,13 @@ namespace Microsoft.AspNet.Razor.Parser
private void ImplicitExpression(AcceptedCharacters acceptedCharacters) private void ImplicitExpression(AcceptedCharacters acceptedCharacters)
{ {
Context.CurrentBlock.Type = BlockType.Expression; Context.CurrentBlock.Type = BlockType.Expression;
Context.CurrentBlock.CodeGenerator = new ExpressionCodeGenerator(); Context.CurrentBlock.ChunkGenerator = new ExpressionChunkGenerator();
using (PushSpanConfig(span => using (PushSpanConfig(span =>
{ {
span.EditHandler = new ImplicitExpressionEditHandler(Language.TokenizeString, Keywords, acceptTrailingDot: IsNested); span.EditHandler = new ImplicitExpressionEditHandler(Language.TokenizeString, Keywords, acceptTrailingDot: IsNested);
span.EditHandler.AcceptedCharacters = acceptedCharacters; span.EditHandler.AcceptedCharacters = acceptedCharacters;
span.CodeGenerator = new ExpressionCodeGenerator(); span.ChunkGenerator = new ExpressionChunkGenerator();
})) }))
{ {
do do
@ -504,7 +504,7 @@ namespace Microsoft.AspNet.Razor.Parser
private void ConfigureExplicitExpressionSpan(SpanBuilder sb) private void ConfigureExplicitExpressionSpan(SpanBuilder sb)
{ {
sb.EditHandler = SpanEditHandler.CreateDefault(Language.TokenizeString); sb.EditHandler = SpanEditHandler.CreateDefault(Language.TokenizeString);
sb.CodeGenerator = new ExpressionCodeGenerator(); sb.ChunkGenerator = new ExpressionChunkGenerator();
} }
private void ExplicitExpression() private void ExplicitExpression()
@ -513,7 +513,7 @@ namespace Microsoft.AspNet.Razor.Parser
Assert(CSharpSymbolType.LeftParenthesis); Assert(CSharpSymbolType.LeftParenthesis);
AcceptAndMoveNext(); AcceptAndMoveNext();
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None; Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None;
Span.CodeGenerator = SpanCodeGenerator.Null; Span.ChunkGenerator = SpanChunkGenerator.Null;
Output(SpanKind.MetaCode); Output(SpanKind.MetaCode);
using (PushSpanConfig(ConfigureExplicitExpressionSpan)) using (PushSpanConfig(ConfigureExplicitExpressionSpan))
{ {
@ -544,7 +544,7 @@ namespace Microsoft.AspNet.Razor.Parser
PutCurrentBack(); PutCurrentBack();
} }
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None; Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None;
Span.CodeGenerator = SpanCodeGenerator.Null; Span.ChunkGenerator = SpanChunkGenerator.Null;
CompleteBlock(insertMarkerIfNecessary: false); CompleteBlock(insertMarkerIfNecessary: false);
Output(SpanKind.MetaCode); Output(SpanKind.MetaCode);
} }
@ -558,7 +558,7 @@ namespace Microsoft.AspNet.Razor.Parser
Output(SpanKind.Code); Output(SpanKind.Code);
using (Context.StartBlock(BlockType.Template)) using (Context.StartBlock(BlockType.Template))
{ {
Context.CurrentBlock.CodeGenerator = new TemplateBlockCodeGenerator(); Context.CurrentBlock.ChunkGenerator = new TemplateBlockChunkGenerator();
PutCurrentBack(); PutCurrentBack();
OtherParserBlock(); OtherParserBlock();
} }

View File

@ -5,7 +5,7 @@ using System;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Razor.Editor; using Microsoft.AspNet.Razor.Editor;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Tokenizer; using Microsoft.AspNet.Razor.Tokenizer;
@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Razor.Parser
protected override bool CanRewrite(Block block) protected override bool CanRewrite(Block block)
{ {
var gen = block.CodeGenerator as AttributeBlockCodeGenerator; var gen = block.ChunkGenerator as AttributeBlockChunkGenerator;
return gen != null && block.Children.Any() && block.Children.All(IsLiteralAttributeValue); return gen != null && block.Children.Any() && block.Children.All(IsLiteralAttributeValue);
} }
@ -44,12 +44,12 @@ namespace Microsoft.AspNet.Razor.Parser
var span = node as Span; var span = node as Span;
Debug.Assert(span != null); Debug.Assert(span != null);
var litGen = span.CodeGenerator as LiteralAttributeCodeGenerator; var litGen = span.ChunkGenerator as LiteralAttributeChunkGenerator;
return span != null && return span != null &&
((litGen != null && litGen.ValueGenerator == null) || ((litGen != null && litGen.ValueGenerator == null) ||
span.CodeGenerator == SpanCodeGenerator.Null || span.ChunkGenerator == SpanChunkGenerator.Null ||
span.CodeGenerator is MarkupCodeGenerator); span.ChunkGenerator is MarkupChunkGenerator);
} }
} }
} }

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Razor.Editor; using Microsoft.AspNet.Razor.Editor;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Text;
using Microsoft.AspNet.Razor.Tokenizer.Symbols; using Microsoft.AspNet.Razor.Tokenizer.Symbols;
@ -50,11 +50,11 @@ namespace Microsoft.AspNet.Razor.Parser
Assert(HtmlSymbolType.Transition); Assert(HtmlSymbolType.Transition);
AcceptAndMoveNext(); AcceptAndMoveNext();
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None; Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None;
Span.CodeGenerator = SpanCodeGenerator.Null; Span.ChunkGenerator = SpanChunkGenerator.Null;
Output(SpanKind.Transition); Output(SpanKind.Transition);
if (At(HtmlSymbolType.Transition)) if (At(HtmlSymbolType.Transition))
{ {
Span.CodeGenerator = SpanCodeGenerator.Null; Span.ChunkGenerator = SpanChunkGenerator.Null;
AcceptAndMoveNext(); AcceptAndMoveNext();
Output(SpanKind.MetaCode); Output(SpanKind.MetaCode);
} }
@ -71,7 +71,7 @@ namespace Microsoft.AspNet.Razor.Parser
private void DefaultMarkupSpan(SpanBuilder span) private void DefaultMarkupSpan(SpanBuilder span)
{ {
span.CodeGenerator = new MarkupCodeGenerator(); span.ChunkGenerator = new MarkupChunkGenerator();
span.EditHandler = new SpanEditHandler(Language.TokenizeString, AcceptedCharacters.Any); span.EditHandler = new SpanEditHandler(Language.TokenizeString, AcceptedCharacters.Any);
} }
@ -85,7 +85,7 @@ namespace Microsoft.AspNet.Razor.Parser
// The first part (left) is added to this span and we return a MetaCode span // The first part (left) is added to this span and we return a MetaCode span
Accept(split.Item1); Accept(split.Item1);
Span.CodeGenerator = SpanCodeGenerator.Null; Span.ChunkGenerator = SpanChunkGenerator.Null;
Output(SpanKind.MetaCode); Output(SpanKind.MetaCode);
if (split.Item2 != null) if (split.Item2 != null)
{ {
@ -368,7 +368,7 @@ namespace Microsoft.AspNet.Razor.Parser
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None; Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None;
} }
Span.CodeGenerator = SpanCodeGenerator.Null; Span.ChunkGenerator = SpanChunkGenerator.Null;
CompleteTagBlockWithSpan(tagBlockWrapper, Span.EditHandler.AcceptedCharacters, SpanKind.Transition); CompleteTagBlockWithSpan(tagBlockWrapper, Span.EditHandler.AcceptedCharacters, SpanKind.Transition);
@ -524,7 +524,7 @@ namespace Microsoft.AspNet.Razor.Parser
if (attributeCanBeConditional) if (attributeCanBeConditional)
{ {
Span.CodeGenerator = SpanCodeGenerator.Null; // The block code generator will render the prefix Span.ChunkGenerator = SpanChunkGenerator.Null; // The block chunk generator will render the prefix
Output(SpanKind.Markup); Output(SpanKind.Markup);
// Read the values // Read the values
@ -543,12 +543,13 @@ namespace Microsoft.AspNet.Razor.Parser
if (Span.Symbols.Count > 0) if (Span.Symbols.Count > 0)
{ {
Span.CodeGenerator = SpanCodeGenerator.Null; // Again, block code generator will render the suffix // Again, block chunk generator will render the suffix
Span.ChunkGenerator = SpanChunkGenerator.Null;
Output(SpanKind.Markup); Output(SpanKind.Markup);
} }
// Create the block code generator // Create the block chunk generator
Context.CurrentBlock.CodeGenerator = new AttributeBlockCodeGenerator( Context.CurrentBlock.ChunkGenerator = new AttributeBlockChunkGenerator(
name, prefix, suffix); name, prefix, suffix);
} }
else else
@ -585,13 +586,13 @@ namespace Microsoft.AspNet.Razor.Parser
Accept(prefix); Accept(prefix);
// Render a single "@" in place of "@@". // Render a single "@" in place of "@@".
Span.CodeGenerator = new LiteralAttributeCodeGenerator( Span.ChunkGenerator = new LiteralAttributeChunkGenerator(
prefix.GetContent(prefixStart), prefix.GetContent(prefixStart),
new LocationTagged<string>(CurrentSymbol.GetContent(), CurrentLocation)); new LocationTagged<string>(CurrentSymbol.GetContent(), CurrentLocation));
AcceptAndMoveNext(); AcceptAndMoveNext();
Output(SpanKind.Markup, AcceptedCharacters.None); Output(SpanKind.Markup, AcceptedCharacters.None);
Span.CodeGenerator = SpanCodeGenerator.Null; Span.ChunkGenerator = SpanChunkGenerator.Null;
AcceptAndMoveNext(); AcceptAndMoveNext();
Output(SpanKind.Markup, AcceptedCharacters.None); Output(SpanKind.Markup, AcceptedCharacters.None);
} }
@ -602,14 +603,14 @@ namespace Microsoft.AspNet.Razor.Parser
var valueStart = CurrentLocation; var valueStart = CurrentLocation;
PutCurrentBack(); PutCurrentBack();
// Output the prefix but as a null-span. DynamicAttributeBlockCodeGenerator will render it // Output the prefix but as a null-span. DynamicAttributeBlockChunkGenerator will render it
Span.CodeGenerator = SpanCodeGenerator.Null; Span.ChunkGenerator = SpanChunkGenerator.Null;
// Dynamic value, start a new block and set the code generator // Dynamic value, start a new block and set the chunk generator
using (Context.StartBlock(BlockType.Markup)) using (Context.StartBlock(BlockType.Markup))
{ {
Context.CurrentBlock.CodeGenerator = Context.CurrentBlock.ChunkGenerator =
new DynamicAttributeBlockCodeGenerator(prefix.GetContent(prefixStart), valueStart); new DynamicAttributeBlockChunkGenerator(prefix.GetContent(prefixStart), valueStart);
OtherParserBlock(); OtherParserBlock();
} }
@ -625,9 +626,9 @@ namespace Microsoft.AspNet.Razor.Parser
// Virtual Path value // Virtual Path value
var valueStart = CurrentLocation; var valueStart = CurrentLocation;
VirtualPath(); VirtualPath();
Span.CodeGenerator = new LiteralAttributeCodeGenerator( Span.ChunkGenerator = new LiteralAttributeChunkGenerator(
prefix.GetContent(prefixStart), prefix.GetContent(prefixStart),
new LocationTagged<SpanCodeGenerator>(new ResolveUrlCodeGenerator(), valueStart)); new LocationTagged<SpanChunkGenerator>(new ResolveUrlChunkGenerator(), valueStart));
} }
else else
{ {
@ -644,7 +645,7 @@ namespace Microsoft.AspNet.Razor.Parser
// but for now that's ok) // but for now that's ok)
!IsEndOfAttributeValue(quote, sym)); !IsEndOfAttributeValue(quote, sym));
Accept(value); Accept(value);
Span.CodeGenerator = new LiteralAttributeCodeGenerator(prefix.GetContent(prefixStart), value.GetContent(prefixStart)); Span.ChunkGenerator = new LiteralAttributeChunkGenerator(prefix.GetContent(prefixStart), value.GetContent(prefixStart));
} }
Output(SpanKind.Markup); Output(SpanKind.Markup);
} }
@ -770,7 +771,7 @@ namespace Microsoft.AspNet.Razor.Parser
string.Equals(tag.Item1.Content, SyntaxConstants.TextTagName, StringComparison.OrdinalIgnoreCase)) string.Equals(tag.Item1.Content, SyntaxConstants.TextTagName, StringComparison.OrdinalIgnoreCase))
{ {
Output(SpanKind.Markup); Output(SpanKind.Markup);
Span.CodeGenerator = SpanCodeGenerator.Null; Span.ChunkGenerator = SpanChunkGenerator.Null;
Accept(_bufferedOpenAngle); Accept(_bufferedOpenAngle);
Assert(HtmlSymbolType.Text); Assert(HtmlSymbolType.Text);
@ -1058,7 +1059,7 @@ namespace Microsoft.AspNet.Razor.Parser
// Accept and mark the whitespace at the end of a <text> tag as code. // Accept and mark the whitespace at the end of a <text> tag as code.
AcceptWhile(HtmlSymbolType.WhiteSpace); AcceptWhile(HtmlSymbolType.WhiteSpace);
Span.CodeGenerator = new StatementCodeGenerator(); Span.ChunkGenerator = new StatementChunkGenerator();
Output(SpanKind.Code); Output(SpanKind.Code);
} }
else else

View File

@ -3,7 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Tokenizer; using Microsoft.AspNet.Razor.Tokenizer;
using Microsoft.AspNet.Razor.Tokenizer.Symbols; using Microsoft.AspNet.Razor.Tokenizer.Symbols;
@ -51,7 +51,7 @@ namespace Microsoft.AspNet.Razor.Parser
public override void BuildSpan(SpanBuilder span, SourceLocation start, string content) public override void BuildSpan(SpanBuilder span, SourceLocation start, string content)
{ {
span.Kind = SpanKind.Markup; span.Kind = SpanKind.Markup;
span.CodeGenerator = new MarkupCodeGenerator(); span.ChunkGenerator = new MarkupChunkGenerator();
base.BuildSpan(span, start, content); base.BuildSpan(span, start, content);
} }
@ -96,7 +96,7 @@ namespace Microsoft.AspNet.Razor.Parser
} }
Output(SpanKind.Markup); Output(SpanKind.Markup);
Accept(transition); Accept(transition);
Span.CodeGenerator = SpanCodeGenerator.Null; Span.ChunkGenerator = SpanChunkGenerator.Null;
Output(SpanKind.Markup); Output(SpanKind.Markup);
AcceptAndMoveNext(); AcceptAndMoveNext();
continue; // while continue; // while
@ -212,7 +212,7 @@ namespace Microsoft.AspNet.Razor.Parser
AcceptAndMoveNext(); AcceptAndMoveNext();
// Setup the metacode span that we will be outputing. // Setup the metacode span that we will be outputing.
Span.CodeGenerator = SpanCodeGenerator.Null; Span.ChunkGenerator = SpanChunkGenerator.Null;
Output(SpanKind.MetaCode, AcceptedCharacters.None); Output(SpanKind.MetaCode, AcceptedCharacters.None);
} }
} }

View File

@ -3,7 +3,7 @@
using System; using System;
using System.Linq; using System.Linq;
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.Razor.Parser namespace Microsoft.AspNet.Razor.Parser
@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Razor.Parser
protected override bool CanRewrite(Span span) protected override bool CanRewrite(Span span)
{ {
return span.Kind == SpanKind.Markup && span.CodeGenerator is MarkupCodeGenerator; return span.Kind == SpanKind.Markup && span.ChunkGenerator is MarkupChunkGenerator;
} }
protected override SyntaxTreeNode RewriteSpan(BlockBuilder parent, Span span) protected override SyntaxTreeNode RewriteSpan(BlockBuilder parent, Span span)

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Text;
using Microsoft.Internal.Web.Utils; using Microsoft.Internal.Web.Utils;
@ -15,12 +15,12 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
public class Block : SyntaxTreeNode public class Block : SyntaxTreeNode
{ {
public Block(BlockBuilder source) public Block(BlockBuilder source)
: this(source.Type, source.Children, source.CodeGenerator) : this(source.Type, source.Children, source.ChunkGenerator)
{ {
source.Reset(); source.Reset();
} }
protected Block(BlockType? type, IEnumerable<SyntaxTreeNode> contents, IBlockCodeGenerator generator) protected Block(BlockType? type, IEnumerable<SyntaxTreeNode> contents, IParentChunkGenerator generator)
{ {
if (type == null) if (type == null)
{ {
@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
Type = type.Value; Type = type.Value;
Children = contents; Children = contents;
CodeGenerator = generator; ChunkGenerator = generator;
foreach (SyntaxTreeNode node in Children) foreach (SyntaxTreeNode node in Children)
{ {
@ -38,10 +38,10 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
} }
// A Test constructor // A Test constructor
internal Block(BlockType type, IEnumerable<SyntaxTreeNode> contents, IBlockCodeGenerator generator) internal Block(BlockType type, IEnumerable<SyntaxTreeNode> contents, IParentChunkGenerator generator)
{ {
Type = type; Type = type;
CodeGenerator = generator; ChunkGenerator = generator;
Children = contents; Children = contents;
} }
@ -50,7 +50,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
public IEnumerable<SyntaxTreeNode> Children { get; } public IEnumerable<SyntaxTreeNode> Children { get; }
public IBlockCodeGenerator CodeGenerator { get; } public IParentChunkGenerator ChunkGenerator { get; }
public override bool IsBlock public override bool IsBlock
{ {
@ -105,7 +105,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
public override string ToString() public override string ToString()
{ {
return string.Format(CultureInfo.CurrentCulture, "{0} Block at {1}::{2} (Gen:{3})", Type, Start, Length, CodeGenerator); return string.Format(CultureInfo.CurrentCulture, "{0} Block at {1}::{2} (Gen:{3})", Type, Start, Length, ChunkGenerator);
} }
public override bool Equals(object obj) public override bool Equals(object obj)
@ -113,7 +113,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
var other = obj as Block; var other = obj as Block;
return other != null && return other != null &&
Type == other.Type && Type == other.Type &&
Equals(CodeGenerator, other.CodeGenerator) && Equals(ChunkGenerator, other.ChunkGenerator) &&
ChildrenEqual(Children, other.Children); ChildrenEqual(Children, other.Children);
} }
@ -121,7 +121,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
{ {
return HashCodeCombiner.Start() return HashCodeCombiner.Start()
.Add(Type) .Add(Type)
.Add(CodeGenerator) .Add(ChunkGenerator)
.Add(Children) .Add(Children)
.CombinedHash; .CombinedHash;
} }

View File

@ -3,7 +3,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks.Generators;
namespace Microsoft.AspNet.Razor.Parser.SyntaxTree namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
{ {
@ -18,13 +18,13 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
{ {
Type = original.Type; Type = original.Type;
Children = new List<SyntaxTreeNode>(original.Children); Children = new List<SyntaxTreeNode>(original.Children);
CodeGenerator = original.CodeGenerator; ChunkGenerator = original.ChunkGenerator;
} }
[SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods", Justification = "Type is the most appropriate name for this property and there is little chance of confusion with GetType")] [SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods", Justification = "Type is the most appropriate name for this property and there is little chance of confusion with GetType")]
public BlockType? Type { get; set; } public BlockType? Type { get; set; }
public IList<SyntaxTreeNode> Children { get; private set; } public IList<SyntaxTreeNode> Children { get; private set; }
public IBlockCodeGenerator CodeGenerator { get; set; } public IParentChunkGenerator ChunkGenerator { get; set; }
public virtual Block Build() public virtual Block Build()
{ {
@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
{ {
Type = null; Type = null;
Children = new List<SyntaxTreeNode>(); Children = new List<SyntaxTreeNode>();
CodeGenerator = BlockCodeGenerator.Null; ChunkGenerator = ParentChunkGenerator.Null;
} }
} }
} }

View File

@ -7,7 +7,7 @@ using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Microsoft.AspNet.Razor.Editor; using Microsoft.AspNet.Razor.Editor;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Text;
using Microsoft.AspNet.Razor.Tokenizer.Symbols; using Microsoft.AspNet.Razor.Tokenizer.Symbols;
@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
public Span Next { get; protected internal set; } public Span Next { get; protected internal set; }
public SpanEditHandler EditHandler { get; protected set; } public SpanEditHandler EditHandler { get; protected set; }
public ISpanCodeGenerator CodeGenerator { get; protected set; } public ISpanChunkGenerator ChunkGenerator { get; protected set; }
public override bool IsBlock public override bool IsBlock
{ {
@ -64,7 +64,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
Kind = builder.Kind; Kind = builder.Kind;
Symbols = builder.Symbols; Symbols = builder.Symbols;
EditHandler = builder.EditHandler; EditHandler = builder.EditHandler;
CodeGenerator = builder.CodeGenerator ?? SpanCodeGenerator.Null; ChunkGenerator = builder.ChunkGenerator ?? SpanChunkGenerator.Null;
_start = builder.Start; _start = builder.Start;
// Since we took references to the values in SpanBuilder, clear its references out // Since we took references to the values in SpanBuilder, clear its references out
@ -94,7 +94,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
builder.Append(EditHandler.ToString()); builder.Append(EditHandler.ToString());
builder.Append(">"); builder.Append(">");
builder.Append(" Gen: <"); builder.Append(" Gen: <");
builder.Append(CodeGenerator.ToString()); builder.Append(ChunkGenerator.ToString());
builder.Append("> {"); builder.Append("> {");
builder.Append(string.Join(";", Symbols.GroupBy(sym => sym.GetType()).Select(grp => string.Concat(grp.Key.Name, ":", grp.Count())))); builder.Append(string.Join(";", Symbols.GroupBy(sym => sym.GetType()).Select(grp => string.Concat(grp.Key.Name, ":", grp.Count()))));
builder.Append("}"); builder.Append("}");
@ -144,7 +144,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
return other != null && return other != null &&
Kind.Equals(other.Kind) && Kind.Equals(other.Kind) &&
EditHandler.Equals(other.EditHandler) && EditHandler.Equals(other.EditHandler) &&
CodeGenerator.Equals(other.CodeGenerator) && ChunkGenerator.Equals(other.ChunkGenerator) &&
Symbols.SequenceEqual(other.Symbols); Symbols.SequenceEqual(other.Symbols);
} }

View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Razor.Editor; using Microsoft.AspNet.Razor.Editor;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Text;
using Microsoft.AspNet.Razor.Tokenizer.Symbols; using Microsoft.AspNet.Razor.Tokenizer.Symbols;
@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
Kind = original.Kind; Kind = original.Kind;
_symbols = new List<ISymbol>(original.Symbols); _symbols = new List<ISymbol>(original.Symbols);
EditHandler = original.EditHandler; EditHandler = original.EditHandler;
CodeGenerator = original.CodeGenerator; ChunkGenerator = original.ChunkGenerator;
Start = original.Start; Start = original.Start;
} }
@ -39,13 +39,13 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
} }
public SpanEditHandler EditHandler { get; set; } public SpanEditHandler EditHandler { get; set; }
public ISpanCodeGenerator CodeGenerator { get; set; } public ISpanChunkGenerator ChunkGenerator { get; set; }
public void Reset() public void Reset()
{ {
_symbols = new List<ISymbol>(); _symbols = new List<ISymbol>();
EditHandler = SpanEditHandler.CreateDefault(s => Enumerable.Empty<ISymbol>()); EditHandler = SpanEditHandler.CreateDefault(s => Enumerable.Empty<ISymbol>());
CodeGenerator = SpanCodeGenerator.Null; ChunkGenerator = SpanChunkGenerator.Null;
Start = SourceLocation.Zero; Start = SourceLocation.Zero;
} }

View File

@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers
/// <param name="source">A <see cref="TagHelperBlockBuilder"/> used to construct a valid /// <param name="source">A <see cref="TagHelperBlockBuilder"/> used to construct a valid
/// <see cref="TagHelperBlock"/>.</param> /// <see cref="TagHelperBlock"/>.</param>
public TagHelperBlock(TagHelperBlockBuilder source) public TagHelperBlock(TagHelperBlockBuilder source)
: base(source.Type, source.Children, source.CodeGenerator) : base(source.Type, source.Children, source.ChunkGenerator)
{ {
TagName = source.TagName; TagName = source.TagName;
Descriptors = source.Descriptors; Descriptors = source.Descriptors;
@ -103,12 +103,12 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers
{ {
return string.Format(CultureInfo.CurrentCulture, return string.Format(CultureInfo.CurrentCulture,
"'{0}' (Attrs: {1}) Tag Helper Block at {2}::{3} (Gen:{4})", "'{0}' (Attrs: {1}) Tag Helper Block at {2}::{3} (Gen:{4})",
TagName, Attributes.Count, Start, Length, CodeGenerator); TagName, Attributes.Count, Start, Length, ChunkGenerator);
} }
/// <summary> /// <summary>
/// Determines whether two <see cref="TagHelperBlock"/>s are equal by comparing the <see cref="TagName"/>, /// Determines whether two <see cref="TagHelperBlock"/>s are equal by comparing the <see cref="TagName"/>,
/// <see cref="Attributes"/>, <see cref="Block.Type"/>, <see cref="Block.CodeGenerator"/> and /// <see cref="Attributes"/>, <see cref="Block.Type"/>, <see cref="Block.ChunkGenerator"/> and
/// <see cref="Block.Children"/>. /// <see cref="Block.Children"/>.
/// </summary> /// </summary>
/// <param name="other">The <see cref="TagHelperBlock"/> to check equality against.</param> /// <param name="other">The <see cref="TagHelperBlock"/> to check equality against.</param>

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.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.AspNet.Razor.TagHelpers;
@ -52,7 +52,7 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers
Descriptors = descriptors; Descriptors = descriptors;
Attributes = new List<KeyValuePair<string, SyntaxTreeNode>>(attributes); Attributes = new List<KeyValuePair<string, SyntaxTreeNode>>(attributes);
Type = BlockType.Tag; Type = BlockType.Tag;
CodeGenerator = new TagHelperCodeGenerator(descriptors); ChunkGenerator = new TagHelperChunkGenerator(descriptors);
} }
// Internal for testing // Internal for testing
@ -66,7 +66,7 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers
SelfClosing = selfClosing; SelfClosing = selfClosing;
Attributes = attributes; Attributes = attributes;
Type = BlockType.Tag; Type = BlockType.Tag;
CodeGenerator = new TagHelperCodeGenerator(tagHelperDescriptors: null); ChunkGenerator = new TagHelperChunkGenerator(tagHelperDescriptors: null);
// Children is IList, no AddRange // Children is IList, no AddRange
foreach (var child in children) foreach (var child in children)

View File

@ -4,7 +4,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.AspNet.Razor.Tokenizer.Symbols; using Microsoft.AspNet.Razor.Tokenizer.Symbols;
@ -126,7 +126,7 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers.Internal
var afterEquals = false; var afterEquals = false;
var builder = new SpanBuilder var builder = new SpanBuilder
{ {
CodeGenerator = span.CodeGenerator, ChunkGenerator = span.ChunkGenerator,
EditHandler = span.EditHandler, EditHandler = span.EditHandler,
Kind = span.Kind Kind = span.Kind
}; };
@ -322,9 +322,9 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers.Internal
} }
} }
// We need to rebuild the code generators of the builder and its children (this is needed to // We need to rebuild the chunk generators of the builder and its children (this is needed to
// ensure we don't do special attribute code generation since this is a tag helper). // ensure we don't do special attribute chunk generation since this is a tag helper).
block = RebuildCodeGenerators(builder.Build()); block = RebuildChunkGenerators(builder.Build());
// If there's only 1 child at this point its value could be a simple markup span (treated differently than // If there's only 1 child at this point its value could be a simple markup span (treated differently than
// block level elements for attributes). // block level elements for attributes).
@ -348,16 +348,16 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers.Internal
return result; return result;
} }
private static Block RebuildCodeGenerators(Block block) private static Block RebuildChunkGenerators(Block block)
{ {
var builder = new BlockBuilder(block); var builder = new BlockBuilder(block);
var isDynamic = builder.CodeGenerator is DynamicAttributeBlockCodeGenerator; var isDynamic = builder.ChunkGenerator is DynamicAttributeBlockChunkGenerator;
// We don't want any attribute specific logic here, null out the block code generator. // We don't want any attribute specific logic here, null out the block chunk generator.
if (isDynamic || builder.CodeGenerator is AttributeBlockCodeGenerator) if (isDynamic || builder.ChunkGenerator is AttributeBlockChunkGenerator)
{ {
builder.CodeGenerator = BlockCodeGenerator.Null; builder.ChunkGenerator = ParentChunkGenerator.Null;
} }
for (var i = 0; i < builder.Children.Count; i++) for (var i = 0; i < builder.Children.Count; i++)
@ -367,40 +367,40 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers.Internal
if (child.IsBlock) if (child.IsBlock)
{ {
// The child is a block, recurse down into the block to rebuild its children // The child is a block, recurse down into the block to rebuild its children
builder.Children[i] = RebuildCodeGenerators((Block)child); builder.Children[i] = RebuildChunkGenerators((Block)child);
} }
else else
{ {
var childSpan = (Span)child; var childSpan = (Span)child;
ISpanCodeGenerator newCodeGenerator = null; ISpanChunkGenerator newChunkGenerator = null;
var literalGenerator = childSpan.CodeGenerator as LiteralAttributeCodeGenerator; var literalGenerator = childSpan.ChunkGenerator as LiteralAttributeChunkGenerator;
if (literalGenerator != null) if (literalGenerator != null)
{ {
if (literalGenerator.ValueGenerator == null || literalGenerator.ValueGenerator.Value == null) if (literalGenerator.ValueGenerator == null || literalGenerator.ValueGenerator.Value == null)
{ {
newCodeGenerator = new MarkupCodeGenerator(); newChunkGenerator = new MarkupChunkGenerator();
} }
else else
{ {
newCodeGenerator = literalGenerator.ValueGenerator.Value; newChunkGenerator = literalGenerator.ValueGenerator.Value;
} }
} }
else if (isDynamic && childSpan.CodeGenerator == SpanCodeGenerator.Null) else if (isDynamic && childSpan.ChunkGenerator == SpanChunkGenerator.Null)
{ {
// Usually the dynamic code generator handles rendering the null code generators underneath // Usually the dynamic chunk generator handles creating the null chunk generators underneath
// it. This doesn't make sense in terms of tag helpers though, we need to change null code // it. This doesn't make sense in terms of tag helpers though, we need to change null code
// generators to markup code generators. // generators to markup chunk generators.
newCodeGenerator = new MarkupCodeGenerator(); newChunkGenerator = new MarkupChunkGenerator();
} }
// If we have a new code generator we'll need to re-build the child // If we have a new chunk generator we'll need to re-build the child
if (newCodeGenerator != null) if (newChunkGenerator != null)
{ {
var childSpanBuilder = new SpanBuilder(childSpan) var childSpanBuilder = new SpanBuilder(childSpan)
{ {
CodeGenerator = newCodeGenerator ChunkGenerator = newChunkGenerator
}; };
builder.Children[i] = childSpanBuilder.Build(); builder.Children[i] = childSpanBuilder.Build();

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.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks.Generators;
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.Internal; using Microsoft.Framework.Internal;
@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers
{ {
/// <summary> /// <summary>
/// A <see cref="ParserVisitor"/> that generates <see cref="TagHelperDescriptor"/>s from /// A <see cref="ParserVisitor"/> that generates <see cref="TagHelperDescriptor"/>s from
/// tag helper code generators in a Razor document. /// tag helper chunk generators in a Razor document.
/// </summary> /// </summary>
public class TagHelperDirectiveSpanVisitor : ParserVisitor public class TagHelperDirectiveSpanVisitor : ParserVisitor
{ {
@ -57,30 +57,30 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers
public override void VisitSpan(Span span) public override void VisitSpan(Span span)
{ {
// We're only interested in spans with an AddOrRemoveTagHelperCodeGenerator. // We're only interested in spans with an AddOrRemoveTagHelperChunkGenerator.
if (span.CodeGenerator is AddOrRemoveTagHelperCodeGenerator) if (span.ChunkGenerator is AddOrRemoveTagHelperChunkGenerator)
{ {
var codeGenerator = (AddOrRemoveTagHelperCodeGenerator)span.CodeGenerator; var chunkGenerator = (AddOrRemoveTagHelperChunkGenerator)span.ChunkGenerator;
var directive = var directive =
codeGenerator.RemoveTagHelperDescriptors ? chunkGenerator.RemoveTagHelperDescriptors ?
TagHelperDirectiveType.RemoveTagHelper : TagHelperDirectiveType.RemoveTagHelper :
TagHelperDirectiveType.AddTagHelper; TagHelperDirectiveType.AddTagHelper;
var directiveDescriptor = new TagHelperDirectiveDescriptor( var directiveDescriptor = new TagHelperDirectiveDescriptor(
codeGenerator.LookupText, chunkGenerator.LookupText,
span.Start, span.Start,
directive); directive);
_directiveDescriptors.Add(directiveDescriptor); _directiveDescriptors.Add(directiveDescriptor);
} }
else if (span.CodeGenerator is TagHelperPrefixDirectiveCodeGenerator) else if (span.ChunkGenerator is TagHelperPrefixDirectiveChunkGenerator)
{ {
var codeGenerator = (TagHelperPrefixDirectiveCodeGenerator)span.CodeGenerator; var chunkGenerator = (TagHelperPrefixDirectiveChunkGenerator)span.ChunkGenerator;
var directiveDescriptor = new TagHelperDirectiveDescriptor( var directiveDescriptor = new TagHelperDirectiveDescriptor(
codeGenerator.Prefix, chunkGenerator.Prefix,
span.Start, span.Start,
TagHelperDirectiveType.TagHelperPrefix); TagHelperDirectiveType.TagHelperPrefix);

View File

@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers.Internal
TrackBlock(new BlockBuilder TrackBlock(new BlockBuilder
{ {
Type = input.Type, Type = input.Type,
CodeGenerator = input.CodeGenerator ChunkGenerator = input.ChunkGenerator
}); });
var activeTagHelpers = _trackerStack.Count; var activeTagHelpers = _trackerStack.Count;

View File

@ -7,7 +7,7 @@ using System.Diagnostics;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Razor.Editor; using Microsoft.AspNet.Razor.Editor;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Tokenizer; using Microsoft.AspNet.Razor.Tokenizer;
using Microsoft.AspNet.Razor.Tokenizer.Symbols; using Microsoft.AspNet.Razor.Tokenizer.Symbols;
@ -487,7 +487,7 @@ namespace Microsoft.AspNet.Razor.Parser
private void CommentSpanConfig(SpanBuilder span) private void CommentSpanConfig(SpanBuilder span)
{ {
span.CodeGenerator = SpanCodeGenerator.Null; span.ChunkGenerator = SpanChunkGenerator.Null;
span.EditHandler = SpanEditHandler.CreateDefault(Language.TokenizeString); span.EditHandler = SpanEditHandler.CreateDefault(Language.TokenizeString);
} }
@ -504,7 +504,7 @@ namespace Microsoft.AspNet.Razor.Parser
{ {
using (Context.StartBlock(BlockType.Comment)) using (Context.StartBlock(BlockType.Comment))
{ {
Context.CurrentBlock.CodeGenerator = new RazorCommentCodeGenerator(); Context.CurrentBlock.ChunkGenerator = new RazorCommentChunkGenerator();
var start = CurrentLocation; var start = CurrentLocation;
Expected(KnownSymbolType.CommentStart); Expected(KnownSymbolType.CommentStart);

View File

@ -1287,7 +1287,7 @@ namespace Microsoft.AspNet.Razor
} }
/// <summary> /// <summary>
/// A TagHelperCodeGenerator must only be used with TagHelperBlocks. /// A TagHelperChunkGenerator must only be used with TagHelperBlocks.
/// </summary> /// </summary>
internal static string TagHelpers_TagHelperCodeGeneartorMustBeAssociatedWithATagHelperBlock internal static string TagHelpers_TagHelperCodeGeneartorMustBeAssociatedWithATagHelperBlock
{ {
@ -1295,7 +1295,7 @@ namespace Microsoft.AspNet.Razor
} }
/// <summary> /// <summary>
/// A TagHelperCodeGenerator must only be used with TagHelperBlocks. /// A TagHelperChunkGenerator must only be used with TagHelperBlocks.
/// </summary> /// </summary>
internal static string FormatTagHelpers_TagHelperCodeGeneartorMustBeAssociatedWithATagHelperBlock() internal static string FormatTagHelpers_TagHelperCodeGeneartorMustBeAssociatedWithATagHelperBlock()
{ {

View File

@ -3,8 +3,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Generator.Compiler; using Microsoft.AspNet.Razor.CodeGeneration;
using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser;
namespace Microsoft.AspNet.Razor namespace Microsoft.AspNet.Razor
@ -50,10 +50,10 @@ namespace Microsoft.AspNet.Razor
public abstract ParserBase CreateCodeParser(); public abstract ParserBase CreateCodeParser();
/// <summary> /// <summary>
/// Constructs the code generator. Must return a new instance on EVERY call to ensure thread-safety /// Constructs the chunk generator. Must return a new instance on EVERY call to ensure thread-safety
/// </summary> /// </summary>
public abstract RazorCodeGenerator CreateCodeGenerator(string className, string rootNamespaceName, string sourceFileName, RazorEngineHost host); public abstract RazorChunkGenerator CreateChunkGenerator(string className, string rootNamespaceName, string sourceFileName, RazorEngineHost host);
public abstract CodeBuilder CreateCodeBuilder(CodeBuilderContext codeGeneratorContext); public abstract CodeBuilder CreateCodeBuilder(CodeBuilderContext chunkGeneratorContext);
} }
} }

View File

@ -4,8 +4,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Generator.Compiler; using Microsoft.AspNet.Razor.CodeGeneration;
using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Razor
/// * The default Base Class to inherit the generated class from /// * The default Base Class to inherit the generated class from
/// * The default Class Name and Namespace for the generated class (can be overridden by parameters in RazorTemplateEngine.GeneratedCode) /// * The default Class Name and Namespace for the generated class (can be overridden by parameters in RazorTemplateEngine.GeneratedCode)
/// * The language of the code in a Razor page /// * The language of the code in a Razor page
/// * The markup, code parsers and code generators to use (the system will select defaults, but a Host gets a change to augment them) /// * The markup, code parsers and chunk generators to use (the system will select defaults, but a Host gets a change to augment them)
/// ** See DecorateNNN methods /// ** See DecorateNNN methods
/// * Additional code to add to the generated code (see PostProcessGeneratedCode) /// * Additional code to add to the generated code (see PostProcessGeneratedCode)
/// </remarks> /// </remarks>
@ -82,7 +82,7 @@ namespace Microsoft.AspNet.Razor
public virtual string DefaultBaseClass { get; set; } public virtual string DefaultBaseClass { get; set; }
/// <summary> /// <summary>
/// Indiciates if the parser and code generator should run in design-time mode /// Indicates if the parser and chunk generator should run in design-time mode
/// </summary> /// </summary>
public virtual bool DesignTimeMode { get; set; } public virtual bool DesignTimeMode { get; set; }
@ -194,13 +194,13 @@ namespace Microsoft.AspNet.Razor
} }
/// <summary> /// <summary>
/// Gets an instance of the code generator and is provided an opportunity to decorate or replace it /// Gets an instance of the chunk generator and is provided an opportunity to decorate or replace it
/// </summary> /// </summary>
/// <param name="incomingCodeGenerator">The code generator</param> /// <param name="incomingChunkGenerator">The chunk generator</param>
/// <returns>Either the same code generator, after modifications, or a different code generator</returns> /// <returns>Either the same chunk generator, after modifications, or a different chunk generator</returns>
public virtual RazorCodeGenerator DecorateCodeGenerator([NotNull] RazorCodeGenerator incomingCodeGenerator) public virtual RazorChunkGenerator DecorateChunkGenerator([NotNull] RazorChunkGenerator incomingChunkGenerator)
{ {
return incomingCodeGenerator; return incomingChunkGenerator;
} }
/// <summary> /// <summary>
@ -215,12 +215,12 @@ namespace Microsoft.AspNet.Razor
return incomingBuilder; return incomingBuilder;
} }
// If a user wants to modify the code generation process they do it via the DecorateCodeGenerator method which // If a user wants to modify the chunk generation process they do it via the DecorateChunkGenerator method
// is why this is internal. // which is why this is internal.
internal RazorCodeGenerator CreateCodeGenerator(string className, string rootNamespace, string sourceFileName) internal RazorChunkGenerator CreateChunkGenerator(string className, string rootNamespace, string sourceFileName)
{ {
return DecorateCodeGenerator( return DecorateChunkGenerator(
CodeLanguage.CreateCodeGenerator(className, rootNamespace, sourceFileName, host: this)); CodeLanguage.CreateChunkGenerator(className, rootNamespace, sourceFileName, host: this));
} }
} }
} }

Some files were not shown because too many files have changed in this diff Show More