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:
parent
b33bff1866
commit
5df9b52afe
|
|
@ -1,9 +1,8 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.CodeGeneration;
|
||||
using Microsoft.AspNet.Razor.Parser;
|
||||
#if NET45
|
||||
|
||||
|
|
@ -35,11 +34,11 @@ namespace Microsoft.AspNet.Razor
|
|||
}
|
||||
|
||||
/// <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>
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.Chunks
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="Chunk"/> used to look up <see cref="TagHelpers.TagHelperDescriptor"/>s.
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.Chunks
|
||||
{
|
||||
public class Chunk
|
||||
{
|
||||
|
|
@ -3,11 +3,11 @@
|
|||
|
||||
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>();
|
||||
}
|
||||
|
|
@ -4,20 +4,20 @@
|
|||
using System.Collections.Generic;
|
||||
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;
|
||||
|
||||
public CodeTreeBuilder()
|
||||
public ChunkTreeBuilder()
|
||||
{
|
||||
CodeTree = new CodeTree();
|
||||
_blockChain = new Stack<ChunkBlock>();
|
||||
ChunkTree = new ChunkTree();
|
||||
_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)
|
||||
{
|
||||
|
|
@ -27,13 +27,13 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
|||
chunk.Association = association;
|
||||
|
||||
// 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
|
||||
{
|
||||
_blockChain.Peek().Children.Add(chunk);
|
||||
_parentChain.Peek().Children.Add(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -148,30 +148,30 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
|||
}, 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
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 LocationTagged<string> Prefix { get; set; }
|
||||
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
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; }
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.Chunks
|
||||
{
|
||||
public class ExpressionBlockChunk : ChunkBlock
|
||||
public class ExpressionBlockChunk : ParentChunk
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.Chunks
|
||||
{
|
||||
public class ExpressionChunk : Chunk
|
||||
{
|
||||
|
|
@ -4,18 +4,18 @@
|
|||
using System;
|
||||
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;
|
||||
}
|
||||
|
||||
public string Namespace { get; }
|
||||
|
||||
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
||||
public override void GenerateChunk(Span target, ChunkGeneratorContext context)
|
||||
{
|
||||
var ns = Namespace;
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
ns = ns.Substring(1);
|
||||
}
|
||||
|
||||
context.CodeTreeBuilder.AddUsingChunk(ns, target);
|
||||
context.ChunkTreeBuilder.AddUsingChunk(ns, target);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
|
@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var other = obj as AddImportCodeGenerator;
|
||||
var other = obj as AddImportChunkGenerator;
|
||||
return other != null &&
|
||||
string.Equals(Namespace, other.Namespace, StringComparison.Ordinal);
|
||||
}
|
||||
|
|
@ -3,21 +3,21 @@
|
|||
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator
|
||||
namespace Microsoft.AspNet.Razor.Chunks.Generators
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="SpanCodeGenerator"/> responsible for generating <see cref="Compiler.AddTagHelperChunk"/>s and
|
||||
/// <see cref="Compiler.RemoveTagHelperChunk"/>s.
|
||||
/// A <see cref="SpanChunkGenerator"/> responsible for generating <see cref="AddTagHelperChunk"/>s and
|
||||
/// <see cref="RemoveTagHelperChunk"/>s.
|
||||
/// </summary>
|
||||
public class AddOrRemoveTagHelperCodeGenerator : SpanCodeGenerator
|
||||
public class AddOrRemoveTagHelperChunkGenerator : SpanChunkGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// Instantiates a new <see cref="AddOrRemoveTagHelperCodeGenerator"/>.
|
||||
/// Instantiates a new <see cref="AddOrRemoveTagHelperChunkGenerator"/>.
|
||||
/// </summary>
|
||||
/// <param name="lookupText">
|
||||
/// Text used to look up <see cref="TagHelpers.TagHelperDescriptor"/>s that should be added or removed.
|
||||
/// </param>
|
||||
public AddOrRemoveTagHelperCodeGenerator(bool removeTagHelperDescriptors, string lookupText)
|
||||
public AddOrRemoveTagHelperChunkGenerator(bool removeTagHelperDescriptors, string lookupText)
|
||||
{
|
||||
RemoveTagHelperDescriptors = removeTagHelperDescriptors;
|
||||
LookupText = lookupText;
|
||||
|
|
@ -32,28 +32,28 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
/// <summary>
|
||||
/// Whether we want to remove <see cref="TagHelpers.TagHelperDescriptor"/>s from the Razor page.
|
||||
/// </summary>
|
||||
/// <remarks>If <c>true</c> <see cref="GenerateCode"/> generates <see cref="Compiler.AddTagHelperChunk"/>s,
|
||||
/// <see cref="Compiler.RemoveTagHelperChunk"/>s otherwise.</remarks>
|
||||
/// <remarks>If <c>true</c> <see cref="GenerateChunk"/> generates <see cref="AddTagHelperChunk"/>s,
|
||||
/// <see cref="RemoveTagHelperChunk"/>s otherwise.</remarks>
|
||||
public bool RemoveTagHelperDescriptors { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Generates <see cref="Compiler.AddTagHelperChunk"/>s if <see cref="RemoveTagHelperDescriptors"/> is
|
||||
/// <c>true</c>, otherwise <see cref="Compiler.RemoveTagHelperChunk"/>s are generated.
|
||||
/// Generates <see cref="AddTagHelperChunk"/>s if <see cref="RemoveTagHelperDescriptors"/> is
|
||||
/// <c>true</c>, otherwise <see cref="RemoveTagHelperChunk"/>s are generated.
|
||||
/// </summary>
|
||||
/// <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 name="context">A <see cref="CodeGeneratorContext"/> instance that contains information about
|
||||
/// the current code generation process.</param>
|
||||
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
||||
/// <param name="context">A <see cref="ChunkGeneratorContext"/> instance that contains information about
|
||||
/// the current chunk generation process.</param>
|
||||
public override void GenerateChunk(Span target, ChunkGeneratorContext context)
|
||||
{
|
||||
if (RemoveTagHelperDescriptors)
|
||||
{
|
||||
context.CodeTreeBuilder.AddRemoveTagHelperChunk(LookupText, target);
|
||||
context.ChunkTreeBuilder.AddRemoveTagHelperChunk(LookupText, target);
|
||||
}
|
||||
else
|
||||
{
|
||||
context.CodeTreeBuilder.AddAddTagHelperChunk(LookupText, target);
|
||||
context.ChunkTreeBuilder.AddAddTagHelperChunk(LookupText, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,16 +3,15 @@
|
|||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.AspNet.Razor.Text;
|
||||
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;
|
||||
Prefix = prefix;
|
||||
|
|
@ -25,18 +24,18 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
|
||||
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.Prefix = Prefix;
|
||||
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()
|
||||
|
|
@ -46,7 +45,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var other = obj as AttributeBlockCodeGenerator;
|
||||
var other = obj as AttributeBlockChunkGenerator;
|
||||
return other != null &&
|
||||
string.Equals(other.Name, Name, StringComparison.Ordinal) &&
|
||||
Equals(other.Prefix, Prefix) &&
|
||||
|
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
|
@ -2,20 +2,19 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Globalization;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
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))
|
||||
{
|
||||
}
|
||||
|
||||
public DynamicAttributeBlockCodeGenerator(LocationTagged<string> prefix, SourceLocation valueStart)
|
||||
public DynamicAttributeBlockChunkGenerator(LocationTagged<string> prefix, SourceLocation valueStart)
|
||||
{
|
||||
Prefix = prefix;
|
||||
ValueStart = valueStart;
|
||||
|
|
@ -25,16 +24,16 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
|
||||
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.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()
|
||||
|
|
@ -44,7 +43,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var other = obj as DynamicAttributeBlockCodeGenerator;
|
||||
var other = obj as DynamicAttributeBlockChunkGenerator;
|
||||
return other != null &&
|
||||
Equals(other.Prefix, Prefix);
|
||||
}
|
||||
|
|
@ -1,28 +1,27 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
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()
|
||||
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,10 +3,10 @@
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,22 +2,21 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Globalization;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.AspNet.Razor.Text;
|
||||
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;
|
||||
ValueGenerator = valueGenerator;
|
||||
}
|
||||
|
||||
public LiteralAttributeCodeGenerator(LocationTagged<string> prefix, LocationTagged<string> value)
|
||||
public LiteralAttributeChunkGenerator(LocationTagged<string> prefix, LocationTagged<string> value)
|
||||
{
|
||||
Prefix = prefix;
|
||||
Value = value;
|
||||
|
|
@ -27,11 +26,11 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
|
||||
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.Value = Value;
|
||||
|
||||
|
|
@ -39,12 +38,12 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
{
|
||||
chunk.ValueLocation = ValueGenerator.Location;
|
||||
|
||||
ValueGenerator.Value.GenerateCode(target, context);
|
||||
ValueGenerator.Value.GenerateChunk(target, context);
|
||||
|
||||
chunk.ValueLocation = ValueGenerator.Location;
|
||||
}
|
||||
|
||||
context.CodeTreeBuilder.EndChunkBlock();
|
||||
context.ChunkTreeBuilder.EndParentChunk();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
|
@ -61,7 +60,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var other = obj as LiteralAttributeCodeGenerator;
|
||||
var other = obj as LiteralAttributeChunkGenerator;
|
||||
return other != null &&
|
||||
Equals(other.Prefix, Prefix) &&
|
||||
Equals(other.Value, Value) &&
|
||||
|
|
@ -3,13 +3,13 @@
|
|||
|
||||
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()
|
||||
|
|
@ -4,20 +4,20 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
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")]
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -6,13 +6,13 @@ using Microsoft.AspNet.Razor.Parser;
|
|||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
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,
|
||||
[NotNull] string rootNamespaceName,
|
||||
string sourceFileName,
|
||||
|
|
@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
public bool GenerateLinePragmas { get; set; }
|
||||
public bool DesignTimeMode { get; set; }
|
||||
|
||||
public CodeGeneratorContext Context
|
||||
public ChunkGeneratorContext Context
|
||||
{
|
||||
get
|
||||
{
|
||||
|
|
@ -51,24 +51,24 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
|
||||
public override void VisitStartBlock(Block block)
|
||||
{
|
||||
block.CodeGenerator.GenerateStartBlockCode(block, Context);
|
||||
block.ChunkGenerator.GenerateStartParentChunk(block, Context);
|
||||
}
|
||||
|
||||
public override void VisitEndBlock(Block block)
|
||||
{
|
||||
block.CodeGenerator.GenerateEndBlockCode(block, Context);
|
||||
block.ChunkGenerator.GenerateEndParentChunk(block, Context);
|
||||
}
|
||||
|
||||
public override void VisitSpan(Span span)
|
||||
{
|
||||
span.CodeGenerator.GenerateCode(span, Context);
|
||||
span.ChunkGenerator.GenerateChunk(span, Context);
|
||||
}
|
||||
|
||||
private void EnsureContextInitialized()
|
||||
{
|
||||
if (_context == null)
|
||||
{
|
||||
_context = new CodeGeneratorContext(Host,
|
||||
_context = new ChunkGeneratorContext(Host,
|
||||
ClassName,
|
||||
RootNamespaceName,
|
||||
SourceFileName,
|
||||
|
|
@ -77,7 +77,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
}
|
||||
}
|
||||
|
||||
protected virtual void Initialize(CodeGeneratorContext context)
|
||||
protected virtual void Initialize(ChunkGeneratorContext context)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -2,9 +2,9 @@
|
|||
// 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
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -3,21 +3,21 @@
|
|||
|
||||
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
|
||||
if (string.IsNullOrEmpty(context.Host.GeneratedClassContext.ResolveUrlMethodName))
|
||||
{
|
||||
// Nope, just use the default MarkupCodeGenerator behavior
|
||||
new MarkupCodeGenerator().GenerateCode(target, context);
|
||||
// Nope, just use the default MarkupChunkGenerator behavior
|
||||
new MarkupChunkGenerator().GenerateChunk(target, context);
|
||||
return;
|
||||
}
|
||||
|
||||
context.CodeTreeBuilder.AddResolveUrlChunk(target.Content, target);
|
||||
context.ChunkTreeBuilder.AddResolveUrlChunk(target.Content, target);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
|
@ -2,35 +2,34 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
var other = obj as SectionCodeGenerator;
|
||||
var other = obj as SectionChunkGenerator;
|
||||
return base.Equals(other) &&
|
||||
string.Equals(SectionName, other.SectionName, StringComparison.Ordinal);
|
||||
}
|
||||
|
|
@ -4,20 +4,20 @@
|
|||
using System;
|
||||
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;
|
||||
}
|
||||
|
||||
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()
|
||||
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var other = obj as SetBaseTypeCodeGenerator;
|
||||
var other = obj as SetBaseTypeChunkGenerator;
|
||||
return other != null &&
|
||||
string.Equals(BaseType, other.BaseType, StringComparison.Ordinal);
|
||||
}
|
||||
|
|
@ -4,16 +4,16 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
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")]
|
||||
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;
|
||||
}
|
||||
|
||||
private class NullSpanCodeGenerator : ISpanCodeGenerator
|
||||
private class NullSpanChunkGenerator : ISpanChunkGenerator
|
||||
{
|
||||
public void GenerateCode(Span target, CodeGeneratorContext context)
|
||||
public void GenerateChunk(Span target, ChunkGeneratorContext context)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -3,13 +3,13 @@
|
|||
|
||||
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()
|
||||
|
|
@ -4,27 +4,26 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.AspNet.Razor.Parser.TagHelpers;
|
||||
using Microsoft.AspNet.Razor.TagHelpers;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator
|
||||
namespace Microsoft.AspNet.Razor.Chunks.Generators
|
||||
{
|
||||
/// <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>
|
||||
public class TagHelperCodeGenerator : BlockCodeGenerator
|
||||
public class TagHelperChunkGenerator : ParentChunkGenerator
|
||||
{
|
||||
private IEnumerable<TagHelperDescriptor> _tagHelperDescriptors;
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a new <see cref="TagHelperCodeGenerator"/>.
|
||||
/// Instantiates a new <see cref="TagHelperChunkGenerator"/>.
|
||||
/// </summary>
|
||||
/// <param name="tagHelperDescriptors">
|
||||
/// <see cref="TagHelperDescriptor"/>s associated with the current HTML tag.
|
||||
/// </param>
|
||||
public TagHelperCodeGenerator(IEnumerable<TagHelperDescriptor> tagHelperDescriptors)
|
||||
public TagHelperChunkGenerator(IEnumerable<TagHelperDescriptor> tagHelperDescriptors)
|
||||
{
|
||||
_tagHelperDescriptors = tagHelperDescriptors;
|
||||
}
|
||||
|
|
@ -33,11 +32,11 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
/// Starts the generation of a <see cref="TagHelperChunk"/>.
|
||||
/// </summary>
|
||||
/// <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 name="context">A <see cref="CodeGeneratorContext"/> instance that contains information about
|
||||
/// the current code generation process.</param>
|
||||
public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context)
|
||||
/// <param name="context">A <see cref="ChunkGeneratorContext"/> instance that contains information about
|
||||
/// the current chunk generation process.</param>
|
||||
public override void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
|
||||
{
|
||||
var tagHelperBlock = target as TagHelperBlock;
|
||||
|
||||
|
|
@ -49,25 +48,25 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
|
||||
var attributes = new List<KeyValuePair<string, Chunk>>();
|
||||
|
||||
// We need to create a code generator to create chunks for each of the attributes.
|
||||
var codeGenerator = context.Host.CreateCodeGenerator(
|
||||
// We need to create a chunk generator to create chunks for each of the attributes.
|
||||
var chunkGenerator = context.Host.CreateChunkGenerator(
|
||||
context.ClassName,
|
||||
context.RootNamespace,
|
||||
context.SourceFile);
|
||||
|
||||
foreach (var attribute in tagHelperBlock.Attributes)
|
||||
{
|
||||
ChunkBlock attributeChunkValue = null;
|
||||
ParentChunk attributeChunkValue = null;
|
||||
|
||||
if (attribute.Value != null)
|
||||
{
|
||||
// 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();
|
||||
|
||||
attributeChunkValue = new ChunkBlock
|
||||
attributeChunkValue = new ParentChunk
|
||||
{
|
||||
Association = first?.Association,
|
||||
Children = chunks,
|
||||
|
|
@ -78,12 +77,12 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
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
|
||||
codeGenerator.Context.CodeTreeBuilder = new CodeTreeBuilder();
|
||||
chunkGenerator.Context.ChunkTreeBuilder = new ChunkTreeBuilder();
|
||||
}
|
||||
|
||||
var unprefixedTagName = tagHelperBlock.TagName.Substring(_tagHelperDescriptors.First().Prefix.Length);
|
||||
|
||||
context.CodeTreeBuilder.StartChunkBlock(
|
||||
context.ChunkTreeBuilder.StartParentChunk(
|
||||
new TagHelperChunk(
|
||||
unprefixedTagName,
|
||||
tagHelperBlock.SelfClosing,
|
||||
|
|
@ -95,16 +94,16 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
/// <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 name="context">A <see cref="CodeGeneratorContext"/> instance that contains information about
|
||||
/// the current code generation process.</param>
|
||||
public override void GenerateEndBlockCode(Block target, CodeGeneratorContext context)
|
||||
/// <param name="context">A <see cref="ChunkGeneratorContext"/> instance that contains information about
|
||||
/// the current chunk generation process.</param>
|
||||
public override void GenerateEndParentChunk(Block target, ChunkGeneratorContext context)
|
||||
{
|
||||
context.CodeTreeBuilder.EndChunkBlock();
|
||||
context.ChunkTreeBuilder.EndParentChunk();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,21 +3,21 @@
|
|||
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator
|
||||
namespace Microsoft.AspNet.Razor.Chunks.Generators
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="SpanCodeGenerator"/> responsible for generating
|
||||
/// <see cref="Compiler.TagHelperPrefixDirectiveChunk"/>s.
|
||||
/// A <see cref="SpanChunkGenerator"/> responsible for generating
|
||||
/// <see cref="TagHelperPrefixDirectiveChunk"/>s.
|
||||
/// </summary>
|
||||
public class TagHelperPrefixDirectiveCodeGenerator : SpanCodeGenerator
|
||||
public class TagHelperPrefixDirectiveChunkGenerator : SpanChunkGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// Instantiates a new <see cref="TagHelperPrefixDirectiveCodeGenerator"/>.
|
||||
/// Instantiates a new <see cref="TagHelperPrefixDirectiveChunkGenerator"/>.
|
||||
/// </summary>
|
||||
/// <param name="prefix">
|
||||
/// Text used as a required prefix when matching HTML.
|
||||
/// </param>
|
||||
public TagHelperPrefixDirectiveCodeGenerator(string prefix)
|
||||
public TagHelperPrefixDirectiveChunkGenerator(string prefix)
|
||||
{
|
||||
Prefix = prefix;
|
||||
}
|
||||
|
|
@ -28,16 +28,16 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
public string Prefix { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Generates <see cref="Compiler.TagHelperPrefixDirectiveChunk"/>s.
|
||||
/// Generates <see cref="TagHelperPrefixDirectiveChunk"/>s.
|
||||
/// </summary>
|
||||
/// <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 name="context">A <see cref="CodeGeneratorContext"/> instance that contains information about
|
||||
/// the current code generation process.</param>
|
||||
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
||||
/// <param name="context">A <see cref="ChunkGeneratorContext"/> instance that contains information about
|
||||
/// the current chunk generation process.</param>
|
||||
public override void GenerateChunk(Span target, ChunkGeneratorContext context)
|
||||
{
|
||||
context.CodeTreeBuilder.AddTagHelperPrefixDirectiveChunk(Prefix, target);
|
||||
context.ChunkTreeBuilder.AddTagHelperPrefixDirectiveChunk(Prefix, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,13 +3,13 @@
|
|||
|
||||
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()
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.Chunks
|
||||
{
|
||||
public class LiteralChunk : Chunk
|
||||
{
|
||||
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
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 LocationTagged<string> Prefix { get; set; }
|
||||
|
|
@ -3,11 +3,11 @@
|
|||
|
||||
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>();
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.Chunks
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="Chunk"/> used to look up <see cref="TagHelpers.TagHelperDescriptor"/>s that should be ignored
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.Chunks
|
||||
{
|
||||
public class ResolveUrlChunk : Chunk
|
||||
{
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.Chunks
|
||||
{
|
||||
public class SectionChunk : ChunkBlock
|
||||
public class SectionChunk : ParentChunk
|
||||
{
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.Chunks
|
||||
{
|
||||
public class SetBaseTypeChunk : Chunk
|
||||
{
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.Chunks
|
||||
{
|
||||
public class StatementChunk : Chunk
|
||||
{
|
||||
|
|
@ -4,12 +4,12 @@
|
|||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Razor.TagHelpers;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.Chunks
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="ChunkBlock"/> that represents a special HTML tag.
|
||||
/// A <see cref="ParentChunk"/> that represents a special HTML tag.
|
||||
/// </summary>
|
||||
public class TagHelperChunk : ChunkBlock
|
||||
public class TagHelperChunk : ParentChunk
|
||||
{
|
||||
/// <summary>
|
||||
/// Instantiates a new <see cref="TagHelperChunk"/>.
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.Chunks
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="Chunk"/> for the <c>@tagHelperPrefix</c> directive.
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.Chunks
|
||||
{
|
||||
public class TemplateChunk : ChunkBlock
|
||||
public class TemplateChunk : ParentChunk
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.Chunks
|
||||
{
|
||||
public class TypeMemberChunk : Chunk
|
||||
{
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.Chunks
|
||||
{
|
||||
public class UsingChunk : Chunk
|
||||
{
|
||||
|
|
@ -4,9 +4,11 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.AspNet.Razor.CodeGeneration.Visitors;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration
|
||||
{
|
||||
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; } }
|
||||
|
||||
// Internal for testing
|
||||
|
|
@ -65,7 +67,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
|||
|
||||
BuildConstructor(writer);
|
||||
|
||||
// Add space inbetween constructor and method body
|
||||
// Add space in-between constructor and method body
|
||||
writer.WriteLine();
|
||||
|
||||
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
|
||||
var usingVisitor = new CSharpUsingVisitor(writer, Context);
|
||||
|
|
@ -5,11 +5,12 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.AspNet.Razor.Text;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration
|
||||
{
|
||||
public class CSharpCodeWriter : CodeWriter
|
||||
{
|
||||
|
|
@ -463,7 +464,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
|||
Write("\"");
|
||||
}
|
||||
|
||||
public void WriteStartInstrumentationContext(CodeGeneratorContext context, SyntaxTreeNode syntaxNode, bool isLiteral)
|
||||
public void WriteStartInstrumentationContext(ChunkGeneratorContext context, SyntaxTreeNode syntaxNode, bool isLiteral)
|
||||
{
|
||||
WriteStartMethodInvocation(context.Host.GeneratedClassContext.BeginContextMethodName);
|
||||
Write(syntaxNode.Start.AbsoluteIndex.ToString(CultureInfo.InvariantCulture));
|
||||
|
|
@ -474,7 +475,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
|||
WriteEndMethodInvocation();
|
||||
}
|
||||
|
||||
public void WriteEndInstrumentationContext(CodeGeneratorContext context)
|
||||
public void WriteEndInstrumentationContext(ChunkGeneratorContext context)
|
||||
{
|
||||
WriteMethodInvocation(context.Host.GeneratedClassContext.EndContextMethodName);
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration
|
||||
{
|
||||
public struct CSharpCodeWritingScope : IDisposable
|
||||
{
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration
|
||||
{
|
||||
public struct CSharpDisableWarningScope : IDisposable
|
||||
{
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration
|
||||
{
|
||||
public class CSharpLineMappingWriter : IDisposable
|
||||
{
|
||||
|
|
@ -6,7 +6,7 @@ using Microsoft.AspNet.Razor.Parser;
|
|||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration
|
||||
{
|
||||
public class CSharpPaddingBuilder
|
||||
{
|
||||
|
|
@ -5,10 +5,12 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.AspNet.Razor.CodeGeneration.Visitors;
|
||||
using Microsoft.AspNet.Razor.TagHelpers;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration
|
||||
{
|
||||
/// <summary>
|
||||
/// 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)
|
||||
{
|
||||
var chunkBlock = chunk as ChunkBlock;
|
||||
var parentChunk = chunk as ParentChunk;
|
||||
|
||||
plainText = null;
|
||||
|
||||
if (chunkBlock == null || chunkBlock.Children.Count != 1)
|
||||
if (parentChunk == null || parentChunk.Children.Count != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var literalChildChunk = chunkBlock.Children[0] as LiteralChunk;
|
||||
var literalChildChunk = parentChunk.Children[0] as LiteralChunk;
|
||||
|
||||
if (literalChildChunk == null)
|
||||
{
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration
|
||||
{
|
||||
public abstract class CodeBuilder
|
||||
{
|
||||
|
|
@ -1,22 +1,24 @@
|
|||
// 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.Generator
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration
|
||||
{
|
||||
/// <summary>
|
||||
/// Context object with information used to generate a Razor page.
|
||||
/// </summary>
|
||||
public class CodeBuilderContext : CodeGeneratorContext
|
||||
public class CodeBuilderContext : ChunkGeneratorContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Instantiates a new instance of the <see cref="CodeBuilderContext"/> object.
|
||||
/// </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">
|
||||
/// The <see cref="ErrorSink"/> used to collect <see cref="RazorError"/>s encountered
|
||||
/// when parsing the current Razor document.
|
||||
/// </param>
|
||||
public CodeBuilderContext(CodeGeneratorContext generatorContext, ErrorSink errorSink)
|
||||
public CodeBuilderContext(ChunkGeneratorContext generatorContext, ErrorSink errorSink)
|
||||
: base(generatorContext)
|
||||
{
|
||||
ErrorSink = errorSink;
|
||||
|
|
@ -41,14 +43,14 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <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="ExpressionRenderingMode.InjectCode"/> writes <see cref="Compiler.Chunk"/> values in their
|
||||
/// <see cref="Chunks.Chunk"/>s to the output page, i.e. WriteLiteral("Hello World").
|
||||
/// <see cref="ExpressionRenderingMode.InjectCode"/> writes <see cref="Chunks.Chunk"/> values in their
|
||||
/// rawest form, i.g. "Hello World".
|
||||
/// </remarks>
|
||||
public ExpressionRenderingMode ExpressionRenderingMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The C# writer to write <see cref="Compiler.Chunk"/> information to.
|
||||
/// The C# writer to write <see cref="Chunks.Chunk"/> information to.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 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>
|
||||
/// 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>
|
||||
public string Checksum { get; set; }
|
||||
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration
|
||||
{
|
||||
public class CodeBuilderResult
|
||||
{
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration
|
||||
{
|
||||
public class CodeWriter : IDisposable
|
||||
{
|
||||
|
|
@ -22,16 +22,16 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
|||
|
||||
public int CurrentIndent { get; private set; }
|
||||
|
||||
public string NewLine
|
||||
{
|
||||
public string NewLine
|
||||
{
|
||||
get
|
||||
{
|
||||
return _writer.NewLine;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
_writer.NewLine = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CodeWriter ResetIndent()
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration
|
||||
{
|
||||
public enum ExpressionRenderingMode
|
||||
{
|
||||
|
|
@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
/// Indicates that expressions should be written to the output stream
|
||||
/// </summary>
|
||||
/// <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);
|
||||
/// </example>
|
||||
|
|
@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
|||
/// the code exists will be used to render it
|
||||
/// </summary>
|
||||
/// <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
|
||||
/// </example>
|
||||
|
|
@ -6,7 +6,7 @@ using System.Diagnostics.CodeAnalysis;
|
|||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Internal.Web.Utils;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration
|
||||
{
|
||||
public struct GeneratedClassContext
|
||||
{
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains necessary information for the tag helper code generation process.
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
using System.Globalization;
|
||||
using Microsoft.Internal.Web.Utils;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration
|
||||
{
|
||||
public class LineMapping
|
||||
{
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration
|
||||
{
|
||||
public class LineMappingManager
|
||||
{
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
using System.Globalization;
|
||||
using Microsoft.Internal.Web.Utils;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration
|
||||
{
|
||||
public class MappingLocation
|
||||
{
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
// 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.Chunks;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
|
||||
{
|
||||
public class CSharpBaseTypeVisitor : CodeVisitor<CSharpCodeWriter>
|
||||
{
|
||||
|
|
@ -3,10 +3,11 @@
|
|||
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
|
||||
{
|
||||
public class CSharpCodeVisitor : CodeVisitor<CSharpCodeWriter>
|
||||
{
|
||||
|
|
@ -70,7 +71,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
|||
TagHelperRenderer.RenderTagHelper(chunk);
|
||||
}
|
||||
|
||||
protected override void Visit(ChunkBlock chunk)
|
||||
protected override void Visit(ParentChunk chunk)
|
||||
{
|
||||
Accept(chunk.Children);
|
||||
}
|
||||
|
|
@ -3,9 +3,10 @@
|
|||
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
|
||||
{
|
||||
public class CSharpDesignTimeHelpersVisitor : CodeVisitor<CSharpCodeWriter>
|
||||
{
|
||||
|
|
@ -28,7 +29,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
|||
_csharpCodeVisitor = csharpCodeVisitor;
|
||||
}
|
||||
|
||||
public void AcceptTree(CodeTree tree)
|
||||
public void AcceptTree(ChunkTree tree)
|
||||
{
|
||||
if (Context.Host.DesignTimeMode)
|
||||
{
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
// 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.Chunks;
|
||||
using Microsoft.AspNet.Razor.Parser;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
|
||||
{
|
||||
/// <summary>
|
||||
/// <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>
|
||||
/// Writes code for the given <paramref name="chunk"/>.
|
||||
/// </summary>
|
||||
/// <param name="chunk">The <see cref="ChunkBlock"/> to render.</param>
|
||||
/// <param name="chunk">The <see cref="ParentChunk"/> to render.</param>
|
||||
/// <remarks>
|
||||
/// Tracks code mappings for all children while writing.
|
||||
/// </remarks>
|
||||
protected override void Visit(ChunkBlock chunk)
|
||||
protected override void Visit(ParentChunk chunk)
|
||||
{
|
||||
// Line mappings are captured in RenderCode(), not this method.
|
||||
_firstChild = true;
|
||||
|
|
@ -97,7 +98,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
|||
/// <param name="chunk">The <see cref="ResolveUrlChunk"/> to render.</param>
|
||||
/// <remarks>
|
||||
/// Allowed to support future C# extensions. Likely "~/..." will lead to a C# compilation error but that is up
|
||||
/// to the compiler.
|
||||
/// to the .
|
||||
/// </remarks>
|
||||
protected override void Visit(ResolveUrlChunk chunk)
|
||||
{
|
||||
|
|
@ -3,9 +3,10 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
|
||||
{
|
||||
public class CSharpTagHelperFieldDeclarationVisitor : CodeVisitor<CSharpCodeWriter>
|
||||
{
|
||||
|
|
@ -80,20 +81,20 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
|||
|
||||
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
|
||||
// each of the special ChunkBlock types and then dive into their children.
|
||||
if (chunkBlock != null && !(chunkBlock is TagHelperChunk))
|
||||
// each of the special ParentChunk types and then dive into their children.
|
||||
if (parentChunk != null && !(parentChunk is TagHelperChunk))
|
||||
{
|
||||
Accept(chunkBlock.Children);
|
||||
Accept(parentChunk.Children);
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we're a TagHelperChunk or any other non ChunkBlock we ".Accept" it. This ensures
|
||||
// that our overriden 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 TagHelperChunk or any other non ParentChunk we ".Accept" it. This ensures
|
||||
// that our overridden Visit(TagHelperChunk) method gets called and is not skipped over.
|
||||
// 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).
|
||||
base.Accept(chunk);
|
||||
}
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
// 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.Chunks;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="CodeVisitor{T}"/> that generates the code to initialize the TagHelperRunner.
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
// 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.Chunks;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
|
||||
{
|
||||
public class CSharpTypeMemberVisitor : CodeVisitor<CSharpCodeWriter>
|
||||
{
|
||||
|
|
@ -3,10 +3,11 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
|
||||
{
|
||||
public class CSharpUsingVisitor : CodeVisitor<CSharpCodeWriter>
|
||||
{
|
||||
|
|
@ -2,9 +2,10 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
|
||||
{
|
||||
public abstract class ChunkVisitor<TWriter> : IChunkVisitor
|
||||
where TWriter : CodeWriter
|
||||
|
|
@ -96,9 +97,9 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
|||
{
|
||||
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(RemoveTagHelperChunk 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(LiteralCodeAttributeChunk chunk);
|
||||
protected abstract void Visit(CodeAttributeChunk chunk);
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
// 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.Chunks;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
|
||||
{
|
||||
public class CodeVisitor<TWriter> : ChunkVisitor<TWriter>
|
||||
where TWriter : CodeWriter
|
||||
|
|
@ -28,7 +29,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
|||
protected override void Visit(UsingChunk chunk)
|
||||
{
|
||||
}
|
||||
protected override void Visit(ChunkBlock chunk)
|
||||
protected override void Visit(ParentChunk chunk)
|
||||
{
|
||||
}
|
||||
protected override void Visit(DynamicCodeAttributeChunk chunk)
|
||||
|
|
@ -2,8 +2,9 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||
namespace Microsoft.AspNet.Razor.CodeGeneration.Visitors
|
||||
{
|
||||
public interface IChunkVisitor
|
||||
{
|
||||
|
|
@ -12,17 +12,17 @@ namespace Microsoft.AspNet.Razor
|
|||
public class DocumentParseCompleteEventArgs : EventArgs
|
||||
{
|
||||
/// <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>
|
||||
public bool TreeStructureChanged { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The results of the code generation and parsing
|
||||
/// The results of the chunk generation and parsing
|
||||
/// </summary>
|
||||
public GeneratorResults GeneratorResults { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The TextChange which triggered the reparse
|
||||
/// The TextChange which triggered the re-parse
|
||||
/// </summary>
|
||||
public TextChange SourceChange { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,8 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.AspNet.Razor.CodeGeneration;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.AspNet.Razor.TagHelpers;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
|
@ -19,15 +20,15 @@ namespace Microsoft.AspNet.Razor
|
|||
/// </summary>
|
||||
/// <param name="parserResults">The results of parsing a 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,
|
||||
[NotNull] CodeBuilderResult codeBuilderResult,
|
||||
[NotNull] CodeTree codeTree)
|
||||
[NotNull] ChunkTree chunkTree)
|
||||
: this(parserResults.Document,
|
||||
parserResults.TagHelperDescriptors,
|
||||
parserResults.ErrorSink,
|
||||
codeBuilderResult,
|
||||
codeTree)
|
||||
chunkTree)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -43,17 +44,17 @@ namespace Microsoft.AspNet.Razor
|
|||
/// current Razor 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,
|
||||
[NotNull] IEnumerable<TagHelperDescriptor> tagHelperDescriptors,
|
||||
[NotNull] ErrorSink errorSink,
|
||||
[NotNull] CodeBuilderResult codeBuilderResult,
|
||||
[NotNull] CodeTree codeTree)
|
||||
[NotNull] ChunkTree chunkTree)
|
||||
: base(document, tagHelperDescriptors, errorSink)
|
||||
{
|
||||
GeneratedCode = codeBuilderResult.Code;
|
||||
DesignTimeLineMappings = codeBuilderResult.DesignTimeLineMappings;
|
||||
CodeTree = codeTree;
|
||||
ChunkTree = chunkTree;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -67,8 +68,8 @@ namespace Microsoft.AspNet.Razor
|
|||
public IList<LineMapping> DesignTimeLineMappings { get; }
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="Generator.Compiler.CodeTree"/> for the document.
|
||||
/// A <see cref="Chunks.ChunkTree"/> for the document.
|
||||
/// </summary>
|
||||
public CodeTree CodeTree { get; }
|
||||
public ChunkTree ChunkTree { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
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.Tokenizer.Symbols;
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
{
|
||||
TagHelperDirective(
|
||||
SyntaxConstants.CSharp.TagHelperPrefixKeyword,
|
||||
prefix => new TagHelperPrefixDirectiveCodeGenerator(prefix));
|
||||
prefix => new TagHelperPrefixDirectiveChunkGenerator(prefix));
|
||||
}
|
||||
|
||||
protected virtual void AddTagHelperDirective()
|
||||
|
|
@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
TagHelperDirective(
|
||||
SyntaxConstants.CSharp.AddTagHelperKeyword,
|
||||
lookupText =>
|
||||
new AddOrRemoveTagHelperCodeGenerator(removeTagHelperDescriptors: false, lookupText: lookupText));
|
||||
new AddOrRemoveTagHelperChunkGenerator(removeTagHelperDescriptors: false, lookupText: lookupText));
|
||||
}
|
||||
|
||||
protected virtual void RemoveTagHelperDirective()
|
||||
|
|
@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
TagHelperDirective(
|
||||
SyntaxConstants.CSharp.RemoveTagHelperKeyword,
|
||||
lookupText =>
|
||||
new AddOrRemoveTagHelperCodeGenerator(removeTagHelperDescriptors: true, lookupText: lookupText));
|
||||
new AddOrRemoveTagHelperChunkGenerator(removeTagHelperDescriptors: true, lookupText: lookupText));
|
||||
}
|
||||
|
||||
protected virtual void SectionDirective()
|
||||
|
|
@ -90,7 +90,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
sectionName = CurrentSymbol.Content;
|
||||
AcceptAndMoveNext();
|
||||
}
|
||||
Context.CurrentBlock.CodeGenerator = new SectionCodeGenerator(sectionName);
|
||||
Context.CurrentBlock.ChunkGenerator = new SectionChunkGenerator(sectionName);
|
||||
|
||||
var errorLocation = CurrentLocation;
|
||||
whitespace = ReadWhile(IsSpacingToken(includeNewLines: true, includeComments: false));
|
||||
|
|
@ -128,7 +128,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
Output(SpanKind.MetaCode);
|
||||
SectionBlock("{", "}", caseSensitive: true);
|
||||
|
||||
Span.CodeGenerator = SpanCodeGenerator.Null;
|
||||
Span.ChunkGenerator = SpanChunkGenerator.Null;
|
||||
// Check for the terminating "}"
|
||||
if (!Optional(CSharpSymbolType.RightBrace))
|
||||
{
|
||||
|
|
@ -182,7 +182,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
Span.EditHandler = editHandler;
|
||||
|
||||
Balance(BalancingModes.NoErrorOnFailure, CSharpSymbolType.LeftBrace, CSharpSymbolType.RightBrace, blockStart);
|
||||
Span.CodeGenerator = new TypeMemberCodeGenerator();
|
||||
Span.ChunkGenerator = new TypeMemberChunkGenerator();
|
||||
if (!At(CSharpSymbolType.RightBrace))
|
||||
{
|
||||
editHandler.AutoCompleteString = "}";
|
||||
|
|
@ -194,7 +194,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
{
|
||||
Output(SpanKind.Code);
|
||||
Assert(CSharpSymbolType.RightBrace);
|
||||
Span.CodeGenerator = SpanCodeGenerator.Null;
|
||||
Span.ChunkGenerator = SpanChunkGenerator.Null;
|
||||
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None;
|
||||
AcceptAndMoveNext();
|
||||
CompleteBlock();
|
||||
|
|
@ -222,10 +222,10 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
|
||||
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;
|
||||
|
||||
|
|
@ -270,15 +270,15 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
// Pull out the type name
|
||||
string baseType = Span.GetContent();
|
||||
|
||||
// Set up code generation
|
||||
Span.CodeGenerator = createCodeGenerator(baseType.Trim());
|
||||
// Set up chunk generation
|
||||
Span.ChunkGenerator = createChunkGenerator(baseType.Trim());
|
||||
|
||||
// Output the span and finish the block
|
||||
CompleteBlock();
|
||||
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);
|
||||
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 (startsWithQuote)
|
||||
{
|
||||
// Set up code generation
|
||||
// The generated chunk of this code generator is picked up by CSharpDesignTimeHelpersVisitor which
|
||||
// Set up chunk generation
|
||||
// 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
|
||||
// so when we render the code we can project the users value into double quotes to not invoke C#
|
||||
// IntelliSense.
|
||||
Span.CodeGenerator = buildCodeGenerator(rawValue.Trim('"'));
|
||||
Span.ChunkGenerator = buildChunkGenerator(rawValue.Trim('"'));
|
||||
}
|
||||
|
||||
// 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 ||
|
||||
!rawValue.EndsWith("\"", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.AspNet.Razor.Tokenizer.Symbols;
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
Context.OnError(CurrentLocation, RazorResources.FormatParseError_ReservedWord(CurrentSymbol.Content));
|
||||
AcceptAndMoveNext();
|
||||
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None;
|
||||
Span.CodeGenerator = SpanCodeGenerator.Null;
|
||||
Span.ChunkGenerator = SpanChunkGenerator.Null;
|
||||
Context.CurrentBlock.Type = BlockType.Directive;
|
||||
CompleteBlock();
|
||||
Output(SpanKind.MetaCode);
|
||||
|
|
@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
HandleKeyword(topLevel, () =>
|
||||
{
|
||||
Context.CurrentBlock.Type = BlockType.Expression;
|
||||
Context.CurrentBlock.CodeGenerator = new ExpressionCodeGenerator();
|
||||
Context.CurrentBlock.ChunkGenerator = new ExpressionChunkGenerator();
|
||||
ImplicitExpression();
|
||||
});
|
||||
}
|
||||
|
|
@ -158,7 +158,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
}
|
||||
|
||||
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.AnyExceptNewline;
|
||||
Span.CodeGenerator = new AddImportCodeGenerator(
|
||||
Span.ChunkGenerator = new AddImportChunkGenerator(
|
||||
Span.GetContent(symbols => symbols.Skip(1)));
|
||||
|
||||
// Optional ";"
|
||||
|
|
@ -510,7 +510,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
|
||||
// Output "@" as hidden span
|
||||
Accept(transition);
|
||||
Span.CodeGenerator = SpanCodeGenerator.Null;
|
||||
Span.ChunkGenerator = SpanChunkGenerator.Null;
|
||||
Output(SpanKind.Code);
|
||||
|
||||
Assert(CSharpSymbolType.Transition);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
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.Tokenizer;
|
||||
using Microsoft.AspNet.Razor.Tokenizer.Symbols;
|
||||
|
|
@ -181,7 +181,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
private void DefaultSpanConfig(SpanBuilder span)
|
||||
{
|
||||
span.EditHandler = SpanEditHandler.CreateDefault(Language.TokenizeString);
|
||||
span.CodeGenerator = new StatementCodeGenerator();
|
||||
span.ChunkGenerator = new StatementChunkGenerator();
|
||||
}
|
||||
|
||||
private void AtTransition(CSharpSymbol current)
|
||||
|
|
@ -189,7 +189,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
Debug.Assert(current.Type == CSharpSymbolType.Transition);
|
||||
Accept(current);
|
||||
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None;
|
||||
Span.CodeGenerator = SpanCodeGenerator.Null;
|
||||
Span.ChunkGenerator = SpanChunkGenerator.Null;
|
||||
|
||||
// Output the "@" span and continue here
|
||||
Output(SpanKind.Transition);
|
||||
|
|
@ -209,7 +209,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
if (CurrentSymbol.Type == CSharpSymbolType.LeftParenthesis)
|
||||
{
|
||||
Context.CurrentBlock.Type = BlockType.Expression;
|
||||
Context.CurrentBlock.CodeGenerator = new ExpressionCodeGenerator();
|
||||
Context.CurrentBlock.ChunkGenerator = new ExpressionChunkGenerator();
|
||||
ExplicitExpression();
|
||||
return;
|
||||
}
|
||||
|
|
@ -218,14 +218,14 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
Action handler;
|
||||
if (TryGetDirectiveHandler(CurrentSymbol.Content, out handler))
|
||||
{
|
||||
Span.CodeGenerator = SpanCodeGenerator.Null;
|
||||
Span.ChunkGenerator = SpanChunkGenerator.Null;
|
||||
handler();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Context.CurrentBlock.Type = BlockType.Expression;
|
||||
Context.CurrentBlock.CodeGenerator = new ExpressionCodeGenerator();
|
||||
Context.CurrentBlock.ChunkGenerator = new ExpressionChunkGenerator();
|
||||
ImplicitExpression();
|
||||
return;
|
||||
}
|
||||
|
|
@ -244,9 +244,9 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
|
||||
// Invalid character
|
||||
Context.CurrentBlock.Type = BlockType.Expression;
|
||||
Context.CurrentBlock.CodeGenerator = new ExpressionCodeGenerator();
|
||||
Context.CurrentBlock.ChunkGenerator = new ExpressionChunkGenerator();
|
||||
AddMarkerSymbolIfNecessary();
|
||||
Span.CodeGenerator = new ExpressionCodeGenerator();
|
||||
Span.ChunkGenerator = new ExpressionChunkGenerator();
|
||||
Span.EditHandler = new ImplicitExpressionEditHandler(
|
||||
Language.TokenizeString,
|
||||
DefaultKeywords,
|
||||
|
|
@ -283,7 +283,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
|
||||
// Set up the "{" span and output
|
||||
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None;
|
||||
Span.CodeGenerator = SpanCodeGenerator.Null;
|
||||
Span.ChunkGenerator = SpanChunkGenerator.Null;
|
||||
Output(SpanKind.MetaCode);
|
||||
|
||||
// Set up auto-complete and parse the code block
|
||||
|
|
@ -291,7 +291,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
Span.EditHandler = editHandler;
|
||||
CodeBlock(false, block);
|
||||
|
||||
Span.CodeGenerator = new StatementCodeGenerator();
|
||||
Span.ChunkGenerator = new StatementChunkGenerator();
|
||||
AddMarkerSymbolIfNecessary();
|
||||
if (!At(CSharpSymbolType.RightBrace))
|
||||
{
|
||||
|
|
@ -303,7 +303,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
{
|
||||
// Set up the "}" span
|
||||
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None;
|
||||
Span.CodeGenerator = SpanCodeGenerator.Null;
|
||||
Span.ChunkGenerator = SpanChunkGenerator.Null;
|
||||
}
|
||||
|
||||
if (!At(CSharpSymbolType.WhiteSpace) && !At(CSharpSymbolType.NewLine))
|
||||
|
|
@ -330,13 +330,13 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
private void ImplicitExpression(AcceptedCharacters acceptedCharacters)
|
||||
{
|
||||
Context.CurrentBlock.Type = BlockType.Expression;
|
||||
Context.CurrentBlock.CodeGenerator = new ExpressionCodeGenerator();
|
||||
Context.CurrentBlock.ChunkGenerator = new ExpressionChunkGenerator();
|
||||
|
||||
using (PushSpanConfig(span =>
|
||||
{
|
||||
span.EditHandler = new ImplicitExpressionEditHandler(Language.TokenizeString, Keywords, acceptTrailingDot: IsNested);
|
||||
span.EditHandler.AcceptedCharacters = acceptedCharacters;
|
||||
span.CodeGenerator = new ExpressionCodeGenerator();
|
||||
span.ChunkGenerator = new ExpressionChunkGenerator();
|
||||
}))
|
||||
{
|
||||
do
|
||||
|
|
@ -504,7 +504,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
private void ConfigureExplicitExpressionSpan(SpanBuilder sb)
|
||||
{
|
||||
sb.EditHandler = SpanEditHandler.CreateDefault(Language.TokenizeString);
|
||||
sb.CodeGenerator = new ExpressionCodeGenerator();
|
||||
sb.ChunkGenerator = new ExpressionChunkGenerator();
|
||||
}
|
||||
|
||||
private void ExplicitExpression()
|
||||
|
|
@ -513,7 +513,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
Assert(CSharpSymbolType.LeftParenthesis);
|
||||
AcceptAndMoveNext();
|
||||
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None;
|
||||
Span.CodeGenerator = SpanCodeGenerator.Null;
|
||||
Span.ChunkGenerator = SpanChunkGenerator.Null;
|
||||
Output(SpanKind.MetaCode);
|
||||
using (PushSpanConfig(ConfigureExplicitExpressionSpan))
|
||||
{
|
||||
|
|
@ -544,7 +544,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
PutCurrentBack();
|
||||
}
|
||||
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None;
|
||||
Span.CodeGenerator = SpanCodeGenerator.Null;
|
||||
Span.ChunkGenerator = SpanChunkGenerator.Null;
|
||||
CompleteBlock(insertMarkerIfNecessary: false);
|
||||
Output(SpanKind.MetaCode);
|
||||
}
|
||||
|
|
@ -558,7 +558,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
Output(SpanKind.Code);
|
||||
using (Context.StartBlock(BlockType.Template))
|
||||
{
|
||||
Context.CurrentBlock.CodeGenerator = new TemplateBlockCodeGenerator();
|
||||
Context.CurrentBlock.ChunkGenerator = new TemplateBlockChunkGenerator();
|
||||
PutCurrentBack();
|
||||
OtherParserBlock();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System;
|
|||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
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.Tokenizer;
|
||||
|
||||
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -44,12 +44,12 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
var span = node as Span;
|
||||
Debug.Assert(span != null);
|
||||
|
||||
var litGen = span.CodeGenerator as LiteralAttributeCodeGenerator;
|
||||
var litGen = span.ChunkGenerator as LiteralAttributeChunkGenerator;
|
||||
|
||||
return span != null &&
|
||||
((litGen != null && litGen.ValueGenerator == null) ||
|
||||
span.CodeGenerator == SpanCodeGenerator.Null ||
|
||||
span.CodeGenerator is MarkupCodeGenerator);
|
||||
span.ChunkGenerator == SpanChunkGenerator.Null ||
|
||||
span.ChunkGenerator is MarkupChunkGenerator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
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.Text;
|
||||
using Microsoft.AspNet.Razor.Tokenizer.Symbols;
|
||||
|
|
@ -50,11 +50,11 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
Assert(HtmlSymbolType.Transition);
|
||||
AcceptAndMoveNext();
|
||||
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None;
|
||||
Span.CodeGenerator = SpanCodeGenerator.Null;
|
||||
Span.ChunkGenerator = SpanChunkGenerator.Null;
|
||||
Output(SpanKind.Transition);
|
||||
if (At(HtmlSymbolType.Transition))
|
||||
{
|
||||
Span.CodeGenerator = SpanCodeGenerator.Null;
|
||||
Span.ChunkGenerator = SpanChunkGenerator.Null;
|
||||
AcceptAndMoveNext();
|
||||
Output(SpanKind.MetaCode);
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
|
||||
private void DefaultMarkupSpan(SpanBuilder span)
|
||||
{
|
||||
span.CodeGenerator = new MarkupCodeGenerator();
|
||||
span.ChunkGenerator = new MarkupChunkGenerator();
|
||||
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
|
||||
Accept(split.Item1);
|
||||
Span.CodeGenerator = SpanCodeGenerator.Null;
|
||||
Span.ChunkGenerator = SpanChunkGenerator.Null;
|
||||
Output(SpanKind.MetaCode);
|
||||
if (split.Item2 != null)
|
||||
{
|
||||
|
|
@ -368,7 +368,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None;
|
||||
}
|
||||
|
||||
Span.CodeGenerator = SpanCodeGenerator.Null;
|
||||
Span.ChunkGenerator = SpanChunkGenerator.Null;
|
||||
|
||||
CompleteTagBlockWithSpan(tagBlockWrapper, Span.EditHandler.AcceptedCharacters, SpanKind.Transition);
|
||||
|
||||
|
|
@ -524,7 +524,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
|
||||
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);
|
||||
|
||||
// Read the values
|
||||
|
|
@ -543,12 +543,13 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
// Create the block code generator
|
||||
Context.CurrentBlock.CodeGenerator = new AttributeBlockCodeGenerator(
|
||||
// Create the block chunk generator
|
||||
Context.CurrentBlock.ChunkGenerator = new AttributeBlockChunkGenerator(
|
||||
name, prefix, suffix);
|
||||
}
|
||||
else
|
||||
|
|
@ -585,13 +586,13 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
Accept(prefix);
|
||||
|
||||
// Render a single "@" in place of "@@".
|
||||
Span.CodeGenerator = new LiteralAttributeCodeGenerator(
|
||||
Span.ChunkGenerator = new LiteralAttributeChunkGenerator(
|
||||
prefix.GetContent(prefixStart),
|
||||
new LocationTagged<string>(CurrentSymbol.GetContent(), CurrentLocation));
|
||||
AcceptAndMoveNext();
|
||||
Output(SpanKind.Markup, AcceptedCharacters.None);
|
||||
|
||||
Span.CodeGenerator = SpanCodeGenerator.Null;
|
||||
Span.ChunkGenerator = SpanChunkGenerator.Null;
|
||||
AcceptAndMoveNext();
|
||||
Output(SpanKind.Markup, AcceptedCharacters.None);
|
||||
}
|
||||
|
|
@ -602,14 +603,14 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
var valueStart = CurrentLocation;
|
||||
PutCurrentBack();
|
||||
|
||||
// Output the prefix but as a null-span. DynamicAttributeBlockCodeGenerator will render it
|
||||
Span.CodeGenerator = SpanCodeGenerator.Null;
|
||||
// Output the prefix but as a null-span. DynamicAttributeBlockChunkGenerator will render it
|
||||
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))
|
||||
{
|
||||
Context.CurrentBlock.CodeGenerator =
|
||||
new DynamicAttributeBlockCodeGenerator(prefix.GetContent(prefixStart), valueStart);
|
||||
Context.CurrentBlock.ChunkGenerator =
|
||||
new DynamicAttributeBlockChunkGenerator(prefix.GetContent(prefixStart), valueStart);
|
||||
|
||||
OtherParserBlock();
|
||||
}
|
||||
|
|
@ -625,9 +626,9 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
// Virtual Path value
|
||||
var valueStart = CurrentLocation;
|
||||
VirtualPath();
|
||||
Span.CodeGenerator = new LiteralAttributeCodeGenerator(
|
||||
Span.ChunkGenerator = new LiteralAttributeChunkGenerator(
|
||||
prefix.GetContent(prefixStart),
|
||||
new LocationTagged<SpanCodeGenerator>(new ResolveUrlCodeGenerator(), valueStart));
|
||||
new LocationTagged<SpanChunkGenerator>(new ResolveUrlChunkGenerator(), valueStart));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -644,7 +645,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
// but for now that's ok)
|
||||
!IsEndOfAttributeValue(quote, sym));
|
||||
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);
|
||||
}
|
||||
|
|
@ -770,7 +771,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
string.Equals(tag.Item1.Content, SyntaxConstants.TextTagName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Output(SpanKind.Markup);
|
||||
Span.CodeGenerator = SpanCodeGenerator.Null;
|
||||
Span.ChunkGenerator = SpanChunkGenerator.Null;
|
||||
|
||||
Accept(_bufferedOpenAngle);
|
||||
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.
|
||||
AcceptWhile(HtmlSymbolType.WhiteSpace);
|
||||
Span.CodeGenerator = new StatementCodeGenerator();
|
||||
Span.ChunkGenerator = new StatementChunkGenerator();
|
||||
Output(SpanKind.Code);
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
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.Tokenizer;
|
||||
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)
|
||||
{
|
||||
span.Kind = SpanKind.Markup;
|
||||
span.CodeGenerator = new MarkupCodeGenerator();
|
||||
span.ChunkGenerator = new MarkupChunkGenerator();
|
||||
base.BuildSpan(span, start, content);
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
}
|
||||
Output(SpanKind.Markup);
|
||||
Accept(transition);
|
||||
Span.CodeGenerator = SpanCodeGenerator.Null;
|
||||
Span.ChunkGenerator = SpanChunkGenerator.Null;
|
||||
Output(SpanKind.Markup);
|
||||
AcceptAndMoveNext();
|
||||
continue; // while
|
||||
|
|
@ -212,7 +212,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
AcceptAndMoveNext();
|
||||
|
||||
// Setup the metacode span that we will be outputing.
|
||||
Span.CodeGenerator = SpanCodeGenerator.Null;
|
||||
Span.ChunkGenerator = SpanChunkGenerator.Null;
|
||||
Output(SpanKind.MetaCode, AcceptedCharacters.None);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Parser
|
||||
|
|
@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.Text;
|
||||
using Microsoft.Internal.Web.Utils;
|
||||
|
||||
|
|
@ -15,12 +15,12 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
|
|||
public class Block : SyntaxTreeNode
|
||||
{
|
||||
public Block(BlockBuilder source)
|
||||
: this(source.Type, source.Children, source.CodeGenerator)
|
||||
: this(source.Type, source.Children, source.ChunkGenerator)
|
||||
{
|
||||
source.Reset();
|
||||
}
|
||||
|
||||
protected Block(BlockType? type, IEnumerable<SyntaxTreeNode> contents, IBlockCodeGenerator generator)
|
||||
protected Block(BlockType? type, IEnumerable<SyntaxTreeNode> contents, IParentChunkGenerator generator)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
|
|
@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
|
|||
|
||||
Type = type.Value;
|
||||
Children = contents;
|
||||
CodeGenerator = generator;
|
||||
ChunkGenerator = generator;
|
||||
|
||||
foreach (SyntaxTreeNode node in Children)
|
||||
{
|
||||
|
|
@ -38,10 +38,10 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
|
|||
}
|
||||
|
||||
// A Test constructor
|
||||
internal Block(BlockType type, IEnumerable<SyntaxTreeNode> contents, IBlockCodeGenerator generator)
|
||||
internal Block(BlockType type, IEnumerable<SyntaxTreeNode> contents, IParentChunkGenerator generator)
|
||||
{
|
||||
Type = type;
|
||||
CodeGenerator = generator;
|
||||
ChunkGenerator = generator;
|
||||
Children = contents;
|
||||
}
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
|
|||
|
||||
public IEnumerable<SyntaxTreeNode> Children { get; }
|
||||
|
||||
public IBlockCodeGenerator CodeGenerator { get; }
|
||||
public IParentChunkGenerator ChunkGenerator { get; }
|
||||
|
||||
public override bool IsBlock
|
||||
{
|
||||
|
|
@ -105,7 +105,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
|
|||
|
||||
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)
|
||||
|
|
@ -113,7 +113,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
|
|||
var other = obj as Block;
|
||||
return other != null &&
|
||||
Type == other.Type &&
|
||||
Equals(CodeGenerator, other.CodeGenerator) &&
|
||||
Equals(ChunkGenerator, other.ChunkGenerator) &&
|
||||
ChildrenEqual(Children, other.Children);
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +121,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
|
|||
{
|
||||
return HashCodeCombiner.Start()
|
||||
.Add(Type)
|
||||
.Add(CodeGenerator)
|
||||
.Add(ChunkGenerator)
|
||||
.Add(Children)
|
||||
.CombinedHash;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
|
||||
namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
|
||||
{
|
||||
|
|
@ -18,13 +18,13 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
|
|||
{
|
||||
Type = original.Type;
|
||||
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")]
|
||||
public BlockType? Type { get; set; }
|
||||
public IList<SyntaxTreeNode> Children { get; private set; }
|
||||
public IBlockCodeGenerator CodeGenerator { get; set; }
|
||||
public IParentChunkGenerator ChunkGenerator { get; set; }
|
||||
|
||||
public virtual Block Build()
|
||||
{
|
||||
|
|
@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
|
|||
{
|
||||
Type = null;
|
||||
Children = new List<SyntaxTreeNode>();
|
||||
CodeGenerator = BlockCodeGenerator.Null;
|
||||
ChunkGenerator = ParentChunkGenerator.Null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using System.Diagnostics;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
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.Tokenizer.Symbols;
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
|
|||
public Span Next { get; protected internal set; }
|
||||
|
||||
public SpanEditHandler EditHandler { get; protected set; }
|
||||
public ISpanCodeGenerator CodeGenerator { get; protected set; }
|
||||
public ISpanChunkGenerator ChunkGenerator { get; protected set; }
|
||||
|
||||
public override bool IsBlock
|
||||
{
|
||||
|
|
@ -64,7 +64,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
|
|||
Kind = builder.Kind;
|
||||
Symbols = builder.Symbols;
|
||||
EditHandler = builder.EditHandler;
|
||||
CodeGenerator = builder.CodeGenerator ?? SpanCodeGenerator.Null;
|
||||
ChunkGenerator = builder.ChunkGenerator ?? SpanChunkGenerator.Null;
|
||||
_start = builder.Start;
|
||||
|
||||
// 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(">");
|
||||
builder.Append(" Gen: <");
|
||||
builder.Append(CodeGenerator.ToString());
|
||||
builder.Append(ChunkGenerator.ToString());
|
||||
builder.Append("> {");
|
||||
builder.Append(string.Join(";", Symbols.GroupBy(sym => sym.GetType()).Select(grp => string.Concat(grp.Key.Name, ":", grp.Count()))));
|
||||
builder.Append("}");
|
||||
|
|
@ -144,7 +144,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
|
|||
return other != null &&
|
||||
Kind.Equals(other.Kind) &&
|
||||
EditHandler.Equals(other.EditHandler) &&
|
||||
CodeGenerator.Equals(other.CodeGenerator) &&
|
||||
ChunkGenerator.Equals(other.ChunkGenerator) &&
|
||||
Symbols.SequenceEqual(other.Symbols);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
|||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
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.Tokenizer.Symbols;
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
|
|||
Kind = original.Kind;
|
||||
_symbols = new List<ISymbol>(original.Symbols);
|
||||
EditHandler = original.EditHandler;
|
||||
CodeGenerator = original.CodeGenerator;
|
||||
ChunkGenerator = original.ChunkGenerator;
|
||||
Start = original.Start;
|
||||
}
|
||||
|
||||
|
|
@ -39,13 +39,13 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
|
|||
}
|
||||
|
||||
public SpanEditHandler EditHandler { get; set; }
|
||||
public ISpanCodeGenerator CodeGenerator { get; set; }
|
||||
public ISpanChunkGenerator ChunkGenerator { get; set; }
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_symbols = new List<ISymbol>();
|
||||
EditHandler = SpanEditHandler.CreateDefault(s => Enumerable.Empty<ISymbol>());
|
||||
CodeGenerator = SpanCodeGenerator.Null;
|
||||
ChunkGenerator = SpanChunkGenerator.Null;
|
||||
Start = SourceLocation.Zero;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers
|
|||
/// <param name="source">A <see cref="TagHelperBlockBuilder"/> used to construct a valid
|
||||
/// <see cref="TagHelperBlock"/>.</param>
|
||||
public TagHelperBlock(TagHelperBlockBuilder source)
|
||||
: base(source.Type, source.Children, source.CodeGenerator)
|
||||
: base(source.Type, source.Children, source.ChunkGenerator)
|
||||
{
|
||||
TagName = source.TagName;
|
||||
Descriptors = source.Descriptors;
|
||||
|
|
@ -103,12 +103,12 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers
|
|||
{
|
||||
return string.Format(CultureInfo.CurrentCulture,
|
||||
"'{0}' (Attrs: {1}) Tag Helper Block at {2}::{3} (Gen:{4})",
|
||||
TagName, Attributes.Count, Start, Length, CodeGenerator);
|
||||
TagName, Attributes.Count, Start, Length, ChunkGenerator);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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"/>.
|
||||
/// </summary>
|
||||
/// <param name="other">The <see cref="TagHelperBlock"/> to check equality against.</param>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.AspNet.Razor.TagHelpers;
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers
|
|||
Descriptors = descriptors;
|
||||
Attributes = new List<KeyValuePair<string, SyntaxTreeNode>>(attributes);
|
||||
Type = BlockType.Tag;
|
||||
CodeGenerator = new TagHelperCodeGenerator(descriptors);
|
||||
ChunkGenerator = new TagHelperChunkGenerator(descriptors);
|
||||
}
|
||||
|
||||
// Internal for testing
|
||||
|
|
@ -66,7 +66,7 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers
|
|||
SelfClosing = selfClosing;
|
||||
Attributes = attributes;
|
||||
Type = BlockType.Tag;
|
||||
CodeGenerator = new TagHelperCodeGenerator(tagHelperDescriptors: null);
|
||||
ChunkGenerator = new TagHelperChunkGenerator(tagHelperDescriptors: null);
|
||||
|
||||
// Children is IList, no AddRange
|
||||
foreach (var child in children)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.AspNet.Razor.TagHelpers;
|
||||
using Microsoft.AspNet.Razor.Tokenizer.Symbols;
|
||||
|
|
@ -126,7 +126,7 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers.Internal
|
|||
var afterEquals = false;
|
||||
var builder = new SpanBuilder
|
||||
{
|
||||
CodeGenerator = span.CodeGenerator,
|
||||
ChunkGenerator = span.ChunkGenerator,
|
||||
EditHandler = span.EditHandler,
|
||||
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
|
||||
// ensure we don't do special attribute code generation since this is a tag helper).
|
||||
block = RebuildCodeGenerators(builder.Build());
|
||||
// We need to rebuild the chunk generators of the builder and its children (this is needed to
|
||||
// ensure we don't do special attribute chunk generation since this is a tag helper).
|
||||
block = RebuildChunkGenerators(builder.Build());
|
||||
|
||||
// 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).
|
||||
|
|
@ -348,16 +348,16 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers.Internal
|
|||
return result;
|
||||
}
|
||||
|
||||
private static Block RebuildCodeGenerators(Block block)
|
||||
private static Block RebuildChunkGenerators(Block 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.
|
||||
if (isDynamic || builder.CodeGenerator is AttributeBlockCodeGenerator)
|
||||
// We don't want any attribute specific logic here, null out the block chunk generator.
|
||||
if (isDynamic || builder.ChunkGenerator is AttributeBlockChunkGenerator)
|
||||
{
|
||||
builder.CodeGenerator = BlockCodeGenerator.Null;
|
||||
builder.ChunkGenerator = ParentChunkGenerator.Null;
|
||||
}
|
||||
|
||||
for (var i = 0; i < builder.Children.Count; i++)
|
||||
|
|
@ -367,40 +367,40 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers.Internal
|
|||
if (child.IsBlock)
|
||||
{
|
||||
// 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
|
||||
{
|
||||
var childSpan = (Span)child;
|
||||
ISpanCodeGenerator newCodeGenerator = null;
|
||||
var literalGenerator = childSpan.CodeGenerator as LiteralAttributeCodeGenerator;
|
||||
ISpanChunkGenerator newChunkGenerator = null;
|
||||
var literalGenerator = childSpan.ChunkGenerator as LiteralAttributeChunkGenerator;
|
||||
|
||||
if (literalGenerator != null)
|
||||
{
|
||||
if (literalGenerator.ValueGenerator == null || literalGenerator.ValueGenerator.Value == null)
|
||||
{
|
||||
newCodeGenerator = new MarkupCodeGenerator();
|
||||
newChunkGenerator = new MarkupChunkGenerator();
|
||||
}
|
||||
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
|
||||
// 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 (newCodeGenerator != null)
|
||||
// If we have a new chunk generator we'll need to re-build the child
|
||||
if (newChunkGenerator != null)
|
||||
{
|
||||
var childSpanBuilder = new SpanBuilder(childSpan)
|
||||
{
|
||||
CodeGenerator = newCodeGenerator
|
||||
ChunkGenerator = newChunkGenerator
|
||||
};
|
||||
|
||||
builder.Children[i] = childSpanBuilder.Build();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.AspNet.Razor.TagHelpers;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
|
@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers
|
|||
{
|
||||
/// <summary>
|
||||
/// 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>
|
||||
public class TagHelperDirectiveSpanVisitor : ParserVisitor
|
||||
{
|
||||
|
|
@ -57,30 +57,30 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers
|
|||
|
||||
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 =
|
||||
codeGenerator.RemoveTagHelperDescriptors ?
|
||||
chunkGenerator.RemoveTagHelperDescriptors ?
|
||||
TagHelperDirectiveType.RemoveTagHelper :
|
||||
TagHelperDirectiveType.AddTagHelper;
|
||||
|
||||
var directiveDescriptor = new TagHelperDirectiveDescriptor(
|
||||
codeGenerator.LookupText,
|
||||
chunkGenerator.LookupText,
|
||||
span.Start,
|
||||
directive);
|
||||
|
||||
_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(
|
||||
codeGenerator.Prefix,
|
||||
chunkGenerator.Prefix,
|
||||
span.Start,
|
||||
TagHelperDirectiveType.TagHelperPrefix);
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers.Internal
|
|||
TrackBlock(new BlockBuilder
|
||||
{
|
||||
Type = input.Type,
|
||||
CodeGenerator = input.CodeGenerator
|
||||
ChunkGenerator = input.ChunkGenerator
|
||||
});
|
||||
|
||||
var activeTagHelpers = _trackerStack.Count;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using System.Diagnostics;
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
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.Tokenizer;
|
||||
using Microsoft.AspNet.Razor.Tokenizer.Symbols;
|
||||
|
|
@ -487,7 +487,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
|
||||
private void CommentSpanConfig(SpanBuilder span)
|
||||
{
|
||||
span.CodeGenerator = SpanCodeGenerator.Null;
|
||||
span.ChunkGenerator = SpanChunkGenerator.Null;
|
||||
span.EditHandler = SpanEditHandler.CreateDefault(Language.TokenizeString);
|
||||
}
|
||||
|
||||
|
|
@ -504,7 +504,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
{
|
||||
using (Context.StartBlock(BlockType.Comment))
|
||||
{
|
||||
Context.CurrentBlock.CodeGenerator = new RazorCommentCodeGenerator();
|
||||
Context.CurrentBlock.ChunkGenerator = new RazorCommentChunkGenerator();
|
||||
var start = CurrentLocation;
|
||||
|
||||
Expected(KnownSymbolType.CommentStart);
|
||||
|
|
|
|||
|
|
@ -1287,7 +1287,7 @@ namespace Microsoft.AspNet.Razor
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// A TagHelperCodeGenerator must only be used with TagHelperBlocks.
|
||||
/// A TagHelperChunkGenerator must only be used with TagHelperBlocks.
|
||||
/// </summary>
|
||||
internal static string TagHelpers_TagHelperCodeGeneartorMustBeAssociatedWithATagHelperBlock
|
||||
{
|
||||
|
|
@ -1295,7 +1295,7 @@ namespace Microsoft.AspNet.Razor
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// A TagHelperCodeGenerator must only be used with TagHelperBlocks.
|
||||
/// A TagHelperChunkGenerator must only be used with TagHelperBlocks.
|
||||
/// </summary>
|
||||
internal static string FormatTagHelpers_TagHelperCodeGeneartorMustBeAssociatedWithATagHelperBlock()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.CodeGeneration;
|
||||
using Microsoft.AspNet.Razor.Parser;
|
||||
|
||||
namespace Microsoft.AspNet.Razor
|
||||
|
|
@ -50,10 +50,10 @@ namespace Microsoft.AspNet.Razor
|
|||
public abstract ParserBase CreateCodeParser();
|
||||
|
||||
/// <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>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Microsoft.AspNet.Razor.Generator;
|
||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||
using Microsoft.AspNet.Razor.Chunks.Generators;
|
||||
using Microsoft.AspNet.Razor.CodeGeneration;
|
||||
using Microsoft.AspNet.Razor.Parser;
|
||||
using Microsoft.AspNet.Razor.TagHelpers;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
|
@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Razor
|
|||
/// * 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 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
|
||||
/// * Additional code to add to the generated code (see PostProcessGeneratedCode)
|
||||
/// </remarks>
|
||||
|
|
@ -82,7 +82,7 @@ namespace Microsoft.AspNet.Razor
|
|||
public virtual string DefaultBaseClass { get; set; }
|
||||
|
||||
/// <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>
|
||||
public virtual bool DesignTimeMode { get; set; }
|
||||
|
||||
|
|
@ -194,13 +194,13 @@ namespace Microsoft.AspNet.Razor
|
|||
}
|
||||
|
||||
/// <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>
|
||||
/// <param name="incomingCodeGenerator">The code generator</param>
|
||||
/// <returns>Either the same code generator, after modifications, or a different code generator</returns>
|
||||
public virtual RazorCodeGenerator DecorateCodeGenerator([NotNull] RazorCodeGenerator incomingCodeGenerator)
|
||||
/// <param name="incomingChunkGenerator">The chunk generator</param>
|
||||
/// <returns>Either the same chunk generator, after modifications, or a different chunk generator</returns>
|
||||
public virtual RazorChunkGenerator DecorateChunkGenerator([NotNull] RazorChunkGenerator incomingChunkGenerator)
|
||||
{
|
||||
return incomingCodeGenerator;
|
||||
return incomingChunkGenerator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -215,12 +215,12 @@ namespace Microsoft.AspNet.Razor
|
|||
return incomingBuilder;
|
||||
}
|
||||
|
||||
// If a user wants to modify the code generation process they do it via the DecorateCodeGenerator method which
|
||||
// is why this is internal.
|
||||
internal RazorCodeGenerator CreateCodeGenerator(string className, string rootNamespace, string sourceFileName)
|
||||
// If a user wants to modify the chunk generation process they do it via the DecorateChunkGenerator method
|
||||
// which is why this is internal.
|
||||
internal RazorChunkGenerator CreateChunkGenerator(string className, string rootNamespace, string sourceFileName)
|
||||
{
|
||||
return DecorateCodeGenerator(
|
||||
CodeLanguage.CreateCodeGenerator(className, rootNamespace, sourceFileName, host: this));
|
||||
return DecorateChunkGenerator(
|
||||
CodeLanguage.CreateChunkGenerator(className, rootNamespace, sourceFileName, host: this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue