-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
SyntaxToken.SyntaxTokenWithTrivia.cs
105 lines (92 loc) · 3.82 KB
/
SyntaxToken.SyntaxTokenWithTrivia.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax
{
internal partial class SyntaxToken
{
internal class SyntaxTokenWithTrivia : SyntaxToken
{
static SyntaxTokenWithTrivia()
{
ObjectBinder.RegisterTypeReader(typeof(SyntaxTokenWithTrivia), r => new SyntaxTokenWithTrivia(r));
}
protected readonly GreenNode LeadingField;
protected readonly GreenNode TrailingField;
internal SyntaxTokenWithTrivia(SyntaxKind kind, GreenNode leading, GreenNode trailing)
: base(kind)
{
if (leading != null)
{
this.AdjustFlagsAndWidth(leading);
this.LeadingField = leading;
}
if (trailing != null)
{
this.AdjustFlagsAndWidth(trailing);
this.TrailingField = trailing;
}
}
internal SyntaxTokenWithTrivia(SyntaxKind kind, GreenNode leading, GreenNode trailing, DiagnosticInfo[] diagnostics, SyntaxAnnotation[] annotations)
: base(kind, diagnostics, annotations)
{
if (leading != null)
{
this.AdjustFlagsAndWidth(leading);
this.LeadingField = leading;
}
if (trailing != null)
{
this.AdjustFlagsAndWidth(trailing);
this.TrailingField = trailing;
}
}
internal SyntaxTokenWithTrivia(ObjectReader reader)
: base(reader)
{
var leading = (GreenNode)reader.ReadValue();
if (leading != null)
{
this.AdjustFlagsAndWidth(leading);
this.LeadingField = leading;
}
var trailing = (GreenNode)reader.ReadValue();
if (trailing != null)
{
this.AdjustFlagsAndWidth(trailing);
this.TrailingField = trailing;
}
}
internal override void WriteTo(ObjectWriter writer)
{
base.WriteTo(writer);
writer.WriteValue(this.LeadingField);
writer.WriteValue(this.TrailingField);
}
public override GreenNode GetLeadingTrivia()
{
return this.LeadingField;
}
public override GreenNode GetTrailingTrivia()
{
return this.TrailingField;
}
public override SyntaxToken TokenWithLeadingTrivia(GreenNode trivia)
{
return new SyntaxTokenWithTrivia(this.Kind, trivia, this.TrailingField, this.GetDiagnostics(), this.GetAnnotations());
}
public override SyntaxToken TokenWithTrailingTrivia(GreenNode trivia)
{
return new SyntaxTokenWithTrivia(this.Kind, this.LeadingField, trivia, this.GetDiagnostics(), this.GetAnnotations());
}
internal override GreenNode SetDiagnostics(DiagnosticInfo[] diagnostics)
{
return new SyntaxTokenWithTrivia(this.Kind, this.LeadingField, this.TrailingField, diagnostics, this.GetAnnotations());
}
internal override GreenNode SetAnnotations(SyntaxAnnotation[] annotations)
{
return new SyntaxTokenWithTrivia(this.Kind, this.LeadingField, this.TrailingField, this.GetDiagnostics(), annotations);
}
}
}
}