Removing NotNullAttribute from Microsoft.AspNet.Razor

This commit is contained in:
Pranav K 2015-09-11 11:56:49 -07:00
parent f71f9fb679
commit 381c055e2f
52 changed files with 1070 additions and 205 deletions

View File

@ -4,7 +4,6 @@
using System;
using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Chunks.Generators
{
@ -14,10 +13,20 @@ namespace Microsoft.AspNet.Razor.Chunks.Generators
public RazorChunkGenerator(
string className,
[NotNull] string rootNamespaceName,
string rootNamespaceName,
string sourceFileName,
[NotNull] RazorEngineHost host)
RazorEngineHost host)
{
if (rootNamespaceName == null)
{
throw new ArgumentNullException(nameof(rootNamespaceName));
}
if (host == null)
{
throw new ArgumentNullException(nameof(host));
}
if (string.IsNullOrEmpty(className))
{
throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, nameof(className));

View File

@ -1,12 +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 System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Razor.Chunks;
using Microsoft.AspNet.Razor.CodeGenerators.Visitors;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators
{
@ -87,9 +87,19 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
return new CodeGeneratorResult(writer.GenerateCode(), writer.LineMappingManager.Mappings);
}
protected virtual CSharpCodeVisitor CreateCSharpCodeVisitor([NotNull] CSharpCodeWriter writer,
[NotNull] CodeGeneratorContext context)
protected virtual CSharpCodeVisitor CreateCSharpCodeVisitor(CSharpCodeWriter writer,
CodeGeneratorContext context)
{
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
return new CSharpCodeVisitor(writer, context);
}

View File

@ -8,7 +8,6 @@ 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.CodeGenerators
{
@ -240,28 +239,58 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
}
// Writes a method invocation for the given instance name.
public CSharpCodeWriter WriteInstanceMethodInvocation([NotNull] string instanceName,
[NotNull] string methodName,
public CSharpCodeWriter WriteInstanceMethodInvocation(string instanceName,
string methodName,
params string[] parameters)
{
if (instanceName == null)
{
throw new ArgumentNullException(nameof(instanceName));
}
if (methodName == null)
{
throw new ArgumentNullException(nameof(methodName));
}
return WriteInstanceMethodInvocation(instanceName, methodName, endLine: true, parameters: parameters);
}
// Writes a method invocation for the given instance name.
public CSharpCodeWriter WriteInstanceMethodInvocation([NotNull] string instanceName,
[NotNull] string methodName,
public CSharpCodeWriter WriteInstanceMethodInvocation(string instanceName,
string methodName,
bool endLine,
params string[] parameters)
{
if (instanceName == null)
{
throw new ArgumentNullException(nameof(instanceName));
}
if (methodName == null)
{
throw new ArgumentNullException(nameof(methodName));
}
return WriteMethodInvocation(
string.Format(CultureInfo.InvariantCulture, InstanceMethodFormat, instanceName, methodName),
endLine,
parameters);
}
public CSharpCodeWriter WriteStartInstanceMethodInvocation([NotNull] string instanceName,
[NotNull] string methodName)
public CSharpCodeWriter WriteStartInstanceMethodInvocation(string instanceName,
string methodName)
{
if (instanceName == null)
{
throw new ArgumentNullException(nameof(instanceName));
}
if (methodName == null)
{
throw new ArgumentNullException(nameof(methodName));
}
return WriteStartMethodInvocation(
string.Format(CultureInfo.InvariantCulture, InstanceMethodFormat, instanceName, methodName));
}

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators
{
@ -17,8 +16,13 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
private SourceLocation _generatedLocation;
private int _generatedContentLength;
private CSharpLineMappingWriter([NotNull] CSharpCodeWriter writer, bool addLineMappings)
private CSharpLineMappingWriter(CSharpCodeWriter writer, bool addLineMappings)
{
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
_writer = writer;
_addLineMapping = addLineMappings;
_startIndent = _writer.CurrentIndent;
@ -54,11 +58,16 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
/// <param name="documentLocation">The <see cref="SourceLocation"/> of the Razor content being mapping.</param>
/// <param name="sourceFileName">The input file path.</param>
public CSharpLineMappingWriter(
[NotNull] CSharpCodeWriter writer,
[NotNull] SourceLocation documentLocation,
[NotNull] string sourceFileName)
CSharpCodeWriter writer,
SourceLocation documentLocation,
string sourceFileName)
: this(writer, addLineMappings: false)
{
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
_writePragmas = true;
_writer.WriteLineNumberDirective(documentLocation, sourceFileName);
}

View File

@ -4,7 +4,6 @@
using System;
using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators
{
@ -20,8 +19,13 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
}
// Special case for statement padding to account for brace positioning in the editor.
public string BuildStatementPadding([NotNull] Span target)
public string BuildStatementPadding(Span target)
{
if (target == null)
{
throw new ArgumentNullException(nameof(target));
}
var padding = CalculatePadding(target, generatedStart: 0);
// We treat statement padding specially so for brace positioning, so that in the following example:
@ -48,15 +52,25 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
return BuildExpressionPadding(target, generatedStart: 0);
}
public string BuildExpressionPadding([NotNull] Span target, int generatedStart)
public string BuildExpressionPadding(Span target, int generatedStart)
{
if (target == null)
{
throw new ArgumentNullException(nameof(target));
}
var padding = CalculatePadding(target, generatedStart);
return BuildPaddingInternal(padding);
}
internal int CalculatePadding([NotNull] Span target, int generatedStart)
internal int CalculatePadding(Span target, int generatedStart)
{
if (target == null)
{
throw new ArgumentNullException(nameof(target));
}
int padding;
padding = CollectSpacesAndTabs(target, _host.TabSize) - generatedStart;

View File

@ -9,7 +9,6 @@ using Microsoft.AspNet.Razor.Chunks;
using Microsoft.AspNet.Razor.CodeGenerators.Visitors;
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators
{
@ -38,10 +37,25 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
/// <param name="context">A <see cref="CodeGeneratorContext"/> instance that contains information about
/// the current code generation process.</param>
public CSharpTagHelperCodeRenderer(
[NotNull] IChunkVisitor bodyVisitor,
[NotNull] CSharpCodeWriter writer,
[NotNull] CodeGeneratorContext context)
IChunkVisitor bodyVisitor,
CSharpCodeWriter writer,
CodeGeneratorContext context)
{
if (bodyVisitor == null)
{
throw new ArgumentNullException(nameof(bodyVisitor));
}
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
_bodyVisitor = bodyVisitor;
_writer = writer;
_context = context;

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators
@ -24,9 +23,14 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
public GeneratedClassContext(string executeMethodName,
string writeMethodName,
string writeLiteralMethodName,
[NotNull] GeneratedTagHelperContext generatedTagHelperContext)
GeneratedTagHelperContext generatedTagHelperContext)
: this()
{
if (generatedTagHelperContext == null)
{
throw new ArgumentNullException(nameof(generatedTagHelperContext));
}
if (string.IsNullOrEmpty(executeMethodName))
{
throw new ArgumentException(

View File

@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Razor.Chunks;
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators
{
@ -20,15 +20,27 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
/// <param name="parserResults">The results of parsing a document.</param>
/// <param name="codeGeneratorResult">The results of generating code for the document.</param>
/// <param name="chunkTree">A <see cref="ChunkTree"/> for the document.</param>
public GeneratorResults([NotNull] ParserResults parserResults,
[NotNull] CodeGeneratorResult codeGeneratorResult,
[NotNull] ChunkTree chunkTree)
public GeneratorResults(ParserResults parserResults,
CodeGeneratorResult codeGeneratorResult,
ChunkTree chunkTree)
: this(parserResults.Document,
parserResults.TagHelperDescriptors,
parserResults.ErrorSink,
codeGeneratorResult,
chunkTree)
{
if (parserResults == null)
{
throw new ArgumentNullException(nameof(parserResults));
}
if (codeGeneratorResult == null)
{
throw new ArgumentNullException(nameof(codeGeneratorResult));
}
if (chunkTree == null)
{
throw new ArgumentNullException(nameof(chunkTree));
}
}
/// <summary>
@ -44,13 +56,38 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
/// </param>
/// <param name="codeGeneratorResult">The results of generating code 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] CodeGeneratorResult codeGeneratorResult,
[NotNull] ChunkTree chunkTree)
public GeneratorResults(Block document,
IEnumerable<TagHelperDescriptor> tagHelperDescriptors,
ErrorSink errorSink,
CodeGeneratorResult codeGeneratorResult,
ChunkTree chunkTree)
: base(document, tagHelperDescriptors, errorSink)
{
if (document == null)
{
throw new ArgumentNullException(nameof(document));
}
if (tagHelperDescriptors == null)
{
throw new ArgumentNullException(nameof(tagHelperDescriptors));
}
if (errorSink == null)
{
throw new ArgumentNullException(nameof(errorSink));
}
if (codeGeneratorResult == null)
{
throw new ArgumentNullException(nameof(codeGeneratorResult));
}
if (chunkTree == null)
{
throw new ArgumentNullException(nameof(chunkTree));
}
GeneratedCode = codeGeneratorResult.Code;
DesignTimeLineMappings = codeGeneratorResult.DesignTimeLineMappings;
ChunkTree = chunkTree;

View File

@ -3,7 +3,6 @@
using System;
using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators
{
@ -31,12 +30,32 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
/// Razor construct e.g. <c>"@(@readonly)"</c>.
/// </param>
public virtual void RenderAttributeValue(
[NotNull] TagHelperAttributeDescriptor attributeDescriptor,
[NotNull] CSharpCodeWriter writer,
[NotNull] CodeGeneratorContext context,
[NotNull] Action<CSharpCodeWriter> renderAttributeValue,
TagHelperAttributeDescriptor attributeDescriptor,
CSharpCodeWriter writer,
CodeGeneratorContext context,
Action<CSharpCodeWriter> renderAttributeValue,
bool complexValue)
{
if (attributeDescriptor == null)
{
throw new ArgumentNullException(nameof(attributeDescriptor));
}
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (renderAttributeValue == null)
{
throw new ArgumentNullException(nameof(renderAttributeValue));
}
renderAttributeValue(writer);
}
}

View File

@ -1,16 +1,25 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Razor.Chunks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
{
public class CSharpBaseTypeVisitor : CodeVisitor<CSharpCodeWriter>
{
public CSharpBaseTypeVisitor([NotNull] CSharpCodeWriter writer, [NotNull] CodeGeneratorContext context)
public CSharpBaseTypeVisitor(CSharpCodeWriter writer, CodeGeneratorContext context)
: base(writer, context)
{
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
}
public string CurrentBaseType { get; set; }

View File

@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Globalization;
using System.Linq;
using Microsoft.AspNet.Razor.Chunks;
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
{
@ -18,9 +18,19 @@ namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
private CSharpPaddingBuilder _paddingBuilder;
private CSharpTagHelperCodeRenderer _tagHelperCodeRenderer;
public CSharpCodeVisitor([NotNull] CSharpCodeWriter writer, [NotNull] CodeGeneratorContext context)
public CSharpCodeVisitor(CSharpCodeWriter writer, CodeGeneratorContext context)
: base(writer, context)
{
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
_paddingBuilder = new CSharpPaddingBuilder(context.Host);
}
@ -35,9 +45,13 @@ namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
return _tagHelperCodeRenderer;
}
[param: NotNull]
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_tagHelperCodeRenderer = value;
}
}

View File

@ -1,10 +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 System;
using System.Diagnostics;
using System.Globalization;
using Microsoft.AspNet.Razor.Chunks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
{
@ -20,12 +20,27 @@ namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
private bool _initializedTagHelperDirectiveSyntaxHelper;
public CSharpDesignTimeHelpersVisitor([NotNull] CSharpCodeVisitor csharpCodeVisitor,
[NotNull] CSharpCodeWriter writer,
[NotNull] CodeGeneratorContext context)
public CSharpDesignTimeHelpersVisitor(CSharpCodeVisitor csharpCodeVisitor,
CSharpCodeWriter writer,
CodeGeneratorContext context)
: base(writer, context)
{
if (csharpCodeVisitor == null)
{
throw new ArgumentNullException(nameof(csharpCodeVisitor));
}
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
_csharpCodeVisitor = csharpCodeVisitor;
}

View File

@ -1,10 +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 System;
using Microsoft.AspNet.Razor.Chunks;
using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
{
@ -34,11 +34,21 @@ namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
/// <see cref="CSharpTagHelperAttributeValueVisitor"/> is writing the value.
/// </param>
public CSharpTagHelperAttributeValueVisitor(
[NotNull] CSharpCodeWriter writer,
[NotNull] CodeGeneratorContext context,
CSharpCodeWriter writer,
CodeGeneratorContext context,
string attributeTypeName)
: base(writer, context)
{
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
_attributeTypeName = attributeTypeName;
}

View File

@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Razor.Chunks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
{
@ -14,10 +13,20 @@ namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
private readonly GeneratedTagHelperContext _tagHelperContext;
private bool _foundTagHelpers;
public CSharpTagHelperFieldDeclarationVisitor([NotNull] CSharpCodeWriter writer,
[NotNull] CodeGeneratorContext context)
public CSharpTagHelperFieldDeclarationVisitor(CSharpCodeWriter writer,
CodeGeneratorContext context)
: base(writer, context)
{
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
_declaredTagHelpers = new HashSet<string>(StringComparer.Ordinal);
_tagHelperContext = Context.Host.GeneratedClassContext.GeneratedTagHelperContext;
}
@ -81,6 +90,11 @@ namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
public override void Accept(Chunk chunk)
{
if (chunk == null)
{
throw new ArgumentNullException(nameof(chunk));
}
var parentChunk = chunk as ParentChunk;
// If we're any ParentChunk other than TagHelperChunk then we want to dive into its Children

View File

@ -1,8 +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 System;
using Microsoft.AspNet.Razor.Chunks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
{
@ -19,16 +19,31 @@ namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
/// </summary>
/// <param name="writer">The <see cref="CSharpCodeWriter"/> used to generate code.</param>
/// <param name="context">The <see cref="CodeGeneratorContext"/>.</param>
public CSharpTagHelperRunnerInitializationVisitor([NotNull] CSharpCodeWriter writer,
[NotNull] CodeGeneratorContext context)
public CSharpTagHelperRunnerInitializationVisitor(CSharpCodeWriter writer,
CodeGeneratorContext context)
: base(writer, context)
{
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
_tagHelperContext = Context.Host.GeneratedClassContext.GeneratedTagHelperContext;
}
/// <inheritdoc />
public override void Accept(Chunk chunk)
{
if (chunk == null)
{
throw new ArgumentNullException(nameof(chunk));
}
// If at any ParentChunk other than a TagHelperChunk, then dive into its Children to search for more
// TagHelperChunk nodes. This method avoids overriding each of the ParentChunk-specific Visit() methods to
// dive into Children.

View File

@ -1,8 +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 System;
using Microsoft.AspNet.Razor.Chunks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
{
@ -10,11 +10,26 @@ namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
{
private CSharpCodeVisitor _csharpCodeVisitor;
public CSharpTypeMemberVisitor([NotNull] CSharpCodeVisitor csharpCodeVisitor,
[NotNull] CSharpCodeWriter writer,
[NotNull] CodeGeneratorContext context)
public CSharpTypeMemberVisitor(CSharpCodeVisitor csharpCodeVisitor,
CSharpCodeWriter writer,
CodeGeneratorContext context)
: base(writer, context)
{
if (csharpCodeVisitor == null)
{
throw new ArgumentNullException(nameof(csharpCodeVisitor));
}
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
_csharpCodeVisitor = csharpCodeVisitor;
}

View File

@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using 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.CodeGenerators.Visitors
{
@ -15,9 +15,19 @@ namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
private bool _foundTagHelpers;
public CSharpUsingVisitor([NotNull] CSharpCodeWriter writer, [NotNull] CodeGeneratorContext context)
public CSharpUsingVisitor(CSharpCodeWriter writer, CodeGeneratorContext context)
: base(writer, context)
{
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
ImportedUsings = new List<string>();
}
@ -26,6 +36,11 @@ namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
/// <inheritdoc />
public override void Accept(Chunk chunk)
{
if (chunk == null)
{
throw new ArgumentNullException(nameof(chunk));
}
// If at any ParentChunk other than a TagHelperChunk, then dive into its Children to search for more
// TagHelperChunk or UsingChunk nodes. This method avoids overriding each of the ParentChunk-specific
// Visit() methods to dive into Children.

View File

@ -1,17 +1,27 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Razor.Chunks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
{
public abstract class ChunkVisitor<TWriter> : IChunkVisitor
where TWriter : CodeWriter
{
public ChunkVisitor([NotNull] TWriter writer, [NotNull] CodeGeneratorContext context)
public ChunkVisitor(TWriter writer, CodeGeneratorContext context)
{
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
Writer = writer;
Context = context;
}
@ -19,16 +29,26 @@ namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
protected TWriter Writer { get; private set; }
protected CodeGeneratorContext Context { get; private set; }
public void Accept([NotNull] IList<Chunk> chunks)
public void Accept(IList<Chunk> chunks)
{
if (chunks == null)
{
throw new ArgumentNullException(nameof(chunks));
}
foreach (Chunk chunk in chunks)
{
Accept(chunk);
}
}
public virtual void Accept([NotNull] Chunk chunk)
public virtual void Accept(Chunk chunk)
{
if (chunk == null)
{
throw new ArgumentNullException(nameof(chunk));
}
if (chunk is LiteralChunk)
{
Visit((LiteralChunk)chunk);

View File

@ -1,17 +1,26 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Razor.Chunks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
{
public class CodeVisitor<TWriter> : ChunkVisitor<TWriter>
where TWriter : CodeWriter
{
public CodeVisitor([NotNull] TWriter writer, [NotNull] CodeGeneratorContext context)
public CodeVisitor(TWriter writer, CodeGeneratorContext context)
: base(writer, context)
{
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
}
protected override void Visit(LiteralChunk chunk)

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Parser
{
@ -14,8 +13,13 @@ namespace Microsoft.AspNet.Razor.Parser
private Stack<BlockBuilder> _blocks = new Stack<BlockBuilder>();
private Action<SpanBuilder, SourceLocation, string> _markupSpanFactory;
protected MarkupRewriter([NotNull] Action<SpanBuilder, SourceLocation, string> markupSpanFactory)
protected MarkupRewriter(Action<SpanBuilder, SourceLocation, string> markupSpanFactory)
{
if (markupSpanFactory == null)
{
throw new ArgumentNullException(nameof(markupSpanFactory));
}
_markupSpanFactory = markupSpanFactory;
}

View File

@ -12,7 +12,6 @@ using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.AspNet.Razor.Text;
using Microsoft.AspNet.Razor.Utils;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Parser
{
@ -25,12 +24,37 @@ namespace Microsoft.AspNet.Razor.Parser
private Stack<BlockBuilder> _blockStack = new Stack<BlockBuilder>();
private readonly ErrorSink _errorSink;
public ParserContext([NotNull] ITextDocument source,
[NotNull] ParserBase codeParser,
[NotNull] ParserBase markupParser,
[NotNull] ParserBase activeParser,
[NotNull] ErrorSink errorSink)
public ParserContext(ITextDocument source,
ParserBase codeParser,
ParserBase markupParser,
ParserBase activeParser,
ErrorSink errorSink)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
if (codeParser == null)
{
throw new ArgumentNullException(nameof(codeParser));
}
if (markupParser == null)
{
throw new ArgumentNullException(nameof(markupParser));
}
if (activeParser == null)
{
throw new ArgumentNullException(nameof(activeParser));
}
if (errorSink == null)
{
throw new ArgumentNullException(nameof(errorSink));
}
if (activeParser != codeParser && activeParser != markupParser)
{
throw new ArgumentException(RazorResources.ActiveParser_Must_Be_Code_Or_Markup_Parser, nameof(activeParser));

View File

@ -1,14 +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.
using Microsoft.Framework.Internal;
using System;
namespace Microsoft.AspNet.Razor.Parser
{
public static class ParserVisitorExtensions
{
public static void Visit([NotNull] this ParserVisitor self, [NotNull] ParserResults result)
public static void Visit(this ParserVisitor self, ParserResults result)
{
if (self == null)
{
throw new ArgumentNullException(nameof(self));
}
if (result == null)
{
throw new ArgumentNullException(nameof(result));
}
result.Document.Accept(self);
foreach (RazorError error in result.ParserErrors)
{

View File

@ -13,7 +13,6 @@ using Microsoft.AspNet.Razor.Parser.TagHelpers;
using Microsoft.AspNet.Razor.Parser.TagHelpers.Internal;
using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.AspNet.Razor.Text;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Parser
{
@ -26,23 +25,37 @@ namespace Microsoft.AspNet.Razor.Parser
/// <param name="markupParser">The <see cref="ParserBase"/> used for parsing markup content.</param>
/// <param name="tagHelperDescriptorResolver">The <see cref="ITagHelperDescriptorResolver"/> used to resolve
/// <see cref="TagHelperDescriptor"/>s.</param>
public RazorParser([NotNull] ParserBase codeParser,
[NotNull] ParserBase markupParser,
public RazorParser(ParserBase codeParser,
ParserBase markupParser,
ITagHelperDescriptorResolver tagHelperDescriptorResolver)
: this(codeParser,
markupParser,
tagHelperDescriptorResolver,
GetDefaultRewriters(markupParser))
{
if (codeParser == null)
{
throw new ArgumentNullException(nameof(codeParser));
}
if (markupParser == null)
{
throw new ArgumentNullException(nameof(markupParser));
}
}
/// <summary>
/// Initializes a new instance of <see cref="RazorParser"/> from the specified <paramref name="parser" />.
/// </summary>
/// <param name="parser">The <see cref="RazorParser"/> to copy values from.</param>
public RazorParser([NotNull] RazorParser parser)
public RazorParser(RazorParser parser)
: this(parser.CodeParser, parser.MarkupParser, parser.TagHelperDescriptorResolver, parser.Optimizers)
{
if (parser == null)
{
throw new ArgumentNullException(nameof(parser));
}
DesignTimeMode = parser.DesignTimeMode;
}
@ -210,9 +223,19 @@ namespace Microsoft.AspNet.Razor.Parser
/// phase.</param>
/// <returns><see cref="TagHelperDescriptor"/>s that are applicable to the <paramref name="documentRoot"/>
/// </returns>
protected virtual IEnumerable<TagHelperDescriptor> GetTagHelperDescriptors([NotNull] Block documentRoot,
[NotNull] ErrorSink errorSink)
protected virtual IEnumerable<TagHelperDescriptor> GetTagHelperDescriptors(Block documentRoot,
ErrorSink errorSink)
{
if (documentRoot == null)
{
throw new ArgumentNullException(nameof(documentRoot));
}
if (errorSink == null)
{
throw new ArgumentNullException(nameof(errorSink));
}
var addOrRemoveTagHelperSpanVisitor =
new TagHelperDirectiveSpanVisitor(TagHelperDescriptorResolver, errorSink);
return addOrRemoveTagHelperSpanVisitor.GetDescriptors(documentRoot);

View File

@ -1,8 +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 System;
using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
{
@ -18,8 +18,13 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
return nodeX != null && nodeX.EquivalentTo(nodeY);
}
public int GetHashCode([NotNull] SyntaxTreeNode node)
public int GetHashCode(SyntaxTreeNode node)
{
if (node == null)
{
throw new ArgumentNullException(nameof(node));
}
return node.GetEquivalenceHash();
}
}

View File

@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Parser.TagHelpers
{
@ -27,15 +27,30 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers
}
public TagHelperDirectiveSpanVisitor(
[NotNull] ITagHelperDescriptorResolver descriptorResolver,
[NotNull] ErrorSink errorSink)
ITagHelperDescriptorResolver descriptorResolver,
ErrorSink errorSink)
{
if (descriptorResolver == null)
{
throw new ArgumentNullException(nameof(descriptorResolver));
}
if (errorSink == null)
{
throw new ArgumentNullException(nameof(errorSink));
}
_descriptorResolver = descriptorResolver;
_errorSink = errorSink;
}
public IEnumerable<TagHelperDescriptor> GetDescriptors([NotNull] Block root)
public IEnumerable<TagHelperDescriptor> GetDescriptors(Block root)
{
if (root == null)
{
throw new ArgumentNullException(nameof(root));
}
_directiveDescriptors = new List<TagHelperDirectiveDescriptor>();
// This will recurse through the syntax tree.
@ -49,9 +64,19 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers
// Allows MVC a chance to override the TagHelperDescriptorResolutionContext
protected virtual TagHelperDescriptorResolutionContext GetTagHelperDescriptorResolutionContext(
[NotNull] IEnumerable<TagHelperDirectiveDescriptor> descriptors,
[NotNull] ErrorSink errorSink)
IEnumerable<TagHelperDirectiveDescriptor> descriptors,
ErrorSink errorSink)
{
if (descriptors == null)
{
throw new ArgumentNullException(nameof(descriptors));
}
if (errorSink == null)
{
throw new ArgumentNullException(nameof(errorSink));
}
return new TagHelperDescriptorResolutionContext(descriptors, errorSink);
}

View File

@ -5,47 +5,96 @@ using System;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Parser
{
internal static class TextReaderExtensions
{
public static string ReadUntil([NotNull] this TextReader reader, char terminator)
public static string ReadUntil(this TextReader reader, char terminator)
{
if (reader == null)
{
throw new ArgumentNullException(nameof(reader));
}
return ReadUntil(reader, terminator, inclusive: false);
}
public static string ReadUntil([NotNull] this TextReader reader, char terminator, bool inclusive)
public static string ReadUntil(this TextReader reader, char terminator, bool inclusive)
{
if (reader == null)
{
throw new ArgumentNullException(nameof(reader));
}
// Rather not allocate an array to use ReadUntil(TextReader, params char[]) so we'll just call the predicate version directly
return ReadUntil(reader, c => c == terminator, inclusive);
}
public static string ReadUntil([NotNull] this TextReader reader, [NotNull] params char[] terminators)
public static string ReadUntil(this TextReader reader, params char[] terminators)
{
if (reader == null)
{
throw new ArgumentNullException(nameof(reader));
}
if (terminators == null)
{
throw new ArgumentNullException(nameof(terminators));
}
// NOTE: Using named parameters would be difficult here, hence the inline comment
return ReadUntil(reader, inclusive: false, terminators: terminators);
}
public static string ReadUntil(
[NotNull] this TextReader reader,
this TextReader reader,
bool inclusive,
[NotNull] params char[] terminators)
params char[] terminators)
{
if (reader == null)
{
throw new ArgumentNullException(nameof(reader));
}
if (terminators == null)
{
throw new ArgumentNullException(nameof(terminators));
}
return ReadUntil(reader, c => terminators.Any(tc => tc == c), inclusive: inclusive);
}
public static string ReadUntil([NotNull] this TextReader reader, [NotNull] Predicate<char> condition)
public static string ReadUntil(this TextReader reader, Predicate<char> condition)
{
if (reader == null)
{
throw new ArgumentNullException(nameof(reader));
}
if (condition == null)
{
throw new ArgumentNullException(nameof(condition));
}
return ReadUntil(reader, condition, inclusive: false);
}
public static string ReadUntil(
[NotNull] this TextReader reader,
[NotNull] Predicate<char> condition,
this TextReader reader,
Predicate<char> condition,
bool inclusive)
{
if (reader == null)
{
throw new ArgumentNullException(nameof(reader));
}
if (condition == null)
{
throw new ArgumentNullException(nameof(condition));
}
var builder = new StringBuilder();
var ch = -1;
while ((ch = reader.Peek()) != -1 && !condition((char)ch))
@ -62,26 +111,56 @@ namespace Microsoft.AspNet.Razor.Parser
return builder.ToString();
}
public static string ReadWhile([NotNull] this TextReader reader, [NotNull] Predicate<char> condition)
public static string ReadWhile(this TextReader reader, Predicate<char> condition)
{
if (reader == null)
{
throw new ArgumentNullException(nameof(reader));
}
if (condition == null)
{
throw new ArgumentNullException(nameof(condition));
}
return ReadWhile(reader, condition, inclusive: false);
}
public static string ReadWhile(
[NotNull] this TextReader reader,
[NotNull] Predicate<char> condition,
this TextReader reader,
Predicate<char> condition,
bool inclusive)
{
if (reader == null)
{
throw new ArgumentNullException(nameof(reader));
}
if (condition == null)
{
throw new ArgumentNullException(nameof(condition));
}
return ReadUntil(reader, ch => !condition(ch), inclusive);
}
public static string ReadWhiteSpace([NotNull] this TextReader reader)
public static string ReadWhiteSpace(this TextReader reader)
{
if (reader == null)
{
throw new ArgumentNullException(nameof(reader));
}
return ReadWhile(reader, c => Char.IsWhiteSpace(c));
}
public static string ReadUntilWhiteSpace([NotNull] this TextReader reader)
public static string ReadUntilWhiteSpace(this TextReader reader)
{
if (reader == null)
{
throw new ArgumentNullException(nameof(reader));
}
return ReadUntil(reader, c => Char.IsWhiteSpace(c));
}
}

View File

@ -5,15 +5,18 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Parser
{
internal class WhiteSpaceRewriter : MarkupRewriter
{
public WhiteSpaceRewriter([NotNull] Action<SpanBuilder, SourceLocation, string> markupSpanFactory)
public WhiteSpaceRewriter(Action<SpanBuilder, SourceLocation, string> markupSpanFactory)
: base(markupSpanFactory)
{
if (markupSpanFactory == null)
{
throw new ArgumentNullException(nameof(markupSpanFactory));
}
}
protected override bool CanRewrite(Block block)

View File

@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor
{
@ -25,11 +25,25 @@ namespace Microsoft.AspNet.Razor
/// The <see cref="ErrorSink"/> used to collect <see cref="RazorError"/>s encountered when parsing the
/// current Razor document.
/// </param>
public ParserResults([NotNull] Block document,
[NotNull] IEnumerable<TagHelperDescriptor> tagHelperDescriptors,
[NotNull] ErrorSink errorSink)
public ParserResults(Block document,
IEnumerable<TagHelperDescriptor> tagHelperDescriptors,
ErrorSink errorSink)
: this(!errorSink.Errors.Any(), document, tagHelperDescriptors, errorSink)
{
if (document == null)
{
throw new ArgumentNullException(nameof(document));
}
if (tagHelperDescriptors == null)
{
throw new ArgumentNullException(nameof(tagHelperDescriptors));
}
if (errorSink == null)
{
throw new ArgumentNullException(nameof(errorSink));
}
}
/// <summary>
@ -45,10 +59,25 @@ namespace Microsoft.AspNet.Razor
/// current Razor document.
/// </param>
protected ParserResults(bool success,
[NotNull] Block document,
[NotNull] IEnumerable<TagHelperDescriptor> tagHelperDescriptors,
[NotNull] ErrorSink errorSink)
Block document,
IEnumerable<TagHelperDescriptor> tagHelperDescriptors,
ErrorSink errorSink)
{
if (document == null)
{
throw new ArgumentNullException(nameof(document));
}
if (tagHelperDescriptors == null)
{
throw new ArgumentNullException(nameof(tagHelperDescriptors));
}
if (errorSink == null)
{
throw new ArgumentNullException(nameof(errorSink));
}
Success = success;
Document = document;
TagHelperDescriptors = tagHelperDescriptors;

View File

@ -9,7 +9,6 @@ using System.IO;
using Microsoft.AspNet.Razor.Editor;
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Text;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor
{
@ -68,8 +67,13 @@ namespace Microsoft.AspNet.Razor
/// </summary>
/// <param name="host">The <see cref="RazorEngineHost"/> which defines the environment in which the generated code will live. <see cref="F:RazorEngineHost.DesignTimeMode"/> should be set if design-time code mappings are desired</param>
/// <param name="sourceFileName">The physical path to use in line pragmas</param>
public RazorEditorParser([NotNull] RazorEngineHost host, string sourceFileName)
public RazorEditorParser(RazorEngineHost host, string sourceFileName)
{
if (host == null)
{
throw new ArgumentNullException(nameof(host));
}
if (string.IsNullOrEmpty(sourceFileName))
{
throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, nameof(sourceFileName));

View File

@ -8,7 +8,6 @@ using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.CodeGenerators;
using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor
{
@ -54,17 +53,31 @@ namespace Microsoft.AspNet.Razor
/// Creates a host which uses the specified code language and the HTML markup language
/// </summary>
/// <param name="codeLanguage">The code language to use</param>
public RazorEngineHost([NotNull] RazorCodeLanguage codeLanguage)
public RazorEngineHost(RazorCodeLanguage codeLanguage)
: this(codeLanguage, () => new HtmlMarkupParser())
{
if (codeLanguage == null)
{
throw new ArgumentNullException(nameof(codeLanguage));
}
}
[SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "The code path is safe, it is a property setter and not dependent on other state")]
public RazorEngineHost(
[NotNull] RazorCodeLanguage codeLanguage,
[NotNull] Func<ParserBase> markupParserFactory)
RazorCodeLanguage codeLanguage,
Func<ParserBase> markupParserFactory)
: this()
{
if (codeLanguage == null)
{
throw new ArgumentNullException(nameof(codeLanguage));
}
if (markupParserFactory == null)
{
throw new ArgumentNullException(nameof(markupParserFactory));
}
CodeLanguage = codeLanguage;
_markupParserFactory = markupParserFactory;
}
@ -170,9 +183,14 @@ namespace Microsoft.AspNet.Razor
/// <param name="sourceFileName">The file name of the Razor file being parsed.</param>
/// <returns>Either the same code parser, after modifications, or a different code parser.</returns>
public virtual RazorParser DecorateRazorParser(
[NotNull] RazorParser incomingRazorParser,
RazorParser incomingRazorParser,
string sourceFileName)
{
if (incomingRazorParser == null)
{
throw new ArgumentNullException(nameof(incomingRazorParser));
}
return incomingRazorParser;
}
@ -181,8 +199,13 @@ namespace Microsoft.AspNet.Razor
/// </summary>
/// <param name="incomingCodeParser">The code parser</param>
/// <returns>Either the same code parser, after modifications, or a different code parser</returns>
public virtual ParserBase DecorateCodeParser([NotNull] ParserBase incomingCodeParser)
public virtual ParserBase DecorateCodeParser(ParserBase incomingCodeParser)
{
if (incomingCodeParser == null)
{
throw new ArgumentNullException(nameof(incomingCodeParser));
}
return incomingCodeParser;
}
@ -191,8 +214,13 @@ namespace Microsoft.AspNet.Razor
/// </summary>
/// <param name="incomingMarkupParser">The markup parser</param>
/// <returns>Either the same markup parser, after modifications, or a different markup parser</returns>
public virtual ParserBase DecorateMarkupParser([NotNull] ParserBase incomingMarkupParser)
public virtual ParserBase DecorateMarkupParser(ParserBase incomingMarkupParser)
{
if (incomingMarkupParser == null)
{
throw new ArgumentNullException(nameof(incomingMarkupParser));
}
return incomingMarkupParser;
}
@ -201,8 +229,13 @@ namespace Microsoft.AspNet.Razor
/// </summary>
/// <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)
public virtual RazorChunkGenerator DecorateChunkGenerator(RazorChunkGenerator incomingChunkGenerator)
{
if (incomingChunkGenerator == null)
{
throw new ArgumentNullException(nameof(incomingChunkGenerator));
}
return incomingChunkGenerator;
}
@ -212,9 +245,14 @@ namespace Microsoft.AspNet.Razor
/// <param name="incomingBuilder">The code generator</param>
/// <returns>Either the same code generator, after modifications, or a different code generator.</returns>
public virtual CodeGenerator DecorateCodeGenerator(
[NotNull] CodeGenerator incomingBuilder,
CodeGenerator incomingBuilder,
CodeGeneratorContext context)
{
if (incomingBuilder == null)
{
throw new ArgumentNullException(nameof(incomingBuilder));
}
return incomingBuilder;
}

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
@ -11,7 +12,6 @@ using Microsoft.AspNet.Razor.Chunks.Generators;
using Microsoft.AspNet.Razor.CodeGenerators;
using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Text;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor
{
@ -30,8 +30,13 @@ namespace Microsoft.AspNet.Razor
/// <param name="host">
/// The host which defines the environment in which the generated template code will live.
/// </param>
public RazorTemplateEngine([NotNull] RazorEngineHost host)
public RazorTemplateEngine(RazorEngineHost host)
{
if (host == null)
{
throw new ArgumentNullException(nameof(host));
}
Host = host;
}
@ -40,8 +45,13 @@ namespace Microsoft.AspNet.Razor
/// </summary>
public RazorEngineHost Host { get; }
public ParserResults ParseTemplate([NotNull] ITextBuffer input)
public ParserResults ParseTemplate(ITextBuffer input)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
return ParseTemplate(input, cancelToken: null);
}
@ -67,15 +77,25 @@ namespace Microsoft.AspNet.Razor
"Microsoft.Reliability", "CA2000:Dispose objects before losing scope",
Justification = "Input object would be disposed if we dispose the wrapper. We don't own the input so " +
"we don't want to dispose it")]
public ParserResults ParseTemplate([NotNull] ITextBuffer input, CancellationToken? cancelToken)
public ParserResults ParseTemplate(ITextBuffer input, CancellationToken? cancelToken)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
return ParseTemplateCore(input.ToDocument(), sourceFileName: null, cancelToken: cancelToken);
}
// See ParseTemplate(ITextBuffer, CancellationToken?),
// this overload simply wraps a TextReader in a TextBuffer (see ITextBuffer and BufferingTextReader)
public ParserResults ParseTemplate([NotNull] TextReader input, string sourceFileName)
public ParserResults ParseTemplate(TextReader input, string sourceFileName)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
return ParseTemplateCore(new SeekableTextReader(input), sourceFileName, cancelToken: null);
}
@ -84,29 +104,49 @@ namespace Microsoft.AspNet.Razor
"CA2000:Dispose objects before losing scope",
Justification = "Input object would be disposed if we dispose the wrapper. We don't own the input so " +
"we don't want to dispose it")]
public ParserResults ParseTemplate([NotNull] TextReader input, CancellationToken? cancelToken)
public ParserResults ParseTemplate(TextReader input, CancellationToken? cancelToken)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
return ParseTemplateCore(new SeekableTextReader(input), sourceFileName: null, cancelToken: cancelToken);
}
protected internal virtual ParserResults ParseTemplateCore(
[NotNull] ITextDocument input,
ITextDocument input,
string sourceFileName,
CancellationToken? cancelToken)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
// Construct the parser
var parser = CreateParser(sourceFileName);
Debug.Assert(parser != null);
return parser.Parse(input);
}
public GeneratorResults GenerateCode([NotNull] ITextBuffer input)
public GeneratorResults GenerateCode(ITextBuffer input)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
return GenerateCode(input, className: null, rootNamespace: null, sourceFileName: null, cancelToken: null);
}
public GeneratorResults GenerateCode([NotNull] ITextBuffer input, CancellationToken? cancelToken)
public GeneratorResults GenerateCode(ITextBuffer input, CancellationToken? cancelToken)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
return GenerateCode(
input,
className: null,
@ -116,11 +156,16 @@ namespace Microsoft.AspNet.Razor
}
public GeneratorResults GenerateCode(
[NotNull] ITextBuffer input,
ITextBuffer input,
string className,
string rootNamespace,
string sourceFileName)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
return GenerateCode(input, className, rootNamespace, sourceFileName, cancelToken: null);
}
@ -163,12 +208,17 @@ namespace Microsoft.AspNet.Razor
Justification = "Input object would be disposed if we dispose the wrapper. We don't own the input so " +
"we don't want to dispose it")]
public GeneratorResults GenerateCode(
[NotNull] ITextBuffer input,
ITextBuffer input,
string className,
string rootNamespace,
string sourceFileName,
CancellationToken? cancelToken)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
return GenerateCodeCore(
input.ToDocument(),
className,
@ -179,13 +229,23 @@ namespace Microsoft.AspNet.Razor
}
// See GenerateCode override which takes ITextBuffer, and BufferingTextReader for details.
public GeneratorResults GenerateCode([NotNull] TextReader input)
public GeneratorResults GenerateCode(TextReader input)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
return GenerateCode(input, className: null, rootNamespace: null, sourceFileName: null, cancelToken: null);
}
public GeneratorResults GenerateCode([NotNull] TextReader input, CancellationToken? cancelToken)
public GeneratorResults GenerateCode(TextReader input, CancellationToken? cancelToken)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
return GenerateCode(
input,
className: null,
@ -195,11 +255,16 @@ namespace Microsoft.AspNet.Razor
}
public GeneratorResults GenerateCode(
[NotNull] TextReader input,
TextReader input,
string className,
string rootNamespace, string sourceFileName)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
return GenerateCode(input, className, rootNamespace, sourceFileName, cancelToken: null);
}
@ -221,11 +286,16 @@ namespace Microsoft.AspNet.Razor
/// debugging.
/// </remarks>
public GeneratorResults GenerateCode(
[NotNull] Stream inputStream,
Stream inputStream,
string className,
string rootNamespace,
string sourceFileName)
{
if (inputStream == null)
{
throw new ArgumentNullException(nameof(inputStream));
}
MemoryStream memoryStream = null;
string checksum = null;
try
@ -280,12 +350,17 @@ namespace Microsoft.AspNet.Razor
Justification = "Input object would be disposed if we dispose the wrapper. We don't own the input so " +
"we don't want to dispose it")]
public GeneratorResults GenerateCode(
[NotNull] TextReader input,
TextReader input,
string className,
string rootNamespace,
string sourceFileName,
CancellationToken? cancelToken)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
return GenerateCodeCore(
new SeekableTextReader(input),
className,
@ -296,13 +371,18 @@ namespace Microsoft.AspNet.Razor
}
protected internal virtual GeneratorResults GenerateCodeCore(
[NotNull] ITextDocument input,
ITextDocument input,
string className,
string rootNamespace,
string sourceFileName,
string checksum,
CancellationToken? cancelToken)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
className = (className ?? Host.DefaultClassName) ?? DefaultClassName;
rootNamespace = (rootNamespace ?? Host.DefaultNamespace) ?? DefaultNamespace;

View File

@ -127,8 +127,13 @@ namespace Microsoft.AspNet.Razor
/// <param name="left">The <see cref="SourceLocation"/> to advance.</param>
/// <param name="text">The <see cref="string"/> to advance <paramref name="left"/> by.</param>
/// <returns>The advanced <see cref="SourceLocation"/>.</returns>
public static SourceLocation Advance(SourceLocation left, [NotNull] string text)
public static SourceLocation Advance(SourceLocation left, string text)
{
if (text == null)
{
throw new ArgumentNullException(nameof(text));
}
var tracker = new SourceLocationTracker(left);
tracker.UpdateLocation(text);
return tracker.CurrentLocation;

View File

@ -3,7 +3,6 @@
using System;
using System.Reflection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.TagHelpers
{
@ -13,6 +12,8 @@ namespace Microsoft.AspNet.Razor.TagHelpers
public class TagHelperAttributeDescriptor
{
private string _typeName;
private string _name;
private string _propertyName;
/// <summary>
/// Instantiates a new instance of the <see cref="TagHelperAttributeDescriptor"/> class.
@ -59,12 +60,43 @@ namespace Microsoft.AspNet.Razor.TagHelpers
/// The HTML attribute name or, if <see cref="IsIndexer"/> is <c>true</c>, the prefix for matching attribute
/// names.
/// </summary>
public string Name { get; [param: NotNull] set; }
public string Name
{
get
{
return _name;
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_name = value;
}
}
/// <summary>
/// The name of the CLR property that corresponds to the HTML attribute.
/// </summary>
public string PropertyName { get; [param: NotNull] set; }
public string PropertyName
{
get
{
return _propertyName;
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_propertyName = value;
}
}
/// <summary>
/// The full name of the named (see <see name="PropertyName"/>) property's <see cref="Type"/> or, if
@ -76,8 +108,13 @@ namespace Microsoft.AspNet.Razor.TagHelpers
{
return _typeName;
}
[param: NotNull] set
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_typeName = value;
IsStringProperty = string.Equals(_typeName, typeof(string).FullName, StringComparison.Ordinal);
}

View File

@ -1,10 +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 System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.TagHelpers
{
@ -13,16 +13,54 @@ namespace Microsoft.AspNet.Razor.TagHelpers
/// </summary>
public class TagHelperDescriptor
{
private string _prefix = string.Empty;
private string _tagName;
private string _typeName;
private string _assemblyName;
private IEnumerable<TagHelperAttributeDescriptor> _attributes =
Enumerable.Empty<TagHelperAttributeDescriptor>();
private IEnumerable<string> _requiredAttributes = Enumerable.Empty<string>();
/// <summary>
/// Text used as a required prefix when matching HTML start and end tags in the Razor source to available
/// tag helpers.
/// </summary>
public string Prefix { get; [param: NotNull] set; } = string.Empty;
public string Prefix
{
get
{
return _prefix;
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_prefix = value;
}
}
/// <summary>
/// The tag name that the tag helper should target.
/// </summary>
public string TagName { get; [param: NotNull] set; }
public string TagName
{
get
{
return _tagName;
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_tagName = value;
}
}
/// <summary>
/// The full tag name that is required for the tag helper to target an HTML element.
@ -39,18 +77,62 @@ namespace Microsoft.AspNet.Razor.TagHelpers
/// <summary>
/// The full name of the tag helper class.
/// </summary>
public string TypeName { get; [param: NotNull] set; }
public string TypeName
{
get
{
return _typeName;
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_typeName = value;
}
}
/// <summary>
/// The name of the assembly containing the tag helper class.
/// </summary>
public string AssemblyName { get; [param: NotNull] set; }
public string AssemblyName
{
get
{
return _assemblyName;
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_assemblyName = value;
}
}
/// <summary>
/// The list of attributes the tag helper expects.
/// </summary>
public IEnumerable<TagHelperAttributeDescriptor> Attributes { get; [param: NotNull] set; }
= Enumerable.Empty<TagHelperAttributeDescriptor>();
public IEnumerable<TagHelperAttributeDescriptor> Attributes
{
get
{
return _attributes;
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_attributes = value;
}
}
/// <summary>
/// The list of required attribute names the tag helper expects to target an element.
@ -58,7 +140,22 @@ namespace Microsoft.AspNet.Razor.TagHelpers
/// <remarks>
/// <c>*</c> at the end of an attribute name acts as a prefix match.
/// </remarks>
public IEnumerable<string> RequiredAttributes { get; [param: NotNull] set; } = Enumerable.Empty<string>();
public IEnumerable<string> RequiredAttributes
{
get
{
return _requiredAttributes;
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_requiredAttributes = value;
}
}
/// <summary>
/// Get the names of elements allowed as children. Tag helpers must target all such elements.

View File

@ -61,8 +61,13 @@ namespace Microsoft.AspNet.Razor.TagHelpers
}
/// <inheritdoc />
public virtual int GetHashCode([NotNull] TagHelperDescriptor descriptor)
public virtual int GetHashCode(TagHelperDescriptor descriptor)
{
if (descriptor == null)
{
throw new ArgumentNullException(nameof(descriptor));
}
var hashCodeCombiner = HashCodeCombiner.Start()
.Add(descriptor.TypeName, StringComparer.Ordinal)
.Add(descriptor.TagName, StringComparer.OrdinalIgnoreCase)

View File

@ -1,8 +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 System;
using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.TagHelpers
{
@ -24,9 +24,19 @@ namespace Microsoft.AspNet.Razor.TagHelpers
/// <see cref="TagHelperDescriptor"/>s.</param>
/// <param name="errorSink">Used to aggregate <see cref="RazorError"/>s.</param>
public TagHelperDescriptorResolutionContext(
[NotNull] IEnumerable<TagHelperDirectiveDescriptor> directiveDescriptors,
[NotNull] ErrorSink errorSink)
IEnumerable<TagHelperDirectiveDescriptor> directiveDescriptors,
ErrorSink errorSink)
{
if (directiveDescriptors == null)
{
throw new ArgumentNullException(nameof(directiveDescriptors));
}
if (errorSink == null)
{
throw new ArgumentNullException(nameof(errorSink));
}
DirectiveDescriptors = new List<TagHelperDirectiveDescriptor>(directiveDescriptors);
ErrorSink = errorSink;
}

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
using System;
namespace Microsoft.AspNet.Razor.TagHelpers
{
@ -10,10 +10,27 @@ namespace Microsoft.AspNet.Razor.TagHelpers
/// </summary>
public class TagHelperDirectiveDescriptor
{
private string _directiveText;
/// <summary>
/// A <see cref="string"/> used to find tag helper <see cref="System.Type"/>s.
/// </summary>
public string DirectiveText { get; [param: NotNull] set; }
public string DirectiveText
{
get
{
return _directiveText;
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_directiveText = value;
}
}
/// <summary>
/// The <see cref="SourceLocation"/> of the directive.

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
@ -47,8 +47,13 @@ namespace Microsoft.AspNet.Razor.TagHelpers
}
/// <inheritdoc />
public int GetHashCode([NotNull] TagHelperDescriptor descriptor)
public int GetHashCode(TagHelperDescriptor descriptor)
{
if (descriptor == null)
{
throw new ArgumentNullException(nameof(descriptor));
}
return HashCodeCombiner.Start()
.Add(descriptor.AssemblyName, StringComparer.Ordinal)
.Add(descriptor.TypeName, StringComparer.Ordinal)

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.AspNet.Razor.Utils;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Text
{
@ -18,8 +17,13 @@ namespace Microsoft.AspNet.Razor.Text
private int _currentCharacter;
private SourceLocationTracker _locationTracker;
public BufferingTextReader([NotNull] TextReader source)
public BufferingTextReader(TextReader source)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
InnerReader = source;
_locationTracker = new SourceLocationTracker();

View File

@ -17,13 +17,22 @@ namespace Microsoft.AspNet.Razor.Text
Value = default(TValue);
}
public LocationTagged([NotNull] TValue value, int offset, int line, int col)
public LocationTagged(TValue value, int offset, int line, int col)
: this(value, new SourceLocation(offset, line, col))
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
}
public LocationTagged([NotNull] TValue value, SourceLocation location)
public LocationTagged(TValue value, SourceLocation location)
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
Location = location;
Value = value;
}

View File

@ -1,8 +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 System;
using System.IO;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Text
{
@ -19,14 +19,22 @@ namespace Microsoft.AspNet.Razor.Text
UpdateState();
}
public SeekableTextReader([NotNull] TextReader source)
public SeekableTextReader(TextReader source)
: this(source.ReadToEnd())
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
}
public SeekableTextReader([NotNull] ITextBuffer buffer)
public SeekableTextReader(ITextBuffer buffer)
: this(buffer.ReadToEnd())
{
if (buffer == null)
{
throw new ArgumentNullException(nameof(buffer));
}
}
public SourceLocation Location

View File

@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Razor.Utils;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Text
{
@ -13,8 +12,13 @@ namespace Microsoft.AspNet.Razor.Text
private Stack<BacktrackContext> _bookmarks = new Stack<BacktrackContext>();
private SourceLocationTracker _tracker = new SourceLocationTracker();
public TextBufferReader([NotNull] ITextBuffer buffer)
public TextBufferReader(ITextBuffer buffer)
{
if (buffer == null)
{
throw new ArgumentNullException(nameof(buffer));
}
InnerBuffer = buffer;
}

View File

@ -26,12 +26,22 @@ namespace Microsoft.AspNet.Razor.Text
public TextChange(
int oldPosition,
int oldLength,
[NotNull] ITextBuffer oldBuffer,
ITextBuffer oldBuffer,
int newPosition,
int newLength,
[NotNull] ITextBuffer newBuffer)
ITextBuffer newBuffer)
: this()
{
if (oldBuffer == null)
{
throw new ArgumentNullException(nameof(oldBuffer));
}
if (newBuffer == null)
{
throw new ArgumentNullException(nameof(newBuffer));
}
if (oldPosition < 0)
{
throw new ArgumentOutOfRangeException(nameof(oldPosition), CommonResources.FormatArgument_Must_Be_GreaterThanOrEqualTo(0));

View File

@ -7,7 +7,6 @@ using System.Diagnostics;
using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Text;
using Microsoft.AspNet.Razor.Tokenizer.Symbols;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Tokenizer
{
@ -15,9 +14,14 @@ namespace Microsoft.AspNet.Razor.Tokenizer
{
private Dictionary<char, Func<CSharpSymbolType>> _operatorHandlers;
public CSharpTokenizer([NotNull] ITextDocument source)
public CSharpTokenizer(ITextDocument source)
: base(source)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
CurrentState = Data;
_operatorHandlers = new Dictionary<char, Func<CSharpSymbolType>>()

View File

@ -1,12 +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 System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Text;
using Microsoft.AspNet.Razor.Tokenizer.Symbols;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Tokenizer
{
@ -15,9 +15,14 @@ namespace Microsoft.AspNet.Razor.Tokenizer
{
private const char TransitionChar = '@';
public HtmlTokenizer([NotNull] ITextDocument source)
public HtmlTokenizer(ITextDocument source)
: base(source)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
CurrentState = Data;
}
@ -158,7 +163,7 @@ namespace Microsoft.AspNet.Razor.Tokenizer
Debug.Fail("Unexpected symbol!");
#else
Debug.Assert(false, "Unexpected symbol");
Debug.Assert(false, "Unexpected symbol");
#endif
return EndSymbol(HtmlSymbolType.Unknown);
}

View File

@ -1,43 +1,59 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Tokenizer.Symbols
{
public class CSharpSymbol : SymbolBase<CSharpSymbolType>
{
// Helper constructor
public CSharpSymbol(int offset, int line, int column, [NotNull] string content, CSharpSymbolType type)
public CSharpSymbol(int offset, int line, int column, string content, CSharpSymbolType type)
: this(new SourceLocation(offset, line, column), content, type, Enumerable.Empty<RazorError>())
{
if (content == null)
{
throw new ArgumentNullException(nameof(content));
}
}
public CSharpSymbol(SourceLocation start, [NotNull] string content, CSharpSymbolType type)
public CSharpSymbol(SourceLocation start, string content, CSharpSymbolType type)
: this(start, content, type, Enumerable.Empty<RazorError>())
{
if (content == null)
{
throw new ArgumentNullException(nameof(content));
}
}
public CSharpSymbol(
int offset,
int line,
int column,
[NotNull] string content,
string content,
CSharpSymbolType type,
IEnumerable<RazorError> errors)
: base(new SourceLocation(offset, line, column), content, type, errors)
{
if (content == null)
{
throw new ArgumentNullException(nameof(content));
}
}
public CSharpSymbol(
SourceLocation start,
[NotNull] string content,
string content,
CSharpSymbolType type,
IEnumerable<RazorError> errors)
: base(start, content, type, errors)
{
if (content == null)
{
throw new ArgumentNullException(nameof(content));
}
}
public bool? EscapedIdentifier { get; set; }

View File

@ -1,43 +1,59 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Tokenizer.Symbols
{
public class HtmlSymbol : SymbolBase<HtmlSymbolType>
{
// Helper constructor
public HtmlSymbol(int offset, int line, int column, [NotNull] string content, HtmlSymbolType type)
public HtmlSymbol(int offset, int line, int column, string content, HtmlSymbolType type)
: this(new SourceLocation(offset, line, column), content, type, Enumerable.Empty<RazorError>())
{
if (content == null)
{
throw new ArgumentNullException(nameof(content));
}
}
public HtmlSymbol(SourceLocation start, [NotNull] string content, HtmlSymbolType type)
public HtmlSymbol(SourceLocation start, string content, HtmlSymbolType type)
: base(start, content, type, Enumerable.Empty<RazorError>())
{
if (content == null)
{
throw new ArgumentNullException(nameof(content));
}
}
public HtmlSymbol(
int offset,
int line,
int column,
[NotNull] string content,
string content,
HtmlSymbolType type,
IEnumerable<RazorError> errors)
: base(new SourceLocation(offset, line, column), content, type, errors)
{
if (content == null)
{
throw new ArgumentNullException(nameof(content));
}
}
public HtmlSymbol(
SourceLocation start,
[NotNull] string content,
string content,
HtmlSymbolType type,
IEnumerable<RazorError> errors)
: base(start, content, type, errors)
{
if (content == null)
{
throw new ArgumentNullException(nameof(content));
}
}
}
}

View File

@ -10,14 +10,19 @@ using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Tokenizer.Symbols
{
public abstract class SymbolBase<TType> : ISymbol
where TType: struct
where TType : struct
{
protected SymbolBase(
SourceLocation start,
[NotNull] string content,
string content,
TType type,
IEnumerable<RazorError> errors)
{
if (content == null)
{
throw new ArgumentNullException(nameof(content));
}
Start = start;
Content = content;
Type = type;

View File

@ -13,7 +13,6 @@ using System.Text;
using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Text;
using Microsoft.AspNet.Razor.Tokenizer.Symbols;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Tokenizer
{
@ -22,8 +21,13 @@ namespace Microsoft.AspNet.Razor.Tokenizer
where TSymbol : SymbolBase<TSymbolType>
{
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "TextDocumentReader does not require disposal")]
protected Tokenizer([NotNull] ITextDocument source)
protected Tokenizer(ITextDocument source)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
Source = new TextDocumentReader(source);
Buffer = new StringBuilder();
CurrentErrors = new List<RazorError>();

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Utils
{
@ -11,8 +10,13 @@ namespace Microsoft.AspNet.Razor.Utils
private Action _action;
private bool _invoked;
public DisposableAction([NotNull] Action action)
public DisposableAction(Action action)
{
if (action == null)
{
throw new ArgumentNullException(nameof(action));
}
_action = action;
}

View File

@ -9,10 +9,6 @@
"Microsoft.Framework.HashCodeCombiner.Sources": {
"type": "build",
"version": "1.0.0-*"
},
"Microsoft.Framework.NotNullAttribute.Sources": {
"type": "build",
"version": "1.0.0-*"
}
},
"frameworks": {

View File

@ -1381,7 +1381,6 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
[Theory]
[InlineData("", 1)]
[InlineData(null, 1)]
[InlineData("*,", 2)]
[InlineData("?,", 2)]
[InlineData(",", 1)]