Skip to content

Commit df86a5f

Browse files
RazorCodeDocument: Convert GetFileKind to non-nullable property
This is a purely mechanical change that makes the RazorCodeDocument.GetFileKind() a readonly, computed property that delegates to ParserOptions.FileKind.
1 parent bea0695 commit df86a5f

File tree

15 files changed

+22
-23
lines changed

15 files changed

+22
-23
lines changed

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorProjectEngineIntegrationTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void Process_WithFileKind_SetsOnCodeDocument()
153153
var codeDocument = projectEngine.Process(RazorSourceDocument.ReadFrom(projectItem), "test", importSources: default, tagHelpers: null);
154154

155155
// Assert
156-
var actual = codeDocument.GetFileKind();
156+
var actual = codeDocument.FileKind;
157157
Assert.Equal("test", actual);
158158
}
159159

@@ -201,7 +201,7 @@ public void Process_SetsInferredFileKindOnCodeDocument_MvcFile()
201201
var codeDocument = projectEngine.Process(projectItem);
202202

203203
// Assert
204-
var actual = codeDocument.GetFileKind();
204+
var actual = codeDocument.FileKind;
205205
Assert.Same(FileKinds.Legacy, actual);
206206
}
207207

@@ -217,7 +217,7 @@ public void Process_SetsInferredFileKindOnCodeDocument_Component()
217217
var codeDocument = projectEngine.Process(projectItem);
218218

219219
// Assert
220-
var actual = codeDocument.GetFileKind();
220+
var actual = codeDocument.FileKind;
221221
Assert.Same(FileKinds.Component, actual);
222222
}
223223

@@ -288,7 +288,7 @@ public void ProcessDesignTime_SetsInferredFileKindOnCodeDocument_MvcFile()
288288
var codeDocument = projectEngine.ProcessDesignTime(projectItem);
289289

290290
// Assert
291-
var actual = codeDocument.GetFileKind();
291+
var actual = codeDocument.FileKind;
292292
Assert.Same(FileKinds.Legacy, actual);
293293
}
294294

@@ -304,7 +304,7 @@ public void ProcessDesignTime_SetsInferredFileKindOnCodeDocument_Component()
304304
var codeDocument = projectEngine.ProcessDesignTime(projectItem);
305305

306306
// Assert
307-
var actual = codeDocument.GetFileKind();
307+
var actual = codeDocument.FileKind;
308308
Assert.Same(FileKinds.Component, actual);
309309
}
310310

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentDocumentClassifierPass.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public ComponentDocumentClassifierPass(RazorLanguageVersion version)
4747

4848
protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
4949
{
50-
return FileKinds.IsComponent(codeDocument.GetFileKind());
50+
return FileKinds.IsComponent(codeDocument.FileKind);
5151
}
5252

5353
protected override CodeTarget CreateTarget(RazorCodeDocument codeDocument, RazorCodeGenerationOptions options)
@@ -95,7 +95,7 @@ protected override void OnDocumentStructureCreated(
9595
@class.Modifiers.Add("public");
9696
@class.Modifiers.Add("partial");
9797

98-
if (FileKinds.IsComponentImport(codeDocument.GetFileKind()))
98+
if (FileKinds.IsComponentImport(codeDocument.FileKind))
9999
{
100100
// We don't want component imports to be considered as real component.
101101
// But we still want to generate code for it so we can get diagnostics.

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentPageDirectivePass.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentInte
3838
for (var i = 0; i < directives.Count; i++)
3939
{
4040
var directive = directives[i];
41-
if (FileKinds.IsComponentImport(codeDocument.GetFileKind()) || directive.Node.IsImported())
41+
if (FileKinds.IsComponentImport(codeDocument.FileKind) || directive.Node.IsImported())
4242
{
4343
directive.Node.Diagnostics.Add(ComponentDiagnosticFactory.CreatePageDirective_CannotBeImported(directive.Node.Source.GetValueOrDefault()));
4444
}

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultDirectiveSyntaxTreePass.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal class DefaultDirectiveSyntaxTreePass : RazorEngineFeatureBase, IRazorSy
1414

1515
public RazorSyntaxTree Execute(RazorCodeDocument codeDocument, RazorSyntaxTree syntaxTree)
1616
{
17-
if (FileKinds.IsComponent(codeDocument.GetFileKind()))
17+
if (FileKinds.IsComponent(codeDocument.FileKind))
1818
{
1919
// Nothing to do here.
2020
return syntaxTree;

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultRazorIntermediateNodeLoweringPhase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, Cancellation
4343
// We need to decide up front if this document is a "component" file. This will affect how
4444
// lowering behaves.
4545
LoweringVisitor visitor;
46-
if (FileKinds.IsComponentImport(codeDocument.GetFileKind()) &&
46+
if (FileKinds.IsComponentImport(codeDocument.FileKind) &&
4747
syntaxTree.Options.AllowComponentFileKind)
4848
{
4949
visitor = new ComponentImportFileKindVisitor(documentNode, builder, syntaxTree.Options)
@@ -53,7 +53,7 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, Cancellation
5353

5454
visitor.Visit(syntaxTree.Root);
5555
}
56-
else if (FileKinds.IsComponent(codeDocument.GetFileKind()) &&
56+
else if (FileKinds.IsComponent(codeDocument.FileKind) &&
5757
syntaxTree.Options.AllowComponentFileKind)
5858
{
5959
visitor = new ComponentFileKindVisitor(documentNode, builder, syntaxTree.Options)

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultRazorTagHelperContextDiscoveryPhase_Pooling.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ internal static PooledDirectiveVisitor GetPooledVisitor(
5252
out DirectiveVisitor visitor)
5353
{
5454
var useComponentDirectiveVisitor = codeDocument.ParserOptions.AllowComponentFileKind &&
55-
FileKinds.IsComponent(codeDocument.GetFileKind());
55+
FileKinds.IsComponent(codeDocument.FileKind);
5656

5757
if (useComponentDirectiveVisitor)
5858
{

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Extensions/FunctionsDirectivePass.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentInte
2323
var directiveNodes = new List<IntermediateNodeReference>();
2424
directiveNodes.AddRange(documentNode.FindDirectiveReferences(FunctionsDirective.Directive));
2525

26-
if (FileKinds.IsComponent(codeDocument.GetFileKind()))
26+
if (FileKinds.IsComponent(codeDocument.FileKind))
2727
{
2828
directiveNodes.AddRange(documentNode.FindDirectiveReferences(ComponentCodeDirective.Directive));
2929
}

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorCodeDocument.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public sealed class RazorCodeDocument
1515
public RazorParserOptions ParserOptions { get; }
1616
public RazorCodeGenerationOptions CodeGenerationOptions { get; }
1717

18+
public string FileKind => ParserOptions.FileKind;
19+
1820
private RazorCodeDocument(
1921
RazorSourceDocument source,
2022
ImmutableArray<RazorSourceDocument> imports,
@@ -50,7 +52,4 @@ public static RazorCodeDocument Create(
5052

5153
return new RazorCodeDocument(source, imports, parserOptions, codeGenerationOptions);
5254
}
53-
54-
public string? GetFileKind()
55-
=> ParserOptions.FileKind;
5655
}

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorCodeDocumentExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ bool TryComputeNamespaceCore(RazorCodeDocument codeDocument, bool fallbackToRoot
340340
appendSuffix = true;
341341

342342
// Empty RootNamespace is allowed only in components.
343-
if (!FileKinds.IsComponent(codeDocument.GetFileKind()) && string.IsNullOrEmpty(baseNamespace))
343+
if (!FileKinds.IsComponent(codeDocument.FileKind) && string.IsNullOrEmpty(baseNamespace))
344344
{
345345
@namespace = null;
346346
return false;

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LinkedEditingRange/LinkedEditingRangeEndpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(LinkedEditingRangeParams
4545
var codeDocument = await documentContext.GetCodeDocumentAsync(cancellationToken).ConfigureAwait(false);
4646
if (codeDocument.IsUnsupported())
4747
{
48-
_logger.LogWarning($"FileKind {codeDocument.GetFileKind()} is unsupported");
48+
_logger.LogWarning($"FileKind {codeDocument.FileKind} is unsupported");
4949
return null;
5050
}
5151

0 commit comments

Comments
 (0)