|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable disable
namespace Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax
{
internal partial class SyntaxToken
{
internal class SyntaxTokenWithTrivia : SyntaxToken
{
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;
}
}
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);
}
}
}
}
|