117 lines
3.6 KiB
C#
117 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Roslyn.Utilities;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax;
|
|
|
|
internal sealed class IdentifierNameSyntax : SimpleNameSyntax
|
|
{
|
|
internal readonly SyntaxToken identifier;
|
|
|
|
public override SyntaxToken Identifier => identifier;
|
|
|
|
public override string ToString()
|
|
{
|
|
return Identifier.Text;
|
|
}
|
|
|
|
internal IdentifierNameSyntax(SyntaxKind kind, SyntaxToken identifier, DiagnosticInfo[]? diagnostics, SyntaxAnnotation[]? annotations)
|
|
: base(kind, diagnostics, annotations)
|
|
{
|
|
((GreenNode)this).SlotCount = 1;
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)identifier);
|
|
this.identifier = identifier;
|
|
}
|
|
|
|
internal IdentifierNameSyntax(SyntaxKind kind, SyntaxToken identifier, SyntaxFactoryContext context)
|
|
: base(kind)
|
|
{
|
|
SetFactoryContext(context);
|
|
((GreenNode)this).SlotCount = 1;
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)identifier);
|
|
this.identifier = identifier;
|
|
}
|
|
|
|
internal IdentifierNameSyntax(SyntaxKind kind, SyntaxToken identifier)
|
|
: base(kind)
|
|
{
|
|
((GreenNode)this).SlotCount = 1;
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)identifier);
|
|
this.identifier = identifier;
|
|
}
|
|
|
|
internal override GreenNode? GetSlot(int index)
|
|
{
|
|
if (index != 0)
|
|
{
|
|
return null;
|
|
}
|
|
return (GreenNode?)(object)identifier;
|
|
}
|
|
|
|
internal override SyntaxNode CreateRed(SyntaxNode? parent, int position)
|
|
{
|
|
return (SyntaxNode)(object)new Microsoft.CodeAnalysis.CSharp.Syntax.IdentifierNameSyntax(this, parent, position);
|
|
}
|
|
|
|
public override void Accept(CSharpSyntaxVisitor visitor)
|
|
{
|
|
visitor.VisitIdentifierName(this);
|
|
}
|
|
|
|
public override TResult Accept<TResult>(CSharpSyntaxVisitor<TResult> visitor)
|
|
{
|
|
return visitor.VisitIdentifierName(this);
|
|
}
|
|
|
|
public IdentifierNameSyntax Update(SyntaxToken identifier)
|
|
{
|
|
if (identifier != Identifier)
|
|
{
|
|
IdentifierNameSyntax identifierNameSyntax = SyntaxFactory.IdentifierName(identifier);
|
|
DiagnosticInfo[] diagnostics = ((GreenNode)this).GetDiagnostics();
|
|
if (diagnostics != null && diagnostics.Length != 0)
|
|
{
|
|
identifierNameSyntax = GreenNodeExtensions.WithDiagnosticsGreen<IdentifierNameSyntax>(identifierNameSyntax, diagnostics);
|
|
}
|
|
SyntaxAnnotation[] annotations = ((GreenNode)this).GetAnnotations();
|
|
if (annotations != null && annotations.Length != 0)
|
|
{
|
|
identifierNameSyntax = GreenNodeExtensions.WithAnnotationsGreen<IdentifierNameSyntax>(identifierNameSyntax, (IEnumerable<SyntaxAnnotation>)annotations);
|
|
}
|
|
return identifierNameSyntax;
|
|
}
|
|
return this;
|
|
}
|
|
|
|
internal override GreenNode SetDiagnostics(DiagnosticInfo[]? diagnostics)
|
|
{
|
|
return (GreenNode)(object)new IdentifierNameSyntax(base.Kind, identifier, diagnostics, ((GreenNode)this).GetAnnotations());
|
|
}
|
|
|
|
internal override GreenNode SetAnnotations(SyntaxAnnotation[]? annotations)
|
|
{
|
|
return (GreenNode)(object)new IdentifierNameSyntax(base.Kind, identifier, ((GreenNode)this).GetDiagnostics(), annotations);
|
|
}
|
|
|
|
internal IdentifierNameSyntax(ObjectReader reader)
|
|
: base(reader)
|
|
{
|
|
((GreenNode)this).SlotCount = 1;
|
|
SyntaxToken syntaxToken = (SyntaxToken)reader.ReadValue();
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)syntaxToken);
|
|
identifier = syntaxToken;
|
|
}
|
|
|
|
internal override void WriteTo(ObjectWriter writer)
|
|
{
|
|
((GreenNode)this).WriteTo(writer);
|
|
writer.WriteValue((IObjectWritable)(object)identifier);
|
|
}
|
|
|
|
static IdentifierNameSyntax()
|
|
{
|
|
ObjectBinder.RegisterTypeReader(typeof(IdentifierNameSyntax), (Func<ObjectReader, IObjectWritable>)((ObjectReader r) => (IObjectWritable)(object)new IdentifierNameSyntax(r)));
|
|
}
|
|
}
|