diff --git a/src/Microsoft.AspNet.Razor/Generator/CSharpRazorCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/CSharpRazorCodeGenerator.cs index cad4a7ce00..a580687563 100644 --- a/src/Microsoft.AspNet.Razor/Generator/CSharpRazorCodeGenerator.cs +++ b/src/Microsoft.AspNet.Razor/Generator/CSharpRazorCodeGenerator.cs @@ -1,12 +1,17 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor.Generator { public class CSharpRazorCodeGenerator : RazorCodeGenerator { - public CSharpRazorCodeGenerator(string className, string rootNamespaceName, string sourceFileName, RazorEngineHost host) + public CSharpRazorCodeGenerator( + string className, + [NotNull] string rootNamespaceName, + string sourceFileName, + [NotNull] RazorEngineHost host) : base(className, rootNamespaceName, sourceFileName, host) { } diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpPaddingBuilder.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpPaddingBuilder.cs index 2c3786933f..0e0636afb1 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpPaddingBuilder.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpPaddingBuilder.cs @@ -4,6 +4,7 @@ using System; using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser.SyntaxTree; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp { @@ -19,13 +20,8 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp } // Special case for statement padding to account for brace positioning in the editor. - public string BuildStatementPadding(Span target) + public string BuildStatementPadding([NotNull] Span target) { - if (target == null) - { - throw new ArgumentNullException("target"); - } - var padding = CalculatePadding(target, generatedStart: 0); // We treat statement padding specially so for brace positioning, so that in the following example: @@ -52,20 +48,15 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp return BuildExpressionPadding(target, generatedStart: 0); } - public string BuildExpressionPadding(Span target, int generatedStart) + public string BuildExpressionPadding([NotNull] Span target, int generatedStart) { var padding = CalculatePadding(target, generatedStart); return BuildPaddingInternal(padding); } - internal int CalculatePadding(Span target, int generatedStart) + internal int CalculatePadding([NotNull] Span target, int generatedStart) { - if (target == null) - { - throw new ArgumentNullException("target"); - } - int padding; padding = CollectSpacesAndTabs(target, _host.TabSize) - generatedStart; diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpBaseTypeVisitor.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpBaseTypeVisitor.cs index be00d34d21..a41cdba5aa 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpBaseTypeVisitor.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpBaseTypeVisitor.cs @@ -1,13 +1,16 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.Framework.Internal; + namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp { public class CSharpBaseTypeVisitor : CodeVisitor { - public CSharpBaseTypeVisitor(CSharpCodeWriter writer, CodeBuilderContext context) + public CSharpBaseTypeVisitor([NotNull] CSharpCodeWriter writer, [NotNull] CodeBuilderContext context) : base(writer, context) - { } + { + } public string CurrentBaseType { get; set; } diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpCodeVisitor.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpCodeVisitor.cs index b99503b3f7..12b2d4e98e 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpCodeVisitor.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpCodeVisitor.cs @@ -1,10 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Globalization; using System.Linq; using Microsoft.AspNet.Razor.Parser.SyntaxTree; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp { @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp private CSharpPaddingBuilder _paddingBuilder; private CSharpTagHelperCodeRenderer _tagHelperCodeRenderer; - public CSharpCodeVisitor(CSharpCodeWriter writer, CodeBuilderContext context) + public CSharpCodeVisitor([NotNull] CSharpCodeWriter writer, [NotNull] CodeBuilderContext context) : base(writer, context) { _paddingBuilder = new CSharpPaddingBuilder(context.Host); @@ -34,13 +34,9 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp return _tagHelperCodeRenderer; } + [param: NotNull] set { - if (value == null) - { - throw new ArgumentNullException(nameof(TagHelperRenderer)); - } - _tagHelperCodeRenderer = value; } } diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpTagHelperAttributeValueVisitor.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpTagHelperAttributeValueVisitor.cs index 6f50ea9b03..62939e2ff4 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpTagHelperAttributeValueVisitor.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpTagHelperAttributeValueVisitor.cs @@ -3,6 +3,7 @@ using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser.SyntaxTree; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp { @@ -32,8 +33,8 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp /// is writing the value. /// public CSharpTagHelperAttributeValueVisitor( - CSharpCodeWriter writer, - CodeBuilderContext context, + [NotNull] CSharpCodeWriter writer, + [NotNull] CodeBuilderContext context, string attributeTypeName) : base(writer, context) { diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpUsingVisitor.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpUsingVisitor.cs index 7ea65b2fc3..449b22b6ed 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpUsingVisitor.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpUsingVisitor.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Razor.Parser.SyntaxTree; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp { @@ -13,7 +14,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp private bool _foundTagHelpers; - public CSharpUsingVisitor(CSharpCodeWriter writer, CodeBuilderContext context) + public CSharpUsingVisitor([NotNull] CSharpCodeWriter writer, [NotNull] CodeBuilderContext context) : base(writer, context) { ImportedUsings = new List(); diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/ChunkVisitor.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/ChunkVisitor.cs index a889ccdec3..ab7859604c 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/ChunkVisitor.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/ChunkVisitor.cs @@ -1,42 +1,33 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Generic; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor.Generator.Compiler { - public abstract class ChunkVisitor : IChunkVisitor where T : CodeWriter + public abstract class ChunkVisitor : IChunkVisitor + where TWriter : CodeWriter { - public ChunkVisitor(T writer, CodeBuilderContext context) + public ChunkVisitor([NotNull] TWriter writer, [NotNull] CodeBuilderContext context) { Writer = writer; Context = context; } - protected T Writer { get; private set; } + protected TWriter Writer { get; private set; } protected CodeBuilderContext Context { get; private set; } - public void Accept(IList chunks) + public void Accept([NotNull] IList chunks) { - if (chunks == null) - { - throw new ArgumentNullException("chunks"); - } - foreach (Chunk chunk in chunks) { Accept(chunk); } } - public virtual void Accept(Chunk chunk) + public virtual void Accept([NotNull] Chunk chunk) { - if (chunk == null) - { - throw new ArgumentNullException("chunk"); - } - if (chunk is LiteralChunk) { Visit((LiteralChunk)chunk); diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CodeVisitor.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CodeVisitor.cs index 2b4cd3ed0f..ffdbe7ba29 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CodeVisitor.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CodeVisitor.cs @@ -1,13 +1,17 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.Framework.Internal; + namespace Microsoft.AspNet.Razor.Generator.Compiler { - public class CodeVisitor : ChunkVisitor where T : CodeWriter + public class CodeVisitor : ChunkVisitor + where TWriter : CodeWriter { - public CodeVisitor(T writer, CodeBuilderContext context) + public CodeVisitor([NotNull] TWriter writer, [NotNull] CodeBuilderContext context) : base(writer, context) - { } + { + } protected override void Visit(LiteralChunk chunk) { diff --git a/src/Microsoft.AspNet.Razor/Generator/RazorCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/RazorCodeGenerator.cs index f828bd7f99..e069482f2a 100644 --- a/src/Microsoft.AspNet.Razor/Generator/RazorCodeGenerator.cs +++ b/src/Microsoft.AspNet.Razor/Generator/RazorCodeGenerator.cs @@ -4,6 +4,7 @@ using System; using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser.SyntaxTree; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor.Generator { @@ -11,20 +12,16 @@ namespace Microsoft.AspNet.Razor.Generator { private CodeGeneratorContext _context; - protected RazorCodeGenerator(string className, string rootNamespaceName, string sourceFileName, RazorEngineHost host) + protected RazorCodeGenerator( + string className, + [NotNull] string rootNamespaceName, + string sourceFileName, + [NotNull] RazorEngineHost host) { if (string.IsNullOrEmpty(className)) { throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "className"); } - if (rootNamespaceName == null) - { - throw new ArgumentNullException("rootNamespaceName"); - } - if (host == null) - { - throw new ArgumentNullException("host"); - } ClassName = className; RootNamespaceName = rootNamespaceName; diff --git a/src/Microsoft.AspNet.Razor/Parser/LanguageCharacteristics.cs b/src/Microsoft.AspNet.Razor/Parser/LanguageCharacteristics.cs index 5c6d1ce95e..f3f41ba8c7 100644 --- a/src/Microsoft.AspNet.Razor/Parser/LanguageCharacteristics.cs +++ b/src/Microsoft.AspNet.Razor/Parser/LanguageCharacteristics.cs @@ -13,6 +13,7 @@ namespace Microsoft.AspNet.Razor.Parser { [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "All generic type parameters are required")] public abstract class LanguageCharacteristics + where TSymbolType : struct where TTokenizer : Tokenizer where TSymbol : SymbolBase { diff --git a/src/Microsoft.AspNet.Razor/Parser/MarkupRewriter.cs b/src/Microsoft.AspNet.Razor/Parser/MarkupRewriter.cs index fb2a8ef069..1bd514a41c 100644 --- a/src/Microsoft.AspNet.Razor/Parser/MarkupRewriter.cs +++ b/src/Microsoft.AspNet.Razor/Parser/MarkupRewriter.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using Microsoft.AspNet.Razor.Parser.SyntaxTree; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor.Parser { @@ -13,12 +14,8 @@ namespace Microsoft.AspNet.Razor.Parser private Stack _blocks = new Stack(); private Action _markupSpanFactory; - protected MarkupRewriter(Action markupSpanFactory) + protected MarkupRewriter([NotNull] Action markupSpanFactory) { - if (markupSpanFactory == null) - { - throw new ArgumentNullException("markupSpanFactory"); - } _markupSpanFactory = markupSpanFactory; } diff --git a/src/Microsoft.AspNet.Razor/Parser/ParserVisitorExtensions.cs b/src/Microsoft.AspNet.Razor/Parser/ParserVisitorExtensions.cs index 178ba360be..0fa7689ba4 100644 --- a/src/Microsoft.AspNet.Razor/Parser/ParserVisitorExtensions.cs +++ b/src/Microsoft.AspNet.Razor/Parser/ParserVisitorExtensions.cs @@ -1,23 +1,14 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor.Parser { public static class ParserVisitorExtensions { - public static void Visit(this ParserVisitor self, ParserResults result) + public static void Visit([NotNull] this ParserVisitor self, [NotNull] ParserResults result) { - if (self == null) - { - throw new ArgumentNullException("self"); - } - if (result == null) - { - throw new ArgumentNullException("result"); - } - result.Document.Accept(self); foreach (RazorError error in result.ParserErrors) { diff --git a/src/Microsoft.AspNet.Razor/Parser/TextReaderExtensions.cs b/src/Microsoft.AspNet.Razor/Parser/TextReaderExtensions.cs index d2e9d04461..c0cfd20db2 100644 --- a/src/Microsoft.AspNet.Razor/Parser/TextReaderExtensions.cs +++ b/src/Microsoft.AspNet.Razor/Parser/TextReaderExtensions.cs @@ -5,63 +5,47 @@ using System; using System.IO; using System.Linq; using System.Text; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor.Parser { internal static class TextReaderExtensions { - public static string ReadUntil(this TextReader reader, char terminator) + public static string ReadUntil([NotNull] this TextReader reader, char terminator) { return ReadUntil(reader, terminator, inclusive: false); } - public static string ReadUntil(this TextReader reader, char terminator, bool inclusive) + public static string ReadUntil([NotNull] this TextReader reader, char terminator, bool inclusive) { - if (reader == null) - { - throw new ArgumentNullException("reader"); - } - // Rather not allocate an array to use ReadUntil(TextReader, params char[]) so we'll just call the predicate version directly - return reader.ReadUntil(c => c == terminator, inclusive); + return ReadUntil(reader, c => c == terminator, inclusive); } - public static string ReadUntil(this TextReader reader, params char[] terminators) + public static string ReadUntil([NotNull] this TextReader reader, [NotNull] params char[] terminators) { // NOTE: Using named parameters would be difficult here, hence the inline comment - return reader.ReadUntil(inclusive: false, terminators: terminators); + return ReadUntil(reader, inclusive: false, terminators: terminators); } - public static string ReadUntil(this TextReader reader, bool inclusive, params char[] terminators) + public static string ReadUntil( + [NotNull] this TextReader reader, + bool inclusive, + [NotNull] params char[] terminators) { - if (reader == null) - { - throw new ArgumentNullException("reader"); - } - if (terminators == null) - { - throw new ArgumentNullException("terminators"); - } - - return reader.ReadUntil(c => terminators.Any(tc => tc == c), inclusive: inclusive); + return ReadUntil(reader, c => terminators.Any(tc => tc == c), inclusive: inclusive); } - public static string ReadUntil(this TextReader reader, Predicate condition) + public static string ReadUntil([NotNull] this TextReader reader, [NotNull] Predicate condition) { - return reader.ReadUntil(condition, inclusive: false); + return ReadUntil(reader, condition, inclusive: false); } - public static string ReadUntil(this TextReader reader, Predicate condition, bool inclusive) + public static string ReadUntil( + [NotNull] this TextReader reader, + [NotNull] Predicate condition, + bool inclusive) { - if (reader == null) - { - throw new ArgumentNullException("reader"); - } - if (condition == null) - { - throw new ArgumentNullException("condition"); - } - var builder = new StringBuilder(); var ch = -1; while ((ch = reader.Peek()) != -1 && !condition((char)ch)) @@ -78,33 +62,27 @@ namespace Microsoft.AspNet.Razor.Parser return builder.ToString(); } - public static string ReadWhile(this TextReader reader, Predicate condition) + public static string ReadWhile([NotNull] this TextReader reader, [NotNull] Predicate condition) { - return reader.ReadWhile(condition, inclusive: false); + return ReadWhile(reader, condition, inclusive: false); } - public static string ReadWhile(this TextReader reader, Predicate condition, bool inclusive) + public static string ReadWhile( + [NotNull] this TextReader reader, + [NotNull] Predicate condition, + bool inclusive) { - if (reader == null) - { - throw new ArgumentNullException("reader"); - } - if (condition == null) - { - throw new ArgumentNullException("condition"); - } - - return reader.ReadUntil(ch => !condition(ch), inclusive); + return ReadUntil(reader, ch => !condition(ch), inclusive); } - public static string ReadWhiteSpace(this TextReader reader) + public static string ReadWhiteSpace([NotNull] this TextReader reader) { - return reader.ReadWhile(c => Char.IsWhiteSpace(c)); + return ReadWhile(reader, c => Char.IsWhiteSpace(c)); } - public static string ReadUntilWhiteSpace(this TextReader reader) + public static string ReadUntilWhiteSpace([NotNull] this TextReader reader) { - return reader.ReadUntil(c => Char.IsWhiteSpace(c)); + return ReadUntil(reader, c => Char.IsWhiteSpace(c)); } } } diff --git a/src/Microsoft.AspNet.Razor/Parser/TokenizerBackedParser.Helpers.cs b/src/Microsoft.AspNet.Razor/Parser/TokenizerBackedParser.Helpers.cs index caf0bb7e1b..64f03c983c 100644 --- a/src/Microsoft.AspNet.Razor/Parser/TokenizerBackedParser.Helpers.cs +++ b/src/Microsoft.AspNet.Razor/Parser/TokenizerBackedParser.Helpers.cs @@ -16,6 +16,7 @@ using Microsoft.AspNet.Razor.Utils; namespace Microsoft.AspNet.Razor.Parser { public abstract partial class TokenizerBackedParser : ParserBase + where TSymbolType : struct where TTokenizer : Tokenizer where TSymbol : SymbolBase { diff --git a/src/Microsoft.AspNet.Razor/Parser/TokenizerBackedParser.cs b/src/Microsoft.AspNet.Razor/Parser/TokenizerBackedParser.cs index 0cad86d87d..6ffcdab753 100644 --- a/src/Microsoft.AspNet.Razor/Parser/TokenizerBackedParser.cs +++ b/src/Microsoft.AspNet.Razor/Parser/TokenizerBackedParser.cs @@ -11,6 +11,7 @@ namespace Microsoft.AspNet.Razor.Parser { [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "All generic type parameters are required")] public abstract partial class TokenizerBackedParser : ParserBase + where TSymbolType : struct where TTokenizer : Tokenizer where TSymbol : SymbolBase { @@ -104,7 +105,7 @@ namespace Microsoft.AspNet.Razor.Parser PutBack(symbols[i]); } - // The PutBacks above will set CurrentSymbol to null. EnsureCurrent will set our CurrentSymbol to the + // The PutBacks above will set CurrentSymbol to null. EnsureCurrent will set our CurrentSymbol to the // next symbol. EnsureCurrent(); diff --git a/src/Microsoft.AspNet.Razor/Parser/WhitespaceRewriter.cs b/src/Microsoft.AspNet.Razor/Parser/WhitespaceRewriter.cs index 8493569719..99855d20b1 100644 --- a/src/Microsoft.AspNet.Razor/Parser/WhitespaceRewriter.cs +++ b/src/Microsoft.AspNet.Razor/Parser/WhitespaceRewriter.cs @@ -5,12 +5,14 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Razor.Parser.SyntaxTree; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor.Parser { internal class WhiteSpaceRewriter : MarkupRewriter { - public WhiteSpaceRewriter(Action markupSpanFactory) : base(markupSpanFactory) + public WhiteSpaceRewriter([NotNull] Action markupSpanFactory) + : base(markupSpanFactory) { } diff --git a/src/Microsoft.AspNet.Razor/RazorEditorParser.cs b/src/Microsoft.AspNet.Razor/RazorEditorParser.cs index 5a6049ee10..a5c9cd027e 100644 --- a/src/Microsoft.AspNet.Razor/RazorEditorParser.cs +++ b/src/Microsoft.AspNet.Razor/RazorEditorParser.cs @@ -9,6 +9,7 @@ using System.IO; using Microsoft.AspNet.Razor.Editor; using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Text; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor { @@ -67,12 +68,8 @@ namespace Microsoft.AspNet.Razor /// /// The which defines the environment in which the generated code will live. should be set if design-time code mappings are desired /// The physical path to use in line pragmas - public RazorEditorParser(RazorEngineHost host, string sourceFileName) + public RazorEditorParser([NotNull] RazorEngineHost host, string sourceFileName) { - if (host == null) - { - throw new ArgumentNullException("host"); - } if (string.IsNullOrEmpty(sourceFileName)) { throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "sourceFileName"); diff --git a/src/Microsoft.AspNet.Razor/RazorEngineHost.cs b/src/Microsoft.AspNet.Razor/RazorEngineHost.cs index 5743b93d47..2903092041 100644 --- a/src/Microsoft.AspNet.Razor/RazorEngineHost.cs +++ b/src/Microsoft.AspNet.Razor/RazorEngineHost.cs @@ -51,24 +51,17 @@ namespace Microsoft.AspNet.Razor /// Creates a host which uses the specified code language and the HTML markup language /// /// The code language to use - public RazorEngineHost(RazorCodeLanguage codeLanguage) + public RazorEngineHost([NotNull] RazorCodeLanguage codeLanguage) : this(codeLanguage, () => new HtmlMarkupParser()) { } [SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "The code path is safe, it is a property setter and not dependent on other state")] - public RazorEngineHost(RazorCodeLanguage codeLanguage, Func markupParserFactory) + public RazorEngineHost( + [NotNull] RazorCodeLanguage codeLanguage, + [NotNull] Func markupParserFactory) : this() { - if (codeLanguage == null) - { - throw new ArgumentNullException("codeLanguage"); - } - if (markupParserFactory == null) - { - throw new ArgumentNullException("markupParserFactory"); - } - CodeLanguage = codeLanguage; _markupParserFactory = markupParserFactory; } @@ -173,8 +166,9 @@ namespace Microsoft.AspNet.Razor /// The /// The file name of the Razor file being parsed. /// Either the same code parser, after modifications, or a different code parser. - public virtual RazorParser DecorateRazorParser([NotNull] RazorParser incomingRazorParser, - string sourceFileName) + public virtual RazorParser DecorateRazorParser( + [NotNull] RazorParser incomingRazorParser, + string sourceFileName) { return incomingRazorParser; } @@ -184,12 +178,8 @@ namespace Microsoft.AspNet.Razor /// /// The code parser /// Either the same code parser, after modifications, or a different code parser - public virtual ParserBase DecorateCodeParser(ParserBase incomingCodeParser) + public virtual ParserBase DecorateCodeParser([NotNull] ParserBase incomingCodeParser) { - if (incomingCodeParser == null) - { - throw new ArgumentNullException("incomingCodeParser"); - } return incomingCodeParser; } @@ -198,12 +188,8 @@ namespace Microsoft.AspNet.Razor /// /// The markup parser /// Either the same markup parser, after modifications, or a different markup parser - public virtual ParserBase DecorateMarkupParser(ParserBase incomingMarkupParser) + public virtual ParserBase DecorateMarkupParser([NotNull] ParserBase incomingMarkupParser) { - if (incomingMarkupParser == null) - { - throw new ArgumentNullException("incomingMarkupParser"); - } return incomingMarkupParser; } @@ -212,12 +198,8 @@ namespace Microsoft.AspNet.Razor /// /// The code generator /// Either the same code generator, after modifications, or a different code generator - public virtual RazorCodeGenerator DecorateCodeGenerator(RazorCodeGenerator incomingCodeGenerator) + public virtual RazorCodeGenerator DecorateCodeGenerator([NotNull] RazorCodeGenerator incomingCodeGenerator) { - if (incomingCodeGenerator == null) - { - throw new ArgumentNullException("incomingCodeGenerator"); - } return incomingCodeGenerator; } @@ -226,12 +208,10 @@ namespace Microsoft.AspNet.Razor /// /// The code builder /// Either the same code builder, after modifications, or a different code builder. - public virtual CodeBuilder DecorateCodeBuilder(CodeBuilder incomingBuilder, CodeBuilderContext context) + public virtual CodeBuilder DecorateCodeBuilder( + [NotNull] CodeBuilder incomingBuilder, + CodeBuilderContext context) { - if (incomingBuilder == null) - { - throw new ArgumentNullException("incomingBuilder"); - } return incomingBuilder; } diff --git a/src/Microsoft.AspNet.Razor/RazorTemplateEngine.cs b/src/Microsoft.AspNet.Razor/RazorTemplateEngine.cs index 37fa65c6fc..8b189d5df4 100644 --- a/src/Microsoft.AspNet.Razor/RazorTemplateEngine.cs +++ b/src/Microsoft.AspNet.Razor/RazorTemplateEngine.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; @@ -28,14 +27,11 @@ namespace Microsoft.AspNet.Razor /// /// Constructs a new RazorTemplateEngine with the specified host /// - /// The host which defines the environment in which the generated template code will live - public RazorTemplateEngine(RazorEngineHost host) + /// + /// The host which defines the environment in which the generated template code will live. + /// + public RazorTemplateEngine([NotNull] RazorEngineHost host) { - if (host == null) - { - throw new ArgumentNullException("host"); - } - Host = host; } @@ -44,7 +40,7 @@ namespace Microsoft.AspNet.Razor /// public RazorEngineHost Host { get; } - public ParserResults ParseTemplate(ITextBuffer input) + public ParserResults ParseTemplate([NotNull] ITextBuffer input) { return ParseTemplate(input, cancelToken: null); } @@ -53,29 +49,32 @@ namespace Microsoft.AspNet.Razor /// Parses the template specified by the TextBuffer and returns it's result /// /// + /// /// IMPORTANT: This does NOT need to be called before GeneratedCode! GenerateCode will automatically /// parse the document first. - /// + /// + /// /// The cancel token provided can be used to cancel the parse. However, please note /// that the parse occurs _synchronously_, on the callers thread. This parameter is /// provided so that if the caller is in a background thread with a CancellationToken, /// it can pass it along to the parser. + /// /// - /// The input text to parse - /// A token used to cancel the parser - /// The resulting parse tree + /// The input text to parse. + /// A token used to cancel the parser. + /// The resulting parse tree. [SuppressMessage( "Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Input object would be disposed if we dispose the wrapper. We don't own the input so " + "we don't want to dispose it")] - public ParserResults ParseTemplate(ITextBuffer input, CancellationToken? cancelToken) + public ParserResults ParseTemplate([NotNull] ITextBuffer input, CancellationToken? cancelToken) { return ParseTemplateCore(input.ToDocument(), sourceFileName: null, cancelToken: cancelToken); } // See ParseTemplate(ITextBuffer, CancellationToken?), // this overload simply wraps a TextReader in a TextBuffer (see ITextBuffer and BufferingTextReader) - public ParserResults ParseTemplate(TextReader input, string sourceFileName) + public ParserResults ParseTemplate([NotNull] TextReader input, string sourceFileName) { return ParseTemplateCore(new SeekableTextReader(input), sourceFileName, cancelToken: null); } @@ -85,13 +84,13 @@ namespace Microsoft.AspNet.Razor "CA2000:Dispose objects before losing scope", Justification = "Input object would be disposed if we dispose the wrapper. We don't own the input so " + "we don't want to dispose it")] - public ParserResults ParseTemplate(TextReader input, CancellationToken? cancelToken) + public ParserResults ParseTemplate([NotNull] TextReader input, CancellationToken? cancelToken) { return ParseTemplateCore(new SeekableTextReader(input), sourceFileName: null, cancelToken: cancelToken); } protected internal virtual ParserResults ParseTemplateCore( - ITextDocument input, + [NotNull] ITextDocument input, string sourceFileName, CancellationToken? cancelToken) { @@ -101,12 +100,12 @@ namespace Microsoft.AspNet.Razor return parser.Parse(input); } - public GeneratorResults GenerateCode(ITextBuffer input) + public GeneratorResults GenerateCode([NotNull] ITextBuffer input) { return GenerateCode(input, className: null, rootNamespace: null, sourceFileName: null, cancelToken: null); } - public GeneratorResults GenerateCode(ITextBuffer input, CancellationToken? cancelToken) + public GeneratorResults GenerateCode([NotNull] ITextBuffer input, CancellationToken? cancelToken) { return GenerateCode( input, @@ -116,7 +115,11 @@ namespace Microsoft.AspNet.Razor cancelToken: cancelToken); } - public GeneratorResults GenerateCode(ITextBuffer input, string className, string rootNamespace, string sourceFileName) + public GeneratorResults GenerateCode( + [NotNull] ITextBuffer input, + string className, + string rootNamespace, + string sourceFileName) { return GenerateCode(input, className, rootNamespace, sourceFileName, cancelToken: null); } @@ -125,22 +128,34 @@ namespace Microsoft.AspNet.Razor /// Parses the template specified by the TextBuffer, generates code for it, and returns the constructed code. /// /// + /// /// The cancel token provided can be used to cancel the parse. However, please note /// that the parse occurs _synchronously_, on the callers thread. This parameter is /// provided so that if the caller is in a background thread with a CancellationToken, /// it can pass it along to the parser. - /// + /// + /// /// The className, rootNamespace and sourceFileName parameters are optional and override the default /// specified by the Host. For example, the WebPageRazorHost in System.Web.WebPages.Razor configures the /// Class Name, Root Namespace and Source File Name based on the virtual path of the page being compiled. /// However, the built-in RazorEngineHost class uses constant defaults, so the caller will likely want to - /// change them using these parameters + /// change them using these parameters. + /// /// - /// The input text to parse - /// A token used to cancel the parser - /// The name of the generated class, overriding whatever is specified in the Host. The default value (defined in the Host) can be used by providing null for this argument - /// The namespace in which the generated class will reside, overriding whatever is specified in the Host. The default value (defined in the Host) can be used by providing null for this argument - /// The file name to use in line pragmas, usually the original Razor file, overriding whatever is specified in the Host. The default value (defined in the Host) can be used by providing null for this argument + /// The input text to parse. + /// A token used to cancel the parser. + /// + /// The name of the generated class, overriding whatever is specified in the Host. The default value (defined + /// in the Host) can be used by providing null for this argument. + /// + /// The namespace in which the generated class will reside, overriding whatever is + /// specified in the Host. The default value (defined in the Host) can be used by providing null for this + /// argument. + /// + /// + /// The file name to use in line pragmas, usually the original Razor file, overriding whatever is specified in + /// the Host. The default value (defined in the Host) can be used by providing null for this argument. + /// /// The resulting parse tree AND generated code. [SuppressMessage( "Microsoft.Reliability", @@ -148,7 +163,7 @@ namespace Microsoft.AspNet.Razor Justification = "Input object would be disposed if we dispose the wrapper. We don't own the input so " + "we don't want to dispose it")] public GeneratorResults GenerateCode( - ITextBuffer input, + [NotNull] ITextBuffer input, string className, string rootNamespace, string sourceFileName, @@ -164,12 +179,12 @@ namespace Microsoft.AspNet.Razor } // See GenerateCode override which takes ITextBuffer, and BufferingTextReader for details. - public GeneratorResults GenerateCode(TextReader input) + public GeneratorResults GenerateCode([NotNull] TextReader input) { return GenerateCode(input, className: null, rootNamespace: null, sourceFileName: null, cancelToken: null); } - public GeneratorResults GenerateCode(TextReader input, CancellationToken? cancelToken) + public GeneratorResults GenerateCode([NotNull] TextReader input, CancellationToken? cancelToken) { return GenerateCode( input, @@ -180,7 +195,7 @@ namespace Microsoft.AspNet.Razor } public GeneratorResults GenerateCode( - TextReader input, + [NotNull] TextReader input, string className, string rootNamespace, string sourceFileName) @@ -196,7 +211,9 @@ namespace Microsoft.AspNet.Razor /// (Host.DefaultClassName). /// The namespace in which the generated class will reside. When null, /// defaults to (Host.DefaultNamespace). - /// The file name to use in line pragmas, usually the original Razor file. + /// + /// The file name to use in line pragmas, usually the original Razor file. + /// /// A that represents the results of parsing the content. /// /// This overload calculates the checksum of the contents of prior to code @@ -264,7 +281,7 @@ namespace Microsoft.AspNet.Razor Justification = "Input object would be disposed if we dispose the wrapper. We don't own the input so " + "we don't want to dispose it")] public GeneratorResults GenerateCode( - TextReader input, + [NotNull] TextReader input, string className, string rootNamespace, string sourceFileName, @@ -280,7 +297,7 @@ namespace Microsoft.AspNet.Razor } protected internal virtual GeneratorResults GenerateCodeCore( - ITextDocument input, + [NotNull] ITextDocument input, string className, string rootNamespace, string sourceFileName, diff --git a/src/Microsoft.AspNet.Razor/Text/BufferingTextReader.cs b/src/Microsoft.AspNet.Razor/Text/BufferingTextReader.cs index 3c683e52bb..8e05ebaa6c 100644 --- a/src/Microsoft.AspNet.Razor/Text/BufferingTextReader.cs +++ b/src/Microsoft.AspNet.Razor/Text/BufferingTextReader.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Text; using Microsoft.AspNet.Razor.Utils; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor.Text { @@ -17,13 +18,8 @@ namespace Microsoft.AspNet.Razor.Text private int _currentCharacter; private SourceLocationTracker _locationTracker; - public BufferingTextReader(TextReader source) + public BufferingTextReader([NotNull] TextReader source) { - if (source == null) - { - throw new ArgumentNullException("source"); - } - InnerReader = source; _locationTracker = new SourceLocationTracker(); diff --git a/src/Microsoft.AspNet.Razor/Text/LocationTagged.cs b/src/Microsoft.AspNet.Razor/Text/LocationTagged.cs index 1e8a95a228..8e02084175 100644 --- a/src/Microsoft.AspNet.Razor/Text/LocationTagged.cs +++ b/src/Microsoft.AspNet.Razor/Text/LocationTagged.cs @@ -4,42 +4,38 @@ using System; using System.Diagnostics; using System.Globalization; +using Microsoft.Framework.Internal; using Microsoft.Internal.Web.Utils; namespace Microsoft.AspNet.Razor.Text { [DebuggerDisplay("({Location})\"{Value}\"")] - public class LocationTagged : IFormattable + public class LocationTagged : IFormattable { private LocationTagged() { Location = SourceLocation.Undefined; - Value = default(T); + Value = default(TValue); } - public LocationTagged(T value, int offset, int line, int col) + public LocationTagged([NotNull] TValue value, int offset, int line, int col) : this(value, new SourceLocation(offset, line, col)) { } - public LocationTagged(T value, SourceLocation location) + public LocationTagged([NotNull] TValue value, SourceLocation location) { - if (value == null) - { - throw new ArgumentNullException("value"); - } - Location = location; Value = value; } public SourceLocation Location { get; } - public T Value { get; } + public TValue Value { get; } public override bool Equals(object obj) { - LocationTagged other = obj as LocationTagged; + LocationTagged other = obj as LocationTagged; if (ReferenceEquals(other, null)) { return false; @@ -81,17 +77,17 @@ namespace Microsoft.AspNet.Razor.Text } } - public static implicit operator T(LocationTagged value) + public static implicit operator TValue(LocationTagged value) { return value.Value; } - public static bool operator ==(LocationTagged left, LocationTagged right) + public static bool operator ==(LocationTagged left, LocationTagged right) { return Equals(left, right); } - public static bool operator !=(LocationTagged left, LocationTagged right) + public static bool operator !=(LocationTagged left, LocationTagged right) { return !Equals(left, right); } diff --git a/src/Microsoft.AspNet.Razor/Text/SeekableTextReader.cs b/src/Microsoft.AspNet.Razor/Text/SeekableTextReader.cs index cf0eb9b53a..db2582a37b 100644 --- a/src/Microsoft.AspNet.Razor/Text/SeekableTextReader.cs +++ b/src/Microsoft.AspNet.Razor/Text/SeekableTextReader.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor.Text { @@ -18,12 +19,12 @@ namespace Microsoft.AspNet.Razor.Text UpdateState(); } - public SeekableTextReader(TextReader source) + public SeekableTextReader([NotNull] TextReader source) : this(source.ReadToEnd()) { } - public SeekableTextReader(ITextBuffer buffer) + public SeekableTextReader([NotNull] ITextBuffer buffer) : this(buffer.ReadToEnd()) { } diff --git a/src/Microsoft.AspNet.Razor/Text/TextBufferReader.cs b/src/Microsoft.AspNet.Razor/Text/TextBufferReader.cs index 6bc5f1a0ff..adb961159b 100644 --- a/src/Microsoft.AspNet.Razor/Text/TextBufferReader.cs +++ b/src/Microsoft.AspNet.Razor/Text/TextBufferReader.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Razor.Utils; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor.Text { @@ -12,13 +13,8 @@ namespace Microsoft.AspNet.Razor.Text private Stack _bookmarks = new Stack(); private SourceLocationTracker _tracker = new SourceLocationTracker(); - public TextBufferReader(ITextBuffer buffer) + public TextBufferReader([NotNull] ITextBuffer buffer) { - if (buffer == null) - { - throw new ArgumentNullException("buffer"); - } - InnerBuffer = buffer; } diff --git a/src/Microsoft.AspNet.Razor/Text/TextChange.cs b/src/Microsoft.AspNet.Razor/Text/TextChange.cs index f6d07668f4..697922ae12 100644 --- a/src/Microsoft.AspNet.Razor/Text/TextChange.cs +++ b/src/Microsoft.AspNet.Razor/Text/TextChange.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Globalization; using System.Text; using Microsoft.AspNet.Razor.Parser.SyntaxTree; +using Microsoft.Framework.Internal; using Microsoft.Internal.Web.Utils; namespace Microsoft.AspNet.Razor.Text @@ -23,7 +24,13 @@ namespace Microsoft.AspNet.Razor.Text { } - public TextChange(int oldPosition, int oldLength, ITextBuffer oldBuffer, int newPosition, int newLength, ITextBuffer newBuffer) + public TextChange( + int oldPosition, + int oldLength, + [NotNull] ITextBuffer oldBuffer, + int newPosition, + int newLength, + [NotNull] ITextBuffer newBuffer) : this() { if (oldPosition < 0) @@ -42,14 +49,6 @@ namespace Microsoft.AspNet.Razor.Text { throw new ArgumentOutOfRangeException("newLength", CommonResources.FormatArgument_Must_Be_GreaterThanOrEqualTo(0)); } - if (oldBuffer == null) - { - throw new ArgumentNullException("oldBuffer"); - } - if (newBuffer == null) - { - throw new ArgumentNullException("newBuffer"); - } OldPosition = oldPosition; NewPosition = newPosition; diff --git a/src/Microsoft.AspNet.Razor/Tokenizer/CSharpTokenizer.cs b/src/Microsoft.AspNet.Razor/Tokenizer/CSharpTokenizer.cs index a5386595c8..daea5adc65 100644 --- a/src/Microsoft.AspNet.Razor/Tokenizer/CSharpTokenizer.cs +++ b/src/Microsoft.AspNet.Razor/Tokenizer/CSharpTokenizer.cs @@ -7,6 +7,7 @@ using System.Diagnostics; using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Tokenizer.Symbols; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor.Tokenizer { @@ -14,7 +15,7 @@ namespace Microsoft.AspNet.Razor.Tokenizer { private Dictionary> _operatorHandlers; - public CSharpTokenizer(ITextDocument source) + public CSharpTokenizer([NotNull] ITextDocument source) : base(source) { CurrentState = Data; diff --git a/src/Microsoft.AspNet.Razor/Tokenizer/HtmlTokenizer.cs b/src/Microsoft.AspNet.Razor/Tokenizer/HtmlTokenizer.cs index 5430238939..c43ca4d773 100644 --- a/src/Microsoft.AspNet.Razor/Tokenizer/HtmlTokenizer.cs +++ b/src/Microsoft.AspNet.Razor/Tokenizer/HtmlTokenizer.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Tokenizer.Symbols; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor.Tokenizer { @@ -14,7 +15,7 @@ namespace Microsoft.AspNet.Razor.Tokenizer { private const char TransitionChar = '@'; - public HtmlTokenizer(ITextDocument source) + public HtmlTokenizer([NotNull] ITextDocument source) : base(source) { CurrentState = Data; diff --git a/src/Microsoft.AspNet.Razor/Tokenizer/Symbols/CSharpSymbol.cs b/src/Microsoft.AspNet.Razor/Tokenizer/Symbols/CSharpSymbol.cs index ab082a7076..5f114cd310 100644 --- a/src/Microsoft.AspNet.Razor/Tokenizer/Symbols/CSharpSymbol.cs +++ b/src/Microsoft.AspNet.Razor/Tokenizer/Symbols/CSharpSymbol.cs @@ -3,28 +3,39 @@ using System.Collections.Generic; using System.Linq; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor.Tokenizer.Symbols { public class CSharpSymbol : SymbolBase { // Helper constructor - public CSharpSymbol(int offset, int line, int column, string content, CSharpSymbolType type) + public CSharpSymbol(int offset, int line, int column, [NotNull] string content, CSharpSymbolType type) : this(new SourceLocation(offset, line, column), content, type, Enumerable.Empty()) { } - public CSharpSymbol(SourceLocation start, string content, CSharpSymbolType type) + public CSharpSymbol(SourceLocation start, [NotNull] string content, CSharpSymbolType type) : this(start, content, type, Enumerable.Empty()) { } - public CSharpSymbol(int offset, int line, int column, string content, CSharpSymbolType type, IEnumerable errors) + public CSharpSymbol( + int offset, + int line, + int column, + [NotNull] string content, + CSharpSymbolType type, + IEnumerable errors) : base(new SourceLocation(offset, line, column), content, type, errors) { } - public CSharpSymbol(SourceLocation start, string content, CSharpSymbolType type, IEnumerable errors) + public CSharpSymbol( + SourceLocation start, + [NotNull] string content, + CSharpSymbolType type, + IEnumerable errors) : base(start, content, type, errors) { } diff --git a/src/Microsoft.AspNet.Razor/Tokenizer/Symbols/HtmlSymbol.cs b/src/Microsoft.AspNet.Razor/Tokenizer/Symbols/HtmlSymbol.cs index 10f038f5e0..639974e40f 100644 --- a/src/Microsoft.AspNet.Razor/Tokenizer/Symbols/HtmlSymbol.cs +++ b/src/Microsoft.AspNet.Razor/Tokenizer/Symbols/HtmlSymbol.cs @@ -3,28 +3,39 @@ using System.Collections.Generic; using System.Linq; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor.Tokenizer.Symbols { public class HtmlSymbol : SymbolBase { // Helper constructor - public HtmlSymbol(int offset, int line, int column, string content, HtmlSymbolType type) + public HtmlSymbol(int offset, int line, int column, [NotNull] string content, HtmlSymbolType type) : this(new SourceLocation(offset, line, column), content, type, Enumerable.Empty()) { } - public HtmlSymbol(SourceLocation start, string content, HtmlSymbolType type) + public HtmlSymbol(SourceLocation start, [NotNull] string content, HtmlSymbolType type) : base(start, content, type, Enumerable.Empty()) { } - public HtmlSymbol(int offset, int line, int column, string content, HtmlSymbolType type, IEnumerable errors) + public HtmlSymbol( + int offset, + int line, + int column, + [NotNull] string content, + HtmlSymbolType type, + IEnumerable errors) : base(new SourceLocation(offset, line, column), content, type, errors) { } - public HtmlSymbol(SourceLocation start, string content, HtmlSymbolType type, IEnumerable errors) + public HtmlSymbol( + SourceLocation start, + [NotNull] string content, + HtmlSymbolType type, + IEnumerable errors) : base(start, content, type, errors) { } diff --git a/src/Microsoft.AspNet.Razor/Tokenizer/Symbols/SymbolBase.cs b/src/Microsoft.AspNet.Razor/Tokenizer/Symbols/SymbolBase.cs index 7ae20e99ef..cc96f199f1 100644 --- a/src/Microsoft.AspNet.Razor/Tokenizer/Symbols/SymbolBase.cs +++ b/src/Microsoft.AspNet.Razor/Tokenizer/Symbols/SymbolBase.cs @@ -5,23 +5,20 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Globalization; +using Microsoft.Framework.Internal; using Microsoft.Internal.Web.Utils; namespace Microsoft.AspNet.Razor.Tokenizer.Symbols { public abstract class SymbolBase : ISymbol + where TType: struct { - protected SymbolBase(SourceLocation start, string content, TType type, IEnumerable errors) + protected SymbolBase( + SourceLocation start, + [NotNull] string content, + TType type, + IEnumerable errors) { - if (content == null) - { - throw new ArgumentNullException("content"); - } - if (type == null) - { - throw new ArgumentNullException("type"); - } - Start = start; Content = content; Type = type; diff --git a/src/Microsoft.AspNet.Razor/Tokenizer/Tokenizer.cs b/src/Microsoft.AspNet.Razor/Tokenizer/Tokenizer.cs index 561d315627..ca6ae0d43f 100644 --- a/src/Microsoft.AspNet.Razor/Tokenizer/Tokenizer.cs +++ b/src/Microsoft.AspNet.Razor/Tokenizer/Tokenizer.cs @@ -13,19 +13,17 @@ using System.Text; using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Tokenizer.Symbols; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor.Tokenizer { public abstract partial class Tokenizer : StateMachine, ITokenizer + where TSymbolType : struct where TSymbol : SymbolBase { [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "TextDocumentReader does not require disposal")] - protected Tokenizer(ITextDocument source) + protected Tokenizer([NotNull] ITextDocument source) { - if (source == null) - { - throw new ArgumentNullException("source"); - } Source = new TextDocumentReader(source); Buffer = new StringBuilder(); CurrentErrors = new List(); diff --git a/src/Microsoft.AspNet.Razor/Tokenizer/TokenizerView.cs b/src/Microsoft.AspNet.Razor/Tokenizer/TokenizerView.cs index de64bedc44..8c4df8bca8 100644 --- a/src/Microsoft.AspNet.Razor/Tokenizer/TokenizerView.cs +++ b/src/Microsoft.AspNet.Razor/Tokenizer/TokenizerView.cs @@ -11,6 +11,7 @@ namespace Microsoft.AspNet.Razor.Tokenizer { [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "All generic parameters are required")] public class TokenizerView + where TSymbolType : struct where TTokenizer : Tokenizer where TSymbol : SymbolBase { diff --git a/src/Microsoft.AspNet.Razor/Utils/DisposableAction.cs b/src/Microsoft.AspNet.Razor/Utils/DisposableAction.cs index 06622eceb3..3d01811ebb 100644 --- a/src/Microsoft.AspNet.Razor/Utils/DisposableAction.cs +++ b/src/Microsoft.AspNet.Razor/Utils/DisposableAction.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Razor.Utils { @@ -10,12 +11,8 @@ namespace Microsoft.AspNet.Razor.Utils private Action _action; private bool _invoked; - public DisposableAction(Action action) + public DisposableAction([NotNull] Action action) { - if (action == null) - { - throw new ArgumentNullException("action"); - } _action = action; } diff --git a/test/Microsoft.AspNet.Razor.Test/Editor/RazorEditorParserTest.cs b/test/Microsoft.AspNet.Razor.Test/Editor/RazorEditorParserTest.cs index 65ddd3db3e..4ea8936832 100644 --- a/test/Microsoft.AspNet.Razor.Test/Editor/RazorEditorParserTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Editor/RazorEditorParserTest.cs @@ -21,12 +21,6 @@ namespace Microsoft.AspNet.Razor.Test.Editor private static readonly TestFile SimpleCSHTMLDocumentGenerated = TestFile.Create("TestFiles/DesignTime/Simple.txt"); private const string TestLinePragmaFileName = "C:\\This\\Path\\Is\\Just\\For\\Line\\Pragmas.cshtml"; - [Fact] - public void ConstructorRequiresNonNullHost() - { - Assert.Throws("host", () => new RazorEditorParser(null, TestLinePragmaFileName)); - } - [Fact] public void ConstructorRequiresNonNullPhysicalPath() { diff --git a/test/Microsoft.AspNet.Razor.Test/Framework/RawTextSymbol.cs b/test/Microsoft.AspNet.Razor.Test/Framework/RawTextSymbol.cs index 39f1f22e73..c967ed855e 100644 --- a/test/Microsoft.AspNet.Razor.Test/Framework/RawTextSymbol.cs +++ b/test/Microsoft.AspNet.Razor.Test/Framework/RawTextSymbol.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Globalization; using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Text; @@ -16,11 +15,6 @@ namespace Microsoft.AspNet.Razor.Test.Framework public RawTextSymbol(SourceLocation start, string content) { - if (content == null) - { - throw new ArgumentNullException("content"); - } - Start = start; Content = content; } @@ -28,7 +22,7 @@ namespace Microsoft.AspNet.Razor.Test.Framework public override bool Equals(object obj) { var other = obj as RawTextSymbol; - return Equals(Start, other.Start) && Equals(Content, other.Content); + return other != null && Equals(Start, other.Start) && Equals(Content, other.Content); } internal bool EquivalentTo(ISymbol sym) diff --git a/test/Microsoft.AspNet.Razor.Test/Generator/CSharpRazorCodeGeneratorTest.cs b/test/Microsoft.AspNet.Razor.Test/Generator/CSharpRazorCodeGeneratorTest.cs index 2dc2e5626b..f6346c987a 100644 --- a/test/Microsoft.AspNet.Razor.Test/Generator/CSharpRazorCodeGeneratorTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Generator/CSharpRazorCodeGeneratorTest.cs @@ -42,24 +42,12 @@ namespace Microsoft.AspNet.Razor.Test.Generator Assert.Throws("className", () => new CSharpRazorCodeGenerator(string.Empty, TestRootNamespaceName, TestPhysicalPath, CreateHost())); } - [Fact] - public void ConstructorRequiresNonNullRootNamespaceName() - { - Assert.Throws("rootNamespaceName", () => new CSharpRazorCodeGenerator("Foo", null, TestPhysicalPath, CreateHost())); - } - [Fact] public void ConstructorAllowsEmptyRootNamespaceName() { new CSharpRazorCodeGenerator("Foo", string.Empty, TestPhysicalPath, CreateHost()); } - [Fact] - public void ConstructorRequiresNonNullHost() - { - Assert.Throws("host", () => new CSharpRazorCodeGenerator("Foo", TestRootNamespaceName, TestPhysicalPath, null)); - } - [Theory] [InlineData("NestedCodeBlocks")] [InlineData("CodeBlock")] diff --git a/test/Microsoft.AspNet.Razor.Test/Parser/ParserVisitorExtensionsTest.cs b/test/Microsoft.AspNet.Razor.Test/Parser/ParserVisitorExtensionsTest.cs index 0cd7f7e70e..53c2acbc4a 100644 --- a/test/Microsoft.AspNet.Razor.Test/Parser/ParserVisitorExtensionsTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Parser/ParserVisitorExtensionsTest.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. #if !DNXCORE50 -using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Razor.Parser; @@ -15,25 +14,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser { public class ParserVisitorExtensionsTest { - [Fact] - public void VisitThrowsOnNullVisitor() - { - ParserVisitor target = null; - var errorSink = new ErrorSink(); - var results = new ParserResults(new BlockBuilder() { Type = BlockType.Comment }.Build(), - Enumerable.Empty(), - errorSink); - - Assert.Throws("self", () => target.Visit(results)); - } - - [Fact] - public void VisitThrowsOnNullResults() - { - var target = new Mock().Object; - Assert.Throws("result", () => target.Visit(null)); - } - [Fact] public void VisitSendsDocumentToVisitor() { diff --git a/test/Microsoft.AspNet.Razor.Test/Parser/WhitespaceRewriterTest.cs b/test/Microsoft.AspNet.Razor.Test/Parser/WhitespaceRewriterTest.cs index 1520697852..d421328ddd 100644 --- a/test/Microsoft.AspNet.Razor.Test/Parser/WhitespaceRewriterTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Parser/WhitespaceRewriterTest.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Test.Framework; using Xunit; @@ -10,12 +9,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser { public class WhitespaceRewriterTest { - [Fact] - public void Constructor_Requires_NonNull_SymbolConverter() - { - Assert.Throws("markupSpanFactory", () => new WhiteSpaceRewriter(null)); - } - [Fact] public void Rewrite_Moves_Whitespace_Preceeding_ExpressionBlock_To_Parent_Block() { diff --git a/test/Microsoft.AspNet.Razor.Test/RazorEngineHostTest.cs b/test/Microsoft.AspNet.Razor.Test/RazorEngineHostTest.cs index bebfb82fe7..65c98b94e0 100644 --- a/test/Microsoft.AspNet.Razor.Test/RazorEngineHostTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/RazorEngineHostTest.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Parser; using Xunit; @@ -10,19 +9,6 @@ namespace Microsoft.AspNet.Razor.Test { public class RazorEngineHostTest { - [Fact] - public void ConstructorRequiresNonNullCodeLanguage() - { - Assert.Throws("codeLanguage", () => new RazorEngineHost(null)); - Assert.Throws("codeLanguage", () => new RazorEngineHost(null, () => new HtmlMarkupParser())); - } - - [Fact] - public void ConstructorRequiresNonNullMarkupParser() - { - Assert.Throws("markupParserFactory", () => new RazorEngineHost(new CSharpRazorCodeLanguage(), null)); - } - [Fact] public void ConstructorWithCodeLanguageSetsPropertiesAppropriately() { @@ -54,24 +40,6 @@ namespace Microsoft.AspNet.Razor.Test Assert.Same(expected, host.CreateMarkupParser()); } - [Fact] - public void DecorateCodeParserRequiresNonNullCodeParser() - { - Assert.Throws("incomingCodeParser", () => CreateHost().DecorateCodeParser(null)); - } - - [Fact] - public void DecorateMarkupParserRequiresNonNullMarkupParser() - { - Assert.Throws("incomingMarkupParser", () => CreateHost().DecorateMarkupParser(null)); - } - - [Fact] - public void DecorateCodeGeneratorRequiresNonNullCodeGenerator() - { - Assert.Throws("incomingCodeGenerator", () => CreateHost().DecorateCodeGenerator(null)); - } - [Fact] public void DecorateCodeParserDoesNotModifyIncomingParser() { diff --git a/test/Microsoft.AspNet.Razor.Test/RazorTemplateEngineTest.cs b/test/Microsoft.AspNet.Razor.Test/RazorTemplateEngineTest.cs index 01d67d05cb..8693d4323f 100644 --- a/test/Microsoft.AspNet.Razor.Test/RazorTemplateEngineTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/RazorTemplateEngineTest.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. #if !DNXCORE50 -using System; using System.Collections.Generic; using System.IO; using System.Text; @@ -19,12 +18,6 @@ namespace Microsoft.AspNet.Razor.Test { public class RazorTemplateEngineTest { - [Fact] - public void ConstructorRequiresNonNullHost() - { - Assert.Throws("host", () => new RazorTemplateEngine(null)); - } - [Fact] public void ConstructorInitializesHost() { diff --git a/test/Microsoft.AspNet.Razor.Test/Text/BufferingTextReaderTest.cs b/test/Microsoft.AspNet.Razor.Test/Text/BufferingTextReaderTest.cs index e3033bddcf..c310b93bba 100644 --- a/test/Microsoft.AspNet.Razor.Test/Text/BufferingTextReaderTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Text/BufferingTextReaderTest.cs @@ -28,12 +28,6 @@ namespace Microsoft.AspNet.Razor.Test.Text return new BufferingTextReader(new StringReader(testString)); } - [Fact] - public void ConstructorRequiresNonNullSourceReader() - { - Assert.Throws("source", () => new BufferingTextReader(null)); - } - [Fact] public void PeekReturnsCurrentCharacterWithoutAdvancingPosition() { diff --git a/test/Microsoft.AspNet.Razor.Test/Text/TextBufferReaderTest.cs b/test/Microsoft.AspNet.Razor.Test/Text/TextBufferReaderTest.cs index 94a5d090eb..93fcf70ff8 100644 --- a/test/Microsoft.AspNet.Razor.Test/Text/TextBufferReaderTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Text/TextBufferReaderTest.cs @@ -15,12 +15,6 @@ namespace Microsoft.AspNet.Razor.Test.Text return new TextBufferReader(new StringTextBuffer(testString)); } - [Fact] - public void ConstructorRequiresNonNullTextBuffer() - { - Assert.Throws("buffer", () => new TextBufferReader(null)); - } - [Fact] public void PeekReturnsCurrentCharacterWithoutAdvancingPosition() { diff --git a/test/Microsoft.AspNet.Razor.Test/Text/TextChangeTest.cs b/test/Microsoft.AspNet.Razor.Test/Text/TextChangeTest.cs index ce1d30dc9f..c7679f8861 100644 --- a/test/Microsoft.AspNet.Razor.Test/Text/TextChangeTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Text/TextChangeTest.cs @@ -46,18 +46,6 @@ namespace Microsoft.AspNet.Razor.Test.Text ExceptionHelpers.ValidateArgumentException(parameterName, "Value must be greater than or equal to 0.", exception); } - [Fact] - public void ConstructorRequiresNonNullOldBuffer() - { - Assert.Throws("oldBuffer", () => new TextChange(0, 0, null, 0, 0, new Mock().Object)); - } - - [Fact] - public void ConstructorRequiresNonNullNewBuffer() - { - Assert.Throws("newBuffer", () => new TextChange(0, 0, new Mock().Object, 0, 0, null)); - } - [Fact] public void ConstructorInitializesProperties() { diff --git a/test/Microsoft.AspNet.Razor.Test/Text/TextReaderExtensionsTest.cs b/test/Microsoft.AspNet.Razor.Test/Text/TextReaderExtensionsTest.cs index 5725443fc0..7d91423397 100644 --- a/test/Microsoft.AspNet.Razor.Test/Text/TextReaderExtensionsTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Text/TextReaderExtensionsTest.cs @@ -10,79 +10,6 @@ namespace Microsoft.AspNet.Razor.Test.Text { public class TextReaderExtensionsTest { - [Fact] - public void ReadUntilWithCharThrowsArgNullIfReaderNull() - { - Assert.Throws("reader", () => TextReaderExtensions.ReadUntil(null, '@')); - } - - [Fact] - public void ReadUntilInclusiveWithCharThrowsArgNullIfReaderNull() - { - Assert.Throws("reader", () => TextReaderExtensions.ReadUntil(null, '@', inclusive: true)); - } - - [Fact] - public void ReadUntilWithMultipleTerminatorsThrowsArgNullIfReaderNull() - { - Assert.Throws("reader", () => TextReaderExtensions.ReadUntil(null, '/', '>')); - } - - [Fact] - public void ReadUntilInclusiveWithMultipleTerminatorsThrowsArgNullIfReaderNull() - { - // NOTE: Using named parameters would be difficult here, hence the inline comment - Assert.Throws("reader", () => TextReaderExtensions.ReadUntil(null, /* inclusive */ true, '/', '>')); - } - - [Fact] - public void ReadUntilWithPredicateThrowsArgNullIfReaderNull() - { - Assert.Throws("reader", () => TextReaderExtensions.ReadUntil(null, c => true)); - } - - [Fact] - public void ReadUntilInclusiveWithPredicateThrowsArgNullIfReaderNull() - { - Assert.Throws("reader", () => TextReaderExtensions.ReadUntil(null, c => true, inclusive: true)); - } - - [Fact] - public void ReadUntilWithPredicateThrowsArgExceptionIfPredicateNull() - { - Assert.Throws("condition", () => TextReaderExtensions.ReadUntil(new StringReader("Foo"), (Predicate)null)); - } - - [Fact] - public void ReadUntilInclusiveWithPredicateThrowsArgExceptionIfPredicateNull() - { - Assert.Throws("condition", () => TextReaderExtensions.ReadUntil(new StringReader("Foo"), (Predicate)null, inclusive: true)); - } - - [Fact] - public void ReadWhileWithPredicateThrowsArgNullIfReaderNull() - { - Assert.Throws("reader", () => TextReaderExtensions.ReadWhile(null, c => true)); - } - - [Fact] - public void ReadWhileInclusiveWithPredicateThrowsArgNullIfReaderNull() - { - Assert.Throws("reader", () => TextReaderExtensions.ReadWhile(null, c => true, inclusive: true)); - } - - [Fact] - public void ReadWhileWithPredicateThrowsArgNullIfPredicateNull() - { - Assert.Throws("condition", () => TextReaderExtensions.ReadWhile(new StringReader("Foo"), (Predicate)null)); - } - - [Fact] - public void ReadWhileInclusiveWithPredicateThrowsArgNullIfPredicateNull() - { - Assert.Throws("condition", () => TextReaderExtensions.ReadWhile(new StringReader("Foo"), (Predicate)null, inclusive: true)); - } - [Fact] public void ReadUntilWithCharReadsAllTextUpToSpecifiedCharacterButNotPast() { diff --git a/test/Microsoft.AspNet.Razor.Test/Tokenizer/CSharpTokenizerTest.cs b/test/Microsoft.AspNet.Razor.Test/Tokenizer/CSharpTokenizerTest.cs index 05540ba7ab..182468fe87 100644 --- a/test/Microsoft.AspNet.Razor.Test/Tokenizer/CSharpTokenizerTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Tokenizer/CSharpTokenizerTest.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using Microsoft.AspNet.Razor.Tokenizer; using Microsoft.AspNet.Razor.Tokenizer.Symbols; using Xunit; @@ -10,12 +8,6 @@ namespace Microsoft.AspNet.Razor.Test.Tokenizer { public class CSharpTokenizerTest : CSharpTokenizerTestBase { - [Fact] - public void Constructor_Throws_ArgNull_If_Null_Source_Provided() - { - Assert.Throws("source", () => new CSharpTokenizer(null)); - } - [Fact] public void Next_Returns_Null_When_EOF_Reached() { diff --git a/test/Microsoft.AspNet.Razor.Test/Tokenizer/HtmlTokenizerTest.cs b/test/Microsoft.AspNet.Razor.Test/Tokenizer/HtmlTokenizerTest.cs index 9d37c81756..73890a0d0f 100644 --- a/test/Microsoft.AspNet.Razor.Test/Tokenizer/HtmlTokenizerTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Tokenizer/HtmlTokenizerTest.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using Microsoft.AspNet.Razor.Tokenizer; using Microsoft.AspNet.Razor.Tokenizer.Symbols; using Xunit; @@ -10,12 +8,6 @@ namespace Microsoft.AspNet.Razor.Test.Tokenizer { public class HtmlTokenizerTest : HtmlTokenizerTestBase { - [Fact] - public void Constructor_Throws_ArgNull_If_Null_Source_Provided() - { - Assert.Throws("source", () => new HtmlTokenizer(null)); - } - [Fact] public void Next_Returns_Null_When_EOF_Reached() { diff --git a/test/Microsoft.AspNet.Razor.Test/Tokenizer/TokenizerTestBase.cs b/test/Microsoft.AspNet.Razor.Test/Tokenizer/TokenizerTestBase.cs index 26c05ac42b..e9e7bb3ad9 100644 --- a/test/Microsoft.AspNet.Razor.Test/Tokenizer/TokenizerTestBase.cs +++ b/test/Microsoft.AspNet.Razor.Test/Tokenizer/TokenizerTestBase.cs @@ -13,6 +13,7 @@ using Xunit; namespace Microsoft.AspNet.Razor.Test.Tokenizer { public abstract class TokenizerTestBase + where TSymbolType : struct where TSymbol : SymbolBase { protected abstract TSymbol IgnoreRemaining { get; } diff --git a/test/Microsoft.AspNet.Razor.Test/Utils/DisposableActionTest.cs b/test/Microsoft.AspNet.Razor.Test/Utils/DisposableActionTest.cs index 3ebcf92937..9eea704f5a 100644 --- a/test/Microsoft.AspNet.Razor.Test/Utils/DisposableActionTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Utils/DisposableActionTest.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using Microsoft.AspNet.Razor.Utils; using Xunit; @@ -10,12 +9,6 @@ namespace Microsoft.AspNet.Razor.Test.Utils { public class DisposableActionTest { - [Fact] - public void ConstructorRequiresNonNullAction() - { - Assert.Throws("action", () => new DisposableAction(null)); - } - [Fact] public void ActionIsExecutedOnDispose() {