127 lines
4.3 KiB
C#
127 lines
4.3 KiB
C#
using System;
|
|||
|
|
using System.Collections.Generic;
|
||
|
|
using Roslyn.Utilities;
|
||
|
|
|
||
|
|
namespace Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax;
|
||
|
|
|
||
|
|
internal sealed class WhereClauseSyntax : QueryClauseSyntax
|
||
|
|
{
|
||
|
|
internal readonly SyntaxToken whereKeyword;
|
||
|
|
|
||
|
|
internal readonly ExpressionSyntax condition;
|
||
|
|
|
||
|
|
public SyntaxToken WhereKeyword => whereKeyword;
|
||
|
|
|
||
|
|
public ExpressionSyntax Condition => condition;
|
||
|
|
|
||
|
|
internal WhereClauseSyntax(SyntaxKind kind, SyntaxToken whereKeyword, ExpressionSyntax condition, DiagnosticInfo[]? diagnostics, SyntaxAnnotation[]? annotations)
|
||
|
|
: base(kind, diagnostics, annotations)
|
||
|
|
{
|
||
|
|
((GreenNode)this).SlotCount = 2;
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)whereKeyword);
|
||
|
|
this.whereKeyword = whereKeyword;
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)condition);
|
||
|
|
this.condition = condition;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal WhereClauseSyntax(SyntaxKind kind, SyntaxToken whereKeyword, ExpressionSyntax condition, SyntaxFactoryContext context)
|
||
|
|
: base(kind)
|
||
|
|
{
|
||
|
|
SetFactoryContext(context);
|
||
|
|
((GreenNode)this).SlotCount = 2;
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)whereKeyword);
|
||
|
|
this.whereKeyword = whereKeyword;
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)condition);
|
||
|
|
this.condition = condition;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal WhereClauseSyntax(SyntaxKind kind, SyntaxToken whereKeyword, ExpressionSyntax condition)
|
||
|
|
: base(kind)
|
||
|
|
{
|
||
|
|
((GreenNode)this).SlotCount = 2;
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)whereKeyword);
|
||
|
|
this.whereKeyword = whereKeyword;
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)condition);
|
||
|
|
this.condition = condition;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override GreenNode? GetSlot(int index)
|
||
|
|
{
|
||
|
|
return (GreenNode?)(index switch
|
||
|
|
{
|
||
|
|
0 => whereKeyword,
|
||
|
|
1 => condition,
|
||
|
|
_ => null,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override SyntaxNode CreateRed(SyntaxNode? parent, int position)
|
||
|
|
{
|
||
|
|
return (SyntaxNode)(object)new Microsoft.CodeAnalysis.CSharp.Syntax.WhereClauseSyntax(this, parent, position);
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void Accept(CSharpSyntaxVisitor visitor)
|
||
|
|
{
|
||
|
|
visitor.VisitWhereClause(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
public override TResult Accept<TResult>(CSharpSyntaxVisitor<TResult> visitor)
|
||
|
|
{
|
||
|
|
return visitor.VisitWhereClause(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
public WhereClauseSyntax Update(SyntaxToken whereKeyword, ExpressionSyntax condition)
|
||
|
|
{
|
||
|
|
if (whereKeyword != WhereKeyword || condition != Condition)
|
||
|
|
{
|
||
|
|
WhereClauseSyntax whereClauseSyntax = SyntaxFactory.WhereClause(whereKeyword, condition);
|
||
|
|
DiagnosticInfo[] diagnostics = ((GreenNode)this).GetDiagnostics();
|
||
|
|
if (diagnostics != null && diagnostics.Length != 0)
|
||
|
|
{
|
||
|
|
whereClauseSyntax = GreenNodeExtensions.WithDiagnosticsGreen<WhereClauseSyntax>(whereClauseSyntax, diagnostics);
|
||
|
|
}
|
||
|
|
SyntaxAnnotation[] annotations = ((GreenNode)this).GetAnnotations();
|
||
|
|
if (annotations != null && annotations.Length != 0)
|
||
|
|
{
|
||
|
|
whereClauseSyntax = GreenNodeExtensions.WithAnnotationsGreen<WhereClauseSyntax>(whereClauseSyntax, (IEnumerable<SyntaxAnnotation>)annotations);
|
||
|
|
}
|
||
|
|
return whereClauseSyntax;
|
||
|
|
}
|
||
|
|
return this;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override GreenNode SetDiagnostics(DiagnosticInfo[]? diagnostics)
|
||
|
|
{
|
||
|
|
return (GreenNode)(object)new WhereClauseSyntax(base.Kind, whereKeyword, condition, diagnostics, ((GreenNode)this).GetAnnotations());
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override GreenNode SetAnnotations(SyntaxAnnotation[]? annotations)
|
||
|
|
{
|
||
|
|
return (GreenNode)(object)new WhereClauseSyntax(base.Kind, whereKeyword, condition, ((GreenNode)this).GetDiagnostics(), annotations);
|
||
|
|
}
|
||
|
|
|
||
|
|
internal WhereClauseSyntax(ObjectReader reader)
|
||
|
|
: base(reader)
|
||
|
|
{
|
||
|
|
((GreenNode)this).SlotCount = 2;
|
||
|
|
SyntaxToken syntaxToken = (SyntaxToken)reader.ReadValue();
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)syntaxToken);
|
||
|
|
whereKeyword = syntaxToken;
|
||
|
|
ExpressionSyntax expressionSyntax = (ExpressionSyntax)reader.ReadValue();
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)expressionSyntax);
|
||
|
|
condition = expressionSyntax;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override void WriteTo(ObjectWriter writer)
|
||
|
|
{
|
||
|
|
((GreenNode)this).WriteTo(writer);
|
||
|
|
writer.WriteValue((IObjectWritable)(object)whereKeyword);
|
||
|
|
writer.WriteValue((IObjectWritable)(object)condition);
|
||
|
|
}
|
||
|
|
|
||
|
|
static WhereClauseSyntax()
|
||
|
|
{
|
||
|
|
ObjectBinder.RegisterTypeReader(typeof(WhereClauseSyntax), (Func<ObjectReader, IObjectWritable>)((ObjectReader r) => (IObjectWritable)(object)new WhereClauseSyntax(r)));
|
||
|
|
}
|
||
|
|
}
|