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 System;
using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Chunks.Generators namespace Microsoft.AspNet.Razor.Chunks.Generators
{ {
@ -14,10 +13,20 @@ namespace Microsoft.AspNet.Razor.Chunks.Generators
public RazorChunkGenerator( public RazorChunkGenerator(
string className, string className,
[NotNull] string rootNamespaceName, string rootNamespaceName,
string sourceFileName, 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)) if (string.IsNullOrEmpty(className))
{ {
throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, nameof(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. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Razor.Chunks; using Microsoft.AspNet.Razor.Chunks;
using Microsoft.AspNet.Razor.CodeGenerators.Visitors; using Microsoft.AspNet.Razor.CodeGenerators.Visitors;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators namespace Microsoft.AspNet.Razor.CodeGenerators
{ {
@ -87,9 +87,19 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
return new CodeGeneratorResult(writer.GenerateCode(), writer.LineMappingManager.Mappings); return new CodeGeneratorResult(writer.GenerateCode(), writer.LineMappingManager.Mappings);
} }
protected virtual CSharpCodeVisitor CreateCSharpCodeVisitor([NotNull] CSharpCodeWriter writer, protected virtual CSharpCodeVisitor CreateCSharpCodeVisitor(CSharpCodeWriter writer,
[NotNull] CodeGeneratorContext context) CodeGeneratorContext context)
{ {
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
return new CSharpCodeVisitor(writer, 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.Chunks.Generators;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Text;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators namespace Microsoft.AspNet.Razor.CodeGenerators
{ {
@ -240,28 +239,58 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
} }
// Writes a method invocation for the given instance name. // Writes a method invocation for the given instance name.
public CSharpCodeWriter WriteInstanceMethodInvocation([NotNull] string instanceName, public CSharpCodeWriter WriteInstanceMethodInvocation(string instanceName,
[NotNull] string methodName, string methodName,
params string[] parameters) 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); return WriteInstanceMethodInvocation(instanceName, methodName, endLine: true, parameters: parameters);
} }
// Writes a method invocation for the given instance name. // Writes a method invocation for the given instance name.
public CSharpCodeWriter WriteInstanceMethodInvocation([NotNull] string instanceName, public CSharpCodeWriter WriteInstanceMethodInvocation(string instanceName,
[NotNull] string methodName, string methodName,
bool endLine, bool endLine,
params string[] parameters) params string[] parameters)
{ {
if (instanceName == null)
{
throw new ArgumentNullException(nameof(instanceName));
}
if (methodName == null)
{
throw new ArgumentNullException(nameof(methodName));
}
return WriteMethodInvocation( return WriteMethodInvocation(
string.Format(CultureInfo.InvariantCulture, InstanceMethodFormat, instanceName, methodName), string.Format(CultureInfo.InvariantCulture, InstanceMethodFormat, instanceName, methodName),
endLine, endLine,
parameters); parameters);
} }
public CSharpCodeWriter WriteStartInstanceMethodInvocation([NotNull] string instanceName, public CSharpCodeWriter WriteStartInstanceMethodInvocation(string instanceName,
[NotNull] string methodName) string methodName)
{ {
if (instanceName == null)
{
throw new ArgumentNullException(nameof(instanceName));
}
if (methodName == null)
{
throw new ArgumentNullException(nameof(methodName));
}
return WriteStartMethodInvocation( return WriteStartMethodInvocation(
string.Format(CultureInfo.InvariantCulture, InstanceMethodFormat, instanceName, methodName)); 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators namespace Microsoft.AspNet.Razor.CodeGenerators
{ {
@ -17,8 +16,13 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
private SourceLocation _generatedLocation; private SourceLocation _generatedLocation;
private int _generatedContentLength; 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; _writer = writer;
_addLineMapping = addLineMappings; _addLineMapping = addLineMappings;
_startIndent = _writer.CurrentIndent; _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="documentLocation">The <see cref="SourceLocation"/> of the Razor content being mapping.</param>
/// <param name="sourceFileName">The input file path.</param> /// <param name="sourceFileName">The input file path.</param>
public CSharpLineMappingWriter( public CSharpLineMappingWriter(
[NotNull] CSharpCodeWriter writer, CSharpCodeWriter writer,
[NotNull] SourceLocation documentLocation, SourceLocation documentLocation,
[NotNull] string sourceFileName) string sourceFileName)
: this(writer, addLineMappings: false) : this(writer, addLineMappings: false)
{ {
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
_writePragmas = true; _writePragmas = true;
_writer.WriteLineNumberDirective(documentLocation, sourceFileName); _writer.WriteLineNumberDirective(documentLocation, sourceFileName);
} }

View File

@ -4,7 +4,6 @@
using System; using System;
using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators 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. // 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); var padding = CalculatePadding(target, generatedStart: 0);
// We treat statement padding specially so for brace positioning, so that in the following example: // 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); 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); var padding = CalculatePadding(target, generatedStart);
return BuildPaddingInternal(padding); 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; int padding;
padding = CollectSpacesAndTabs(target, _host.TabSize) - generatedStart; 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.CodeGenerators.Visitors;
using Microsoft.AspNet.Razor.Runtime.TagHelpers; using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators 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 /// <param name="context">A <see cref="CodeGeneratorContext"/> instance that contains information about
/// the current code generation process.</param> /// the current code generation process.</param>
public CSharpTagHelperCodeRenderer( public CSharpTagHelperCodeRenderer(
[NotNull] IChunkVisitor bodyVisitor, IChunkVisitor bodyVisitor,
[NotNull] CSharpCodeWriter writer, CSharpCodeWriter writer,
[NotNull] CodeGeneratorContext context) 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; _bodyVisitor = bodyVisitor;
_writer = writer; _writer = writer;
_context = context; _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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators namespace Microsoft.AspNet.Razor.CodeGenerators
@ -24,9 +23,14 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
public GeneratedClassContext(string executeMethodName, public GeneratedClassContext(string executeMethodName,
string writeMethodName, string writeMethodName,
string writeLiteralMethodName, string writeLiteralMethodName,
[NotNull] GeneratedTagHelperContext generatedTagHelperContext) GeneratedTagHelperContext generatedTagHelperContext)
: this() : this()
{ {
if (generatedTagHelperContext == null)
{
throw new ArgumentNullException(nameof(generatedTagHelperContext));
}
if (string.IsNullOrEmpty(executeMethodName)) if (string.IsNullOrEmpty(executeMethodName))
{ {
throw new ArgumentException( throw new ArgumentException(

View File

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

View File

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

View File

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

View File

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

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Razor.Chunks; using Microsoft.AspNet.Razor.Chunks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
{ {
@ -20,12 +20,27 @@ namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
private bool _initializedTagHelperDirectiveSyntaxHelper; private bool _initializedTagHelperDirectiveSyntaxHelper;
public CSharpDesignTimeHelpersVisitor([NotNull] CSharpCodeVisitor csharpCodeVisitor, public CSharpDesignTimeHelpersVisitor(CSharpCodeVisitor csharpCodeVisitor,
[NotNull] CSharpCodeWriter writer, CSharpCodeWriter writer,
[NotNull] CodeGeneratorContext context) CodeGeneratorContext context)
: base(writer, 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; _csharpCodeVisitor = csharpCodeVisitor;
} }

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Razor.Chunks; using Microsoft.AspNet.Razor.Chunks;
using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
{ {
@ -34,11 +34,21 @@ namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
/// <see cref="CSharpTagHelperAttributeValueVisitor"/> is writing the value. /// <see cref="CSharpTagHelperAttributeValueVisitor"/> is writing the value.
/// </param> /// </param>
public CSharpTagHelperAttributeValueVisitor( public CSharpTagHelperAttributeValueVisitor(
[NotNull] CSharpCodeWriter writer, CSharpCodeWriter writer,
[NotNull] CodeGeneratorContext context, CodeGeneratorContext context,
string attributeTypeName) string attributeTypeName)
: base(writer, context) : base(writer, context)
{ {
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
_attributeTypeName = attributeTypeName; _attributeTypeName = attributeTypeName;
} }

View File

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

View File

@ -1,8 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Razor.Chunks; using Microsoft.AspNet.Razor.Chunks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
{ {
@ -19,16 +19,31 @@ namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
/// </summary> /// </summary>
/// <param name="writer">The <see cref="CSharpCodeWriter"/> used to generate code.</param> /// <param name="writer">The <see cref="CSharpCodeWriter"/> used to generate code.</param>
/// <param name="context">The <see cref="CodeGeneratorContext"/>.</param> /// <param name="context">The <see cref="CodeGeneratorContext"/>.</param>
public CSharpTagHelperRunnerInitializationVisitor([NotNull] CSharpCodeWriter writer, public CSharpTagHelperRunnerInitializationVisitor(CSharpCodeWriter writer,
[NotNull] CodeGeneratorContext context) CodeGeneratorContext context)
: base(writer, 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; _tagHelperContext = Context.Host.GeneratedClassContext.GeneratedTagHelperContext;
} }
/// <inheritdoc /> /// <inheritdoc />
public override void Accept(Chunk chunk) 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 // 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 // TagHelperChunk nodes. This method avoids overriding each of the ParentChunk-specific Visit() methods to
// dive into Children. // dive into Children.

View File

@ -1,8 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Razor.Chunks; using Microsoft.AspNet.Razor.Chunks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
{ {
@ -10,11 +10,26 @@ namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
{ {
private CSharpCodeVisitor _csharpCodeVisitor; private CSharpCodeVisitor _csharpCodeVisitor;
public CSharpTypeMemberVisitor([NotNull] CSharpCodeVisitor csharpCodeVisitor, public CSharpTypeMemberVisitor(CSharpCodeVisitor csharpCodeVisitor,
[NotNull] CSharpCodeWriter writer, CSharpCodeWriter writer,
[NotNull] CodeGeneratorContext context) CodeGeneratorContext context)
: base(writer, 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; _csharpCodeVisitor = csharpCodeVisitor;
} }

View File

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

View File

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

View File

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

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Parser namespace Microsoft.AspNet.Razor.Parser
{ {
@ -14,8 +13,13 @@ namespace Microsoft.AspNet.Razor.Parser
private Stack<BlockBuilder> _blocks = new Stack<BlockBuilder>(); private Stack<BlockBuilder> _blocks = new Stack<BlockBuilder>();
private Action<SpanBuilder, SourceLocation, string> _markupSpanFactory; 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; _markupSpanFactory = markupSpanFactory;
} }

View File

@ -12,7 +12,6 @@ using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Text;
using Microsoft.AspNet.Razor.Utils; using Microsoft.AspNet.Razor.Utils;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Parser namespace Microsoft.AspNet.Razor.Parser
{ {
@ -25,12 +24,37 @@ namespace Microsoft.AspNet.Razor.Parser
private Stack<BlockBuilder> _blockStack = new Stack<BlockBuilder>(); private Stack<BlockBuilder> _blockStack = new Stack<BlockBuilder>();
private readonly ErrorSink _errorSink; private readonly ErrorSink _errorSink;
public ParserContext([NotNull] ITextDocument source, public ParserContext(ITextDocument source,
[NotNull] ParserBase codeParser, ParserBase codeParser,
[NotNull] ParserBase markupParser, ParserBase markupParser,
[NotNull] ParserBase activeParser, ParserBase activeParser,
[NotNull] ErrorSink errorSink) 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) if (activeParser != codeParser && activeParser != markupParser)
{ {
throw new ArgumentException(RazorResources.ActiveParser_Must_Be_Code_Or_Markup_Parser, nameof(activeParser)); 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. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal; using System;
namespace Microsoft.AspNet.Razor.Parser namespace Microsoft.AspNet.Razor.Parser
{ {
public static class ParserVisitorExtensions 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); result.Document.Accept(self);
foreach (RazorError error in result.ParserErrors) 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.Parser.TagHelpers.Internal;
using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Text;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Parser 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="markupParser">The <see cref="ParserBase"/> used for parsing markup content.</param>
/// <param name="tagHelperDescriptorResolver">The <see cref="ITagHelperDescriptorResolver"/> used to resolve /// <param name="tagHelperDescriptorResolver">The <see cref="ITagHelperDescriptorResolver"/> used to resolve
/// <see cref="TagHelperDescriptor"/>s.</param> /// <see cref="TagHelperDescriptor"/>s.</param>
public RazorParser([NotNull] ParserBase codeParser, public RazorParser(ParserBase codeParser,
[NotNull] ParserBase markupParser, ParserBase markupParser,
ITagHelperDescriptorResolver tagHelperDescriptorResolver) ITagHelperDescriptorResolver tagHelperDescriptorResolver)
: this(codeParser, : this(codeParser,
markupParser, markupParser,
tagHelperDescriptorResolver, tagHelperDescriptorResolver,
GetDefaultRewriters(markupParser)) GetDefaultRewriters(markupParser))
{ {
if (codeParser == null)
{
throw new ArgumentNullException(nameof(codeParser));
}
if (markupParser == null)
{
throw new ArgumentNullException(nameof(markupParser));
}
} }
/// <summary> /// <summary>
/// Initializes a new instance of <see cref="RazorParser"/> from the specified <paramref name="parser" />. /// Initializes a new instance of <see cref="RazorParser"/> from the specified <paramref name="parser" />.
/// </summary> /// </summary>
/// <param name="parser">The <see cref="RazorParser"/> to copy values from.</param> /// <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) : this(parser.CodeParser, parser.MarkupParser, parser.TagHelperDescriptorResolver, parser.Optimizers)
{ {
if (parser == null)
{
throw new ArgumentNullException(nameof(parser));
}
DesignTimeMode = parser.DesignTimeMode; DesignTimeMode = parser.DesignTimeMode;
} }
@ -210,9 +223,19 @@ namespace Microsoft.AspNet.Razor.Parser
/// phase.</param> /// phase.</param>
/// <returns><see cref="TagHelperDescriptor"/>s that are applicable to the <paramref name="documentRoot"/> /// <returns><see cref="TagHelperDescriptor"/>s that are applicable to the <paramref name="documentRoot"/>
/// </returns> /// </returns>
protected virtual IEnumerable<TagHelperDescriptor> GetTagHelperDescriptors([NotNull] Block documentRoot, protected virtual IEnumerable<TagHelperDescriptor> GetTagHelperDescriptors(Block documentRoot,
[NotNull] ErrorSink errorSink) ErrorSink errorSink)
{ {
if (documentRoot == null)
{
throw new ArgumentNullException(nameof(documentRoot));
}
if (errorSink == null)
{
throw new ArgumentNullException(nameof(errorSink));
}
var addOrRemoveTagHelperSpanVisitor = var addOrRemoveTagHelperSpanVisitor =
new TagHelperDirectiveSpanVisitor(TagHelperDescriptorResolver, errorSink); new TagHelperDirectiveSpanVisitor(TagHelperDescriptorResolver, errorSink);
return addOrRemoveTagHelperSpanVisitor.GetDescriptors(documentRoot); return addOrRemoveTagHelperSpanVisitor.GetDescriptors(documentRoot);

View File

@ -1,8 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Parser.SyntaxTree namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
{ {
@ -18,8 +18,13 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
return nodeX != null && nodeX.EquivalentTo(nodeY); 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(); return node.GetEquivalenceHash();
} }
} }

View File

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

View File

@ -5,47 +5,96 @@ using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Parser namespace Microsoft.AspNet.Razor.Parser
{ {
internal static class TextReaderExtensions 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); 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 // 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); 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 // NOTE: Using named parameters would be difficult here, hence the inline comment
return ReadUntil(reader, inclusive: false, terminators: terminators); return ReadUntil(reader, inclusive: false, terminators: terminators);
} }
public static string ReadUntil( public static string ReadUntil(
[NotNull] this TextReader reader, this TextReader reader,
bool inclusive, 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); 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); return ReadUntil(reader, condition, inclusive: false);
} }
public static string ReadUntil( public static string ReadUntil(
[NotNull] this TextReader reader, this TextReader reader,
[NotNull] Predicate<char> condition, Predicate<char> condition,
bool inclusive) bool inclusive)
{ {
if (reader == null)
{
throw new ArgumentNullException(nameof(reader));
}
if (condition == null)
{
throw new ArgumentNullException(nameof(condition));
}
var builder = new StringBuilder(); var builder = new StringBuilder();
var ch = -1; var ch = -1;
while ((ch = reader.Peek()) != -1 && !condition((char)ch)) while ((ch = reader.Peek()) != -1 && !condition((char)ch))
@ -62,26 +111,56 @@ namespace Microsoft.AspNet.Razor.Parser
return builder.ToString(); 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); return ReadWhile(reader, condition, inclusive: false);
} }
public static string ReadWhile( public static string ReadWhile(
[NotNull] this TextReader reader, this TextReader reader,
[NotNull] Predicate<char> condition, Predicate<char> condition,
bool inclusive) 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); 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)); 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)); return ReadUntil(reader, c => Char.IsWhiteSpace(c));
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Razor.Runtime.TagHelpers; using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.TagHelpers namespace Microsoft.AspNet.Razor.TagHelpers
{ {
@ -13,16 +13,54 @@ namespace Microsoft.AspNet.Razor.TagHelpers
/// </summary> /// </summary>
public class TagHelperDescriptor 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> /// <summary>
/// Text used as a required prefix when matching HTML start and end tags in the Razor source to available /// Text used as a required prefix when matching HTML start and end tags in the Razor source to available
/// tag helpers. /// tag helpers.
/// </summary> /// </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> /// <summary>
/// The tag name that the tag helper should target. /// The tag name that the tag helper should target.
/// </summary> /// </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> /// <summary>
/// The full tag name that is required for the tag helper to target an HTML element. /// 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> /// <summary>
/// The full name of the tag helper class. /// The full name of the tag helper class.
/// </summary> /// </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> /// <summary>
/// The name of the assembly containing the tag helper class. /// The name of the assembly containing the tag helper class.
/// </summary> /// </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> /// <summary>
/// The list of attributes the tag helper expects. /// The list of attributes the tag helper expects.
/// </summary> /// </summary>
public IEnumerable<TagHelperAttributeDescriptor> Attributes { get; [param: NotNull] set; } public IEnumerable<TagHelperAttributeDescriptor> Attributes
= Enumerable.Empty<TagHelperAttributeDescriptor>(); {
get
{
return _attributes;
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_attributes = value;
}
}
/// <summary> /// <summary>
/// The list of required attribute names the tag helper expects to target an element. /// The list of required attribute names the tag helper expects to target an element.
@ -58,7 +140,22 @@ namespace Microsoft.AspNet.Razor.TagHelpers
/// <remarks> /// <remarks>
/// <c>*</c> at the end of an attribute name acts as a prefix match. /// <c>*</c> at the end of an attribute name acts as a prefix match.
/// </remarks> /// </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> /// <summary>
/// Get the names of elements allowed as children. Tag helpers must target all such elements. /// 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 /> /// <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() var hashCodeCombiner = HashCodeCombiner.Start()
.Add(descriptor.TypeName, StringComparer.Ordinal) .Add(descriptor.TypeName, StringComparer.Ordinal)
.Add(descriptor.TagName, StringComparer.OrdinalIgnoreCase) .Add(descriptor.TagName, StringComparer.OrdinalIgnoreCase)

View File

@ -1,8 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.TagHelpers namespace Microsoft.AspNet.Razor.TagHelpers
{ {
@ -24,9 +24,19 @@ namespace Microsoft.AspNet.Razor.TagHelpers
/// <see cref="TagHelperDescriptor"/>s.</param> /// <see cref="TagHelperDescriptor"/>s.</param>
/// <param name="errorSink">Used to aggregate <see cref="RazorError"/>s.</param> /// <param name="errorSink">Used to aggregate <see cref="RazorError"/>s.</param>
public TagHelperDescriptorResolutionContext( public TagHelperDescriptorResolutionContext(
[NotNull] IEnumerable<TagHelperDirectiveDescriptor> directiveDescriptors, IEnumerable<TagHelperDirectiveDescriptor> directiveDescriptors,
[NotNull] ErrorSink errorSink) ErrorSink errorSink)
{ {
if (directiveDescriptors == null)
{
throw new ArgumentNullException(nameof(directiveDescriptors));
}
if (errorSink == null)
{
throw new ArgumentNullException(nameof(errorSink));
}
DirectiveDescriptors = new List<TagHelperDirectiveDescriptor>(directiveDescriptors); DirectiveDescriptors = new List<TagHelperDirectiveDescriptor>(directiveDescriptors);
ErrorSink = errorSink; ErrorSink = errorSink;
} }

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal; using System;
namespace Microsoft.AspNet.Razor.TagHelpers namespace Microsoft.AspNet.Razor.TagHelpers
{ {
@ -10,10 +10,27 @@ namespace Microsoft.AspNet.Razor.TagHelpers
/// </summary> /// </summary>
public class TagHelperDirectiveDescriptor public class TagHelperDirectiveDescriptor
{ {
private string _directiveText;
/// <summary> /// <summary>
/// A <see cref="string"/> used to find tag helper <see cref="System.Type"/>s. /// A <see cref="string"/> used to find tag helper <see cref="System.Type"/>s.
/// </summary> /// </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> /// <summary>
/// The <see cref="SourceLocation"/> of the directive. /// 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -47,8 +47,13 @@ namespace Microsoft.AspNet.Razor.TagHelpers
} }
/// <inheritdoc /> /// <inheritdoc />
public int GetHashCode([NotNull] TagHelperDescriptor descriptor) public int GetHashCode(TagHelperDescriptor descriptor)
{ {
if (descriptor == null)
{
throw new ArgumentNullException(nameof(descriptor));
}
return HashCodeCombiner.Start() return HashCodeCombiner.Start()
.Add(descriptor.AssemblyName, StringComparer.Ordinal) .Add(descriptor.AssemblyName, StringComparer.Ordinal)
.Add(descriptor.TypeName, StringComparer.Ordinal) .Add(descriptor.TypeName, StringComparer.Ordinal)

View File

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

View File

@ -17,13 +17,22 @@ namespace Microsoft.AspNet.Razor.Text
Value = default(TValue); 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)) : 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; Location = location;
Value = value; Value = value;
} }

View File

@ -1,8 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO; using System.IO;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Text namespace Microsoft.AspNet.Razor.Text
{ {
@ -19,14 +19,22 @@ namespace Microsoft.AspNet.Razor.Text
UpdateState(); UpdateState();
} }
public SeekableTextReader([NotNull] TextReader source) public SeekableTextReader(TextReader source)
: this(source.ReadToEnd()) : this(source.ReadToEnd())
{ {
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
} }
public SeekableTextReader([NotNull] ITextBuffer buffer) public SeekableTextReader(ITextBuffer buffer)
: this(buffer.ReadToEnd()) : this(buffer.ReadToEnd())
{ {
if (buffer == null)
{
throw new ArgumentNullException(nameof(buffer));
}
} }
public SourceLocation Location public SourceLocation Location

View File

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

View File

@ -26,12 +26,22 @@ namespace Microsoft.AspNet.Razor.Text
public TextChange( public TextChange(
int oldPosition, int oldPosition,
int oldLength, int oldLength,
[NotNull] ITextBuffer oldBuffer, ITextBuffer oldBuffer,
int newPosition, int newPosition,
int newLength, int newLength,
[NotNull] ITextBuffer newBuffer) ITextBuffer newBuffer)
: this() : this()
{ {
if (oldBuffer == null)
{
throw new ArgumentNullException(nameof(oldBuffer));
}
if (newBuffer == null)
{
throw new ArgumentNullException(nameof(newBuffer));
}
if (oldPosition < 0) if (oldPosition < 0)
{ {
throw new ArgumentOutOfRangeException(nameof(oldPosition), CommonResources.FormatArgument_Must_Be_GreaterThanOrEqualTo(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.Parser;
using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Text;
using Microsoft.AspNet.Razor.Tokenizer.Symbols; using Microsoft.AspNet.Razor.Tokenizer.Symbols;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Tokenizer namespace Microsoft.AspNet.Razor.Tokenizer
{ {
@ -15,9 +14,14 @@ namespace Microsoft.AspNet.Razor.Tokenizer
{ {
private Dictionary<char, Func<CSharpSymbolType>> _operatorHandlers; private Dictionary<char, Func<CSharpSymbolType>> _operatorHandlers;
public CSharpTokenizer([NotNull] ITextDocument source) public CSharpTokenizer(ITextDocument source)
: base(source) : base(source)
{ {
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
CurrentState = Data; CurrentState = Data;
_operatorHandlers = new Dictionary<char, Func<CSharpSymbolType>>() _operatorHandlers = new Dictionary<char, Func<CSharpSymbolType>>()

View File

@ -1,12 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Text;
using Microsoft.AspNet.Razor.Tokenizer.Symbols; using Microsoft.AspNet.Razor.Tokenizer.Symbols;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Tokenizer namespace Microsoft.AspNet.Razor.Tokenizer
{ {
@ -15,9 +15,14 @@ namespace Microsoft.AspNet.Razor.Tokenizer
{ {
private const char TransitionChar = '@'; private const char TransitionChar = '@';
public HtmlTokenizer([NotNull] ITextDocument source) public HtmlTokenizer(ITextDocument source)
: base(source) : base(source)
{ {
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
CurrentState = Data; CurrentState = Data;
} }
@ -158,7 +163,7 @@ namespace Microsoft.AspNet.Razor.Tokenizer
Debug.Fail("Unexpected symbol!"); Debug.Fail("Unexpected symbol!");
#else #else
Debug.Assert(false, "Unexpected symbol"); Debug.Assert(false, "Unexpected symbol");
#endif #endif
return EndSymbol(HtmlSymbolType.Unknown); return EndSymbol(HtmlSymbolType.Unknown);
} }

View File

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

View File

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

View File

@ -13,7 +13,6 @@ using System.Text;
using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Text;
using Microsoft.AspNet.Razor.Tokenizer.Symbols; using Microsoft.AspNet.Razor.Tokenizer.Symbols;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Tokenizer namespace Microsoft.AspNet.Razor.Tokenizer
{ {
@ -22,8 +21,13 @@ namespace Microsoft.AspNet.Razor.Tokenizer
where TSymbol : SymbolBase<TSymbolType> where TSymbol : SymbolBase<TSymbolType>
{ {
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "TextDocumentReader does not require disposal")] [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); Source = new TextDocumentReader(source);
Buffer = new StringBuilder(); Buffer = new StringBuilder();
CurrentErrors = new List<RazorError>(); 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Utils namespace Microsoft.AspNet.Razor.Utils
{ {
@ -11,8 +10,13 @@ namespace Microsoft.AspNet.Razor.Utils
private Action _action; private Action _action;
private bool _invoked; private bool _invoked;
public DisposableAction([NotNull] Action action) public DisposableAction(Action action)
{ {
if (action == null)
{
throw new ArgumentNullException(nameof(action));
}
_action = action; _action = action;
} }

View File

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

View File

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