Skip to content

Commit 6593264

Browse files
Clean up and enable nullability for CodeRenderingContext and DefaultDocumentWriter
1 parent 7a9f32e commit 6593264

File tree

4 files changed

+94
-112
lines changed

4 files changed

+94
-112
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Immutable;
66
using System.Globalization;
7-
using System.Text;
87
using Microsoft.AspNetCore.Razor.PooledObjects;
98

109
namespace Microsoft.AspNetCore.Razor.Language;

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/CodeGeneration/CodeRenderingContext.cs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
#nullable disable
5-
64
using System;
75
using System.Collections.Generic;
86
using System.Collections.Immutable;
@@ -28,6 +26,9 @@ public sealed class CodeRenderingContext : IDisposable
2826
private readonly ImmutableArray<SourceMapping>.Builder _sourceMappings;
2927
private readonly ImmutableArray<LinePragma>.Builder _linePragmas;
3028

29+
private IntermediateNodeVisitor? _visitor;
30+
public IntermediateNodeVisitor Visitor => _visitor.AssumeNotNull();
31+
3132
public string DocumentKind => _documentNode.DocumentKind;
3233

3334
public CodeRenderingContext(
@@ -74,12 +75,16 @@ public void Dispose()
7475
CodeWriter.Dispose();
7576
}
7677

77-
// This will be initialized by the document writer when the context is 'live'.
78-
public IntermediateNodeVisitor Visitor { get; set; }
78+
// This will be called by the document writer when the context is 'live'.
79+
public void SetVisitor(IntermediateNodeVisitor visitor)
80+
{
81+
_visitor = visitor;
82+
}
7983

8084
public IntermediateNodeWriter NodeWriter => _scopeStack.Peek().Writer;
8185

82-
public IntermediateNode Parent => _ancestorStack.Count == 0 ? null : _ancestorStack.Peek();
86+
public IntermediateNode? Parent
87+
=> _ancestorStack.Count == 0 ? null : _ancestorStack.Peek();
8388

8489
public void AddDiagnostic(RazorDiagnostic diagnostic)
8590
{

0 commit comments

Comments
 (0)