From 9ff785742a60980ab642adeadb7bfe2f81f791d7 Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Tue, 16 Mar 2021 10:29:31 -0700 Subject: [PATCH 1/3] Add Consolidated view classifier to make view types internal --- ...nsolidatedMvcViewDocumentClassifierPass.cs | 92 +++++++++ .../src/PublicAPI.Unshipped.txt | 6 + .../src/RazorExtensions.cs | 10 +- ...idatedMvcViewDocumentClassifierPassTest.cs | 178 ++++++++++++++++++ .../src/PublicAPI.Unshipped.txt | 3 + .../src/RazorConfiguration.cs | 21 ++- 6 files changed, 305 insertions(+), 5 deletions(-) create mode 100644 src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/ConsolidatedMvcViewDocumentClassifierPass.cs create mode 100644 src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/ConsolidatedMvcViewDocumentClassifierPass.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/ConsolidatedMvcViewDocumentClassifierPass.cs new file mode 100644 index 000000000000..345670d35fd3 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/ConsolidatedMvcViewDocumentClassifierPass.cs @@ -0,0 +1,92 @@ +// 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.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Intermediate; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions +{ + public class ConsolidatedMvcViewDocumentClassifierPass : DocumentClassifierPassBase + { + public static readonly string MvcViewDocumentKind = "mvc.1.0.view"; + + protected override string DocumentKind => MvcViewDocumentKind; + + protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) => true; + + + protected override void OnDocumentStructureCreated( + RazorCodeDocument codeDocument, + NamespaceDeclarationIntermediateNode @namespace, + ClassDeclarationIntermediateNode @class, + MethodDeclarationIntermediateNode method) + { + base.OnDocumentStructureCreated(codeDocument, @namespace, @class, method); + + if (!codeDocument.TryComputeNamespace(fallbackToRootNamespace: false, out var namespaceName)) + { + @namespace.Content = "AspNetCoreGeneratedDocument"; + } + else + { + @namespace.Content = namespaceName; + } + + if (!TryComputeClassName(codeDocument, out var className)) + { + // It's possible for a Razor document to not have a file path. + // Eg. When we try to generate code for an in memory document like default imports. + var checksum = Checksum.BytesToString(codeDocument.Source.GetChecksum()); + @class.ClassName = $"AspNetCore_{checksum}"; + } + else + { + @class.ClassName = className; + } + + + @class.BaseType = "global::Microsoft.AspNetCore.Mvc.Razor.RazorPage"; + @class.Modifiers.Clear(); + @class.Modifiers.Add("internal"); + @class.Modifiers.Add("sealed"); + + method.MethodName = "ExecuteAsync"; + method.Modifiers.Clear(); + method.Modifiers.Add("public"); + method.Modifiers.Add("async"); + method.Modifiers.Add("override"); + method.ReturnType = $"global::{typeof(System.Threading.Tasks.Task).FullName}"; + } + + private bool TryComputeClassName(RazorCodeDocument codeDocument, out string className) + { + var filePath = codeDocument.Source.RelativePath ?? codeDocument.Source.FilePath; + if (string.IsNullOrEmpty(filePath)) + { + className = null; + return false; + } + + className = GetClassNameFromPath(filePath); + return true; + } + + private static string GetClassNameFromPath(string path) + { + const string cshtmlExtension = ".cshtml"; + + if (string.IsNullOrEmpty(path)) + { + return path; + } + + if (path.EndsWith(cshtmlExtension, StringComparison.OrdinalIgnoreCase)) + { + path = path.Substring(0, path.Length - cshtmlExtension.Length); + } + + return CSharpIdentifier.SanitizeIdentifier(path); + } + } +} \ No newline at end of file diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/PublicAPI.Unshipped.txt b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/PublicAPI.Unshipped.txt index 7dc5c58110bf..9c3b5a493fbb 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/PublicAPI.Unshipped.txt +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/PublicAPI.Unshipped.txt @@ -1 +1,7 @@ #nullable enable +Microsoft.AspNetCore.Mvc.Razor.Extensions.ConsolidatedMvcViewDocumentClassifierPass +Microsoft.AspNetCore.Mvc.Razor.Extensions.ConsolidatedMvcViewDocumentClassifierPass.ConsolidatedMvcViewDocumentClassifierPass() -> void +~override Microsoft.AspNetCore.Mvc.Razor.Extensions.ConsolidatedMvcViewDocumentClassifierPass.DocumentKind.get -> string +~override Microsoft.AspNetCore.Mvc.Razor.Extensions.ConsolidatedMvcViewDocumentClassifierPass.IsMatch(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument codeDocument, Microsoft.AspNetCore.Razor.Language.Intermediate.DocumentIntermediateNode documentNode) -> bool +~override Microsoft.AspNetCore.Mvc.Razor.Extensions.ConsolidatedMvcViewDocumentClassifierPass.OnDocumentStructureCreated(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument codeDocument, Microsoft.AspNetCore.Razor.Language.Intermediate.NamespaceDeclarationIntermediateNode namespace, Microsoft.AspNetCore.Razor.Language.Intermediate.ClassDeclarationIntermediateNode class, Microsoft.AspNetCore.Razor.Language.Intermediate.MethodDeclarationIntermediateNode method) -> void +~static readonly Microsoft.AspNetCore.Mvc.Razor.Extensions.ConsolidatedMvcViewDocumentClassifierPass.MvcViewDocumentKind -> string \ No newline at end of file diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorExtensions.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorExtensions.cs index dfaebba00740..13757a407dea 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorExtensions.cs +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorExtensions.cs @@ -37,7 +37,15 @@ public static void Register(RazorProjectEngineBuilder builder) builder.Features.Add(new PagesPropertyInjectionPass()); builder.Features.Add(new ViewComponentTagHelperPass()); builder.Features.Add(new RazorPageDocumentClassifierPass()); - builder.Features.Add(new MvcViewDocumentClassifierPass()); + + if (builder.Configuration.IsConsolidatedMvcViews) + { + builder.Features.Add(new ConsolidatedMvcViewDocumentClassifierPass()); + } + else + { + builder.Features.Add(new MvcViewDocumentClassifierPass()); + } builder.Features.Add(new MvcImportProjectFeature()); diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs new file mode 100644 index 000000000000..0aea34c3100f --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs @@ -0,0 +1,178 @@ +// 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.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Intermediate; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions +{ + public class ConsolidatedMvcViewDocumentClassifierPassTest : RazorProjectEngineTestBase + { + protected override RazorLanguageVersion Version => RazorLanguageVersion.Latest; + + [Fact] + public void ConsolidatedMvcViewDocumentClassifierPass_SetsDifferentNamespace() + { + // Arrange + var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("some-content", "Test.cshtml")); + + var projectEngine = CreateProjectEngine(); + var irDocument = CreateIRDocument(projectEngine, codeDocument); + var pass = new ConsolidatedMvcViewDocumentClassifierPass + { + Engine = projectEngine.Engine + }; + + // Act + pass.Execute(codeDocument, irDocument); + var visitor = new Visitor(); + visitor.Visit(irDocument); + + // Assert + Assert.Equal("AspNetCoreGeneratedDocument", visitor.Namespace.Content); + } + + [Fact] + public void ConsolidatedMvcViewDocumentClassifierPass_SetsClass() + { + // Arrange + var properties = new RazorSourceDocumentProperties(filePath: "ignored", relativePath: "Test.cshtml"); + var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("some-content", properties)); + + var projectEngine = CreateProjectEngine(); + var irDocument = CreateIRDocument(projectEngine, codeDocument); + var pass = new ConsolidatedMvcViewDocumentClassifierPass + { + Engine = projectEngine.Engine + }; + + // Act + pass.Execute(codeDocument, irDocument); + var visitor = new Visitor(); + visitor.Visit(irDocument); + + // Assert + Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType); + Assert.Equal(new[] { "internal" }, visitor.Class.Modifiers); + Assert.Equal("Test", visitor.Class.ClassName); + } + + [Fact] + public void MvcViewDocumentClassifierPass_NullFilePath_SetsClass() + { + // Arrange + var properties = new RazorSourceDocumentProperties(filePath: null, relativePath: null); + var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("some-content", properties)); + + var projectEngine = CreateProjectEngine(); + var irDocument = CreateIRDocument(projectEngine, codeDocument); + var pass = new ConsolidatedMvcViewDocumentClassifierPass + { + Engine = projectEngine.Engine + }; + + // Act + pass.Execute(codeDocument, irDocument); + var visitor = new Visitor(); + visitor.Visit(irDocument); + + // Assert + Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType); + Assert.Equal(new[] { "internal" }, visitor.Class.Modifiers); + Assert.Equal("AspNetCore_d9f877a857a7e9928eac04d09a59f25967624155", visitor.Class.ClassName); + } + + [Theory] + [InlineData("/Views/Home/Index.cshtml", "_Views_Home_Index")] + [InlineData("/Areas/MyArea/Views/Home/About.cshtml", "_Areas_MyArea_Views_Home_About")] + public void MvcViewDocumentClassifierPass_UsesRelativePathToGenerateTypeName(string relativePath, string expected) + { + // Arrange + var properties = new RazorSourceDocumentProperties(filePath: "ignored", relativePath: relativePath); + var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("some-content", properties)); + + var projectEngine = CreateProjectEngine(); + var irDocument = CreateIRDocument(projectEngine, codeDocument); + var pass = new ConsolidatedMvcViewDocumentClassifierPass + { + Engine = projectEngine.Engine + }; + + // Act + pass.Execute(codeDocument, irDocument); + var visitor = new Visitor(); + visitor.Visit(irDocument); + + // Assert + Assert.Equal(expected, visitor.Class.ClassName); + Assert.Equal(new[] { "internal" }, visitor.Class.Modifiers); + } + + [Fact] + public void ConsolidatedMvcViewDocumentClassifierPass_SetsUpExecuteAsyncMethod() + { + // Arrange + var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("some-content", "Test.cshtml")); + + var projectEngine = CreateProjectEngine(); + var irDocument = CreateIRDocument(projectEngine, codeDocument); + var pass = new ConsolidatedMvcViewDocumentClassifierPass + { + Engine = projectEngine.Engine + }; + + // Act + pass.Execute(codeDocument, irDocument); + var visitor = new Visitor(); + visitor.Visit(irDocument); + + // Assert + Assert.Equal("ExecuteAsync", visitor.Method.MethodName); + Assert.Equal("global::System.Threading.Tasks.Task", visitor.Method.ReturnType); + Assert.Equal(new[] { "public", "async", "override" }, visitor.Method.Modifiers); + } + + private static DocumentIntermediateNode CreateIRDocument(RazorProjectEngine projectEngine, RazorCodeDocument codeDocument) + { + for (var i = 0; i < projectEngine.Phases.Count; i++) + { + var phase = projectEngine.Phases[i]; + phase.Execute(codeDocument); + + if (phase is IRazorIntermediateNodeLoweringPhase) + { + break; + } + } + + return codeDocument.GetDocumentIntermediateNode(); + } + + private class Visitor : IntermediateNodeWalker + { + public NamespaceDeclarationIntermediateNode Namespace { get; private set; } + + public ClassDeclarationIntermediateNode Class { get; private set; } + + public MethodDeclarationIntermediateNode Method { get; private set; } + + public override void VisitMethodDeclaration(MethodDeclarationIntermediateNode node) + { + Method = node; + } + + public override void VisitNamespaceDeclaration(NamespaceDeclarationIntermediateNode node) + { + Namespace = node; + base.VisitNamespaceDeclaration(node); + } + + public override void VisitClassDeclaration(ClassDeclarationIntermediateNode node) + { + Class = node; + base.VisitClassDeclaration(node); + } + } + } +} \ No newline at end of file diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/PublicAPI.Unshipped.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/PublicAPI.Unshipped.txt index 15ad64837f8a..521e01354ff2 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/PublicAPI.Unshipped.txt +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/PublicAPI.Unshipped.txt @@ -7,3 +7,6 @@ Microsoft.AspNetCore.Razor.Language.Intermediate.CascadingGenericTypeParameter.C ~Microsoft.AspNetCore.Razor.Language.Intermediate.ComponentIntermediateNode.ProvidesCascadingGenericTypes.set -> void ~Microsoft.AspNetCore.Razor.Language.Intermediate.ComponentTypeInferenceMethodIntermediateNode.ReceivesCascadingGenericTypes.get -> System.Collections.Generic.List ~Microsoft.AspNetCore.Razor.Language.Intermediate.ComponentTypeInferenceMethodIntermediateNode.ReceivesCascadingGenericTypes.set -> void +abstract Microsoft.AspNetCore.Razor.Language.RazorConfiguration.IsConsolidatedMvcViews.get -> bool +*REMOVED*~static Microsoft.AspNetCore.Razor.Language.RazorConfiguration.Create(Microsoft.AspNetCore.Razor.Language.RazorLanguageVersion languageVersion, string configurationName, System.Collections.Generic.IEnumerable extensions) -> Microsoft.AspNetCore.Razor.Language.RazorConfiguration +~static Microsoft.AspNetCore.Razor.Language.RazorConfiguration.Create(Microsoft.AspNetCore.Razor.Language.RazorLanguageVersion languageVersion, string configurationName, System.Collections.Generic.IEnumerable extensions, bool isConsolidatedMvcViews = false) -> Microsoft.AspNetCore.Razor.Language.RazorConfiguration diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorConfiguration.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorConfiguration.cs index 1094b0a43238..dc9eddfc7fa8 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorConfiguration.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorConfiguration.cs @@ -13,12 +13,14 @@ public abstract class RazorConfiguration : IEquatable public static readonly RazorConfiguration Default = new DefaultRazorConfiguration( RazorLanguageVersion.Latest, "unnamed", - Array.Empty()); + Array.Empty(), + false); public static RazorConfiguration Create( RazorLanguageVersion languageVersion, string configurationName, - IEnumerable extensions) + IEnumerable extensions, + bool isConsolidatedMvcViews = false) { if (languageVersion == null) { @@ -35,7 +37,7 @@ public static RazorConfiguration Create( throw new ArgumentNullException(nameof(extensions)); } - return new DefaultRazorConfiguration(languageVersion, configurationName, extensions.ToArray()); + return new DefaultRazorConfiguration(languageVersion, configurationName, extensions.ToArray(), isConsolidatedMvcViews); } public abstract string ConfigurationName { get; } @@ -44,6 +46,8 @@ public static RazorConfiguration Create( public abstract RazorLanguageVersion LanguageVersion { get; } + public abstract bool IsConsolidatedMvcViews { get; } + public override bool Equals(object obj) { return base.Equals(obj as RazorConfiguration); @@ -71,6 +75,11 @@ public virtual bool Equals(RazorConfiguration other) return false; } + if (IsConsolidatedMvcViews != other.IsConsolidatedMvcViews) + { + return false; + } + for (var i = 0; i < Extensions.Count; i++) { if (Extensions[i].ExtensionName != other.Extensions[i].ExtensionName) @@ -101,11 +110,13 @@ private class DefaultRazorConfiguration : RazorConfiguration public DefaultRazorConfiguration( RazorLanguageVersion languageVersion, string configurationName, - RazorExtension[] extensions) + RazorExtension[] extensions, + bool isConsolidatedMvcViews = false) { LanguageVersion = languageVersion; ConfigurationName = configurationName; Extensions = extensions; + IsConsolidatedMvcViews = isConsolidatedMvcViews; } public override string ConfigurationName { get; } @@ -113,6 +124,8 @@ public DefaultRazorConfiguration( public override IReadOnlyList Extensions { get; } public override RazorLanguageVersion LanguageVersion { get; } + + public override bool IsConsolidatedMvcViews { get; } } } } From 2c39db450e0cf05cc755fc03746d4369a0df257e Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Tue, 16 Mar 2021 11:50:57 -0700 Subject: [PATCH 2/3] Address feedback from peer review --- .../ConsolidatedMvcViewDocumentClassifierPass.cs | 2 -- .../src/RazorExtensions.cs | 2 +- .../src/PublicAPI.Unshipped.txt | 4 ++-- .../src/RazorConfiguration.cs | 14 +++++++------- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/ConsolidatedMvcViewDocumentClassifierPass.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/ConsolidatedMvcViewDocumentClassifierPass.cs index 345670d35fd3..76077b27574e 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/ConsolidatedMvcViewDocumentClassifierPass.cs +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/ConsolidatedMvcViewDocumentClassifierPass.cs @@ -14,7 +14,6 @@ public class ConsolidatedMvcViewDocumentClassifierPass : DocumentClassifierPassB protected override string DocumentKind => MvcViewDocumentKind; protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) => true; - protected override void OnDocumentStructureCreated( RazorCodeDocument codeDocument, @@ -45,7 +44,6 @@ protected override void OnDocumentStructureCreated( @class.ClassName = className; } - @class.BaseType = "global::Microsoft.AspNetCore.Mvc.Razor.RazorPage"; @class.Modifiers.Clear(); @class.Modifiers.Add("internal"); diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorExtensions.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorExtensions.cs index 13757a407dea..0c7b298aa738 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorExtensions.cs +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorExtensions.cs @@ -38,7 +38,7 @@ public static void Register(RazorProjectEngineBuilder builder) builder.Features.Add(new ViewComponentTagHelperPass()); builder.Features.Add(new RazorPageDocumentClassifierPass()); - if (builder.Configuration.IsConsolidatedMvcViews) + if (builder.Configuration.UseConsolidatedMvcViews) { builder.Features.Add(new ConsolidatedMvcViewDocumentClassifierPass()); } diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/PublicAPI.Unshipped.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/PublicAPI.Unshipped.txt index 521e01354ff2..8a9e35f076b7 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/PublicAPI.Unshipped.txt +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/PublicAPI.Unshipped.txt @@ -7,6 +7,6 @@ Microsoft.AspNetCore.Razor.Language.Intermediate.CascadingGenericTypeParameter.C ~Microsoft.AspNetCore.Razor.Language.Intermediate.ComponentIntermediateNode.ProvidesCascadingGenericTypes.set -> void ~Microsoft.AspNetCore.Razor.Language.Intermediate.ComponentTypeInferenceMethodIntermediateNode.ReceivesCascadingGenericTypes.get -> System.Collections.Generic.List ~Microsoft.AspNetCore.Razor.Language.Intermediate.ComponentTypeInferenceMethodIntermediateNode.ReceivesCascadingGenericTypes.set -> void -abstract Microsoft.AspNetCore.Razor.Language.RazorConfiguration.IsConsolidatedMvcViews.get -> bool +abstract Microsoft.AspNetCore.Razor.Language.RazorConfiguration.UseConsolidatedMvcViews.get -> bool *REMOVED*~static Microsoft.AspNetCore.Razor.Language.RazorConfiguration.Create(Microsoft.AspNetCore.Razor.Language.RazorLanguageVersion languageVersion, string configurationName, System.Collections.Generic.IEnumerable extensions) -> Microsoft.AspNetCore.Razor.Language.RazorConfiguration -~static Microsoft.AspNetCore.Razor.Language.RazorConfiguration.Create(Microsoft.AspNetCore.Razor.Language.RazorLanguageVersion languageVersion, string configurationName, System.Collections.Generic.IEnumerable extensions, bool isConsolidatedMvcViews = false) -> Microsoft.AspNetCore.Razor.Language.RazorConfiguration +~static Microsoft.AspNetCore.Razor.Language.RazorConfiguration.Create(Microsoft.AspNetCore.Razor.Language.RazorLanguageVersion languageVersion, string configurationName, System.Collections.Generic.IEnumerable extensions, bool useConsolidatedMvcViews = false) -> Microsoft.AspNetCore.Razor.Language.RazorConfiguration diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorConfiguration.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorConfiguration.cs index dc9eddfc7fa8..e70676b2963d 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorConfiguration.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorConfiguration.cs @@ -20,7 +20,7 @@ public static RazorConfiguration Create( RazorLanguageVersion languageVersion, string configurationName, IEnumerable extensions, - bool isConsolidatedMvcViews = false) + bool useConsolidatedMvcViews = false) { if (languageVersion == null) { @@ -37,7 +37,7 @@ public static RazorConfiguration Create( throw new ArgumentNullException(nameof(extensions)); } - return new DefaultRazorConfiguration(languageVersion, configurationName, extensions.ToArray(), isConsolidatedMvcViews); + return new DefaultRazorConfiguration(languageVersion, configurationName, extensions.ToArray(), useConsolidatedMvcViews); } public abstract string ConfigurationName { get; } @@ -46,7 +46,7 @@ public static RazorConfiguration Create( public abstract RazorLanguageVersion LanguageVersion { get; } - public abstract bool IsConsolidatedMvcViews { get; } + public abstract bool UseConsolidatedMvcViews { get; } public override bool Equals(object obj) { @@ -75,7 +75,7 @@ public virtual bool Equals(RazorConfiguration other) return false; } - if (IsConsolidatedMvcViews != other.IsConsolidatedMvcViews) + if (UseConsolidatedMvcViews != other.UseConsolidatedMvcViews) { return false; } @@ -111,12 +111,12 @@ public DefaultRazorConfiguration( RazorLanguageVersion languageVersion, string configurationName, RazorExtension[] extensions, - bool isConsolidatedMvcViews = false) + bool useConsolidatedMvcViews = false) { LanguageVersion = languageVersion; ConfigurationName = configurationName; Extensions = extensions; - IsConsolidatedMvcViews = isConsolidatedMvcViews; + UseConsolidatedMvcViews = useConsolidatedMvcViews; } public override string ConfigurationName { get; } @@ -125,7 +125,7 @@ public DefaultRazorConfiguration( public override RazorLanguageVersion LanguageVersion { get; } - public override bool IsConsolidatedMvcViews { get; } + public override bool UseConsolidatedMvcViews { get; } } } } From 761a9e0e224f970240bbc0fc6d81e95154b34997 Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Tue, 16 Mar 2021 13:40:34 -0700 Subject: [PATCH 3/3] Address feedback and fix tests --- .../src/ConsolidatedMvcViewDocumentClassifierPass.cs | 2 +- .../src/PublicAPI.Unshipped.txt | 3 --- .../test/ConsolidatedMvcViewDocumentClassifierPassTest.cs | 6 +++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/ConsolidatedMvcViewDocumentClassifierPass.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/ConsolidatedMvcViewDocumentClassifierPass.cs index 76077b27574e..715ae3496e89 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/ConsolidatedMvcViewDocumentClassifierPass.cs +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/ConsolidatedMvcViewDocumentClassifierPass.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions { - public class ConsolidatedMvcViewDocumentClassifierPass : DocumentClassifierPassBase + public sealed class ConsolidatedMvcViewDocumentClassifierPass : DocumentClassifierPassBase { public static readonly string MvcViewDocumentKind = "mvc.1.0.view"; diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/PublicAPI.Unshipped.txt b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/PublicAPI.Unshipped.txt index 9c3b5a493fbb..e4a5fa72ae36 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/PublicAPI.Unshipped.txt +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/PublicAPI.Unshipped.txt @@ -1,7 +1,4 @@ #nullable enable Microsoft.AspNetCore.Mvc.Razor.Extensions.ConsolidatedMvcViewDocumentClassifierPass Microsoft.AspNetCore.Mvc.Razor.Extensions.ConsolidatedMvcViewDocumentClassifierPass.ConsolidatedMvcViewDocumentClassifierPass() -> void -~override Microsoft.AspNetCore.Mvc.Razor.Extensions.ConsolidatedMvcViewDocumentClassifierPass.DocumentKind.get -> string -~override Microsoft.AspNetCore.Mvc.Razor.Extensions.ConsolidatedMvcViewDocumentClassifierPass.IsMatch(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument codeDocument, Microsoft.AspNetCore.Razor.Language.Intermediate.DocumentIntermediateNode documentNode) -> bool -~override Microsoft.AspNetCore.Mvc.Razor.Extensions.ConsolidatedMvcViewDocumentClassifierPass.OnDocumentStructureCreated(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument codeDocument, Microsoft.AspNetCore.Razor.Language.Intermediate.NamespaceDeclarationIntermediateNode namespace, Microsoft.AspNetCore.Razor.Language.Intermediate.ClassDeclarationIntermediateNode class, Microsoft.AspNetCore.Razor.Language.Intermediate.MethodDeclarationIntermediateNode method) -> void ~static readonly Microsoft.AspNetCore.Mvc.Razor.Extensions.ConsolidatedMvcViewDocumentClassifierPass.MvcViewDocumentKind -> string \ No newline at end of file diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs index 0aea34c3100f..b4c6ed145ed7 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs @@ -54,7 +54,7 @@ public void ConsolidatedMvcViewDocumentClassifierPass_SetsClass() // Assert Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType); - Assert.Equal(new[] { "internal" }, visitor.Class.Modifiers); + Assert.Equal(new[] { "internal", "sealed" }, visitor.Class.Modifiers); Assert.Equal("Test", visitor.Class.ClassName); } @@ -79,7 +79,7 @@ public void MvcViewDocumentClassifierPass_NullFilePath_SetsClass() // Assert Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType); - Assert.Equal(new[] { "internal" }, visitor.Class.Modifiers); + Assert.Equal(new[] { "internal", "sealed" }, visitor.Class.Modifiers); Assert.Equal("AspNetCore_d9f877a857a7e9928eac04d09a59f25967624155", visitor.Class.ClassName); } @@ -106,7 +106,7 @@ public void MvcViewDocumentClassifierPass_UsesRelativePathToGenerateTypeName(str // Assert Assert.Equal(expected, visitor.Class.ClassName); - Assert.Equal(new[] { "internal" }, visitor.Class.Modifiers); + Assert.Equal(new[] { "internal", "sealed" }, visitor.Class.Modifiers); } [Fact]