Skip to content

Commit

Permalink
Merge branch 'main' into better-action
Browse files Browse the repository at this point in the history
  • Loading branch information
shocklateboy92 authored Oct 10, 2023
2 parents 4d8238b + 3aeb571 commit 6bde3da
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
struct BasicStruct { }

public readonly struct ReadonlyStruct { }

public struct NamedItem2(
string name1________________________________,
string name2________________________________
)
{
public string Name1 => name1;
public string Name2 => name1;
}
38 changes: 38 additions & 0 deletions Src/CSharpier/SyntaxNodeComparer.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ private CompareResult Compare(
return this.CompareClassDeclarationSyntax(classDeclarationSyntax, formattedNode as ClassDeclarationSyntax);
case ClassOrStructConstraintSyntax classOrStructConstraintSyntax:
return this.CompareClassOrStructConstraintSyntax(classOrStructConstraintSyntax, formattedNode as ClassOrStructConstraintSyntax);
case CollectionExpressionSyntax collectionExpressionSyntax:
return this.CompareCollectionExpressionSyntax(collectionExpressionSyntax, formattedNode as CollectionExpressionSyntax);
case CompilationUnitSyntax compilationUnitSyntax:
return this.CompareCompilationUnitSyntax(compilationUnitSyntax, formattedNode as CompilationUnitSyntax);
case ConditionalAccessExpressionSyntax conditionalAccessExpressionSyntax:
Expand Down Expand Up @@ -196,6 +198,8 @@ private CompareResult Compare(
return this.CompareExplicitInterfaceSpecifierSyntax(explicitInterfaceSpecifierSyntax, formattedNode as ExplicitInterfaceSpecifierSyntax);
case ExpressionColonSyntax expressionColonSyntax:
return this.CompareExpressionColonSyntax(expressionColonSyntax, formattedNode as ExpressionColonSyntax);
case ExpressionElementSyntax expressionElementSyntax:
return this.CompareExpressionElementSyntax(expressionElementSyntax, formattedNode as ExpressionElementSyntax);
case ExpressionStatementSyntax expressionStatementSyntax:
return this.CompareExpressionStatementSyntax(expressionStatementSyntax, formattedNode as ExpressionStatementSyntax);
case ExternAliasDirectiveSyntax externAliasDirectiveSyntax:
Expand Down Expand Up @@ -416,6 +420,8 @@ private CompareResult Compare(
return this.CompareSkippedTokensTriviaSyntax(skippedTokensTriviaSyntax, formattedNode as SkippedTokensTriviaSyntax);
case SlicePatternSyntax slicePatternSyntax:
return this.CompareSlicePatternSyntax(slicePatternSyntax, formattedNode as SlicePatternSyntax);
case SpreadElementSyntax spreadElementSyntax:
return this.CompareSpreadElementSyntax(spreadElementSyntax, formattedNode as SpreadElementSyntax);
case StackAllocArrayCreationExpressionSyntax stackAllocArrayCreationExpressionSyntax:
return this.CompareStackAllocArrayCreationExpressionSyntax(stackAllocArrayCreationExpressionSyntax, formattedNode as StackAllocArrayCreationExpressionSyntax);
case StructDeclarationSyntax structDeclarationSyntax:
Expand Down Expand Up @@ -1041,6 +1047,20 @@ private CompareResult CompareClassOrStructConstraintSyntax(ClassOrStructConstrai
if (result.IsInvalid) return result;
return Equal;
}
private CompareResult CompareCollectionExpressionSyntax(CollectionExpressionSyntax originalNode, CollectionExpressionSyntax formattedNode)
{
CompareResult result;
result = this.Compare(originalNode.CloseBracketToken, formattedNode.CloseBracketToken, originalNode, formattedNode);
if (result.IsInvalid) return result;
result = this.CompareLists(originalNode.Elements, formattedNode.Elements, null, o => o.Span, originalNode.Span, formattedNode.Span);
if (result.IsInvalid) return result;
result = this.CompareLists(originalNode.Elements.GetSeparators().ToList(), formattedNode.Elements.GetSeparators().ToList(), Compare, o => o.Span, originalNode.Span, formattedNode.Span);
if (result.IsInvalid) return result;
if (originalNode.IsMissing != formattedNode.IsMissing) return NotEqual(originalNode, formattedNode);
result = this.Compare(originalNode.OpenBracketToken, formattedNode.OpenBracketToken, originalNode, formattedNode);
if (result.IsInvalid) return result;
return Equal;
}
private CompareResult CompareCompilationUnitSyntax(CompilationUnitSyntax originalNode, CompilationUnitSyntax formattedNode)
{
CompareResult result;
Expand Down Expand Up @@ -1624,6 +1644,14 @@ private CompareResult CompareExpressionColonSyntax(ExpressionColonSyntax origina
if (originalNode.IsMissing != formattedNode.IsMissing) return NotEqual(originalNode, formattedNode);
return Equal;
}
private CompareResult CompareExpressionElementSyntax(ExpressionElementSyntax originalNode, ExpressionElementSyntax formattedNode)
{
CompareResult result;
originalStack.Push((originalNode.Expression, originalNode));
formattedStack.Push((formattedNode.Expression, formattedNode));
if (originalNode.IsMissing != formattedNode.IsMissing) return NotEqual(originalNode, formattedNode);
return Equal;
}
private CompareResult CompareExpressionStatementSyntax(ExpressionStatementSyntax originalNode, ExpressionStatementSyntax formattedNode)
{
CompareResult result;
Expand Down Expand Up @@ -3295,6 +3323,16 @@ private CompareResult CompareSlicePatternSyntax(SlicePatternSyntax originalNode,
formattedStack.Push((formattedNode.Pattern, formattedNode));
return Equal;
}
private CompareResult CompareSpreadElementSyntax(SpreadElementSyntax originalNode, SpreadElementSyntax formattedNode)
{
CompareResult result;
originalStack.Push((originalNode.Expression, originalNode));
formattedStack.Push((formattedNode.Expression, formattedNode));
if (originalNode.IsMissing != formattedNode.IsMissing) return NotEqual(originalNode, formattedNode);
result = this.Compare(originalNode.OperatorToken, formattedNode.OperatorToken, originalNode, formattedNode);
if (result.IsInvalid) return result;
return Equal;
}
private CompareResult CompareStackAllocArrayCreationExpressionSyntax(StackAllocArrayCreationExpressionSyntax originalNode, StackAllocArrayCreationExpressionSyntax formattedNode)
{
CompareResult result;
Expand Down
77 changes: 77 additions & 0 deletions Src/CSharpier/SyntaxNodeJsonWriter.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static void WriteSyntaxNode(StringBuilder builder, SyntaxNode syntaxNode)
if (syntaxNode is CheckedStatementSyntax) WriteCheckedStatementSyntax(builder, syntaxNode as CheckedStatementSyntax);
if (syntaxNode is ClassDeclarationSyntax) WriteClassDeclarationSyntax(builder, syntaxNode as ClassDeclarationSyntax);
if (syntaxNode is ClassOrStructConstraintSyntax) WriteClassOrStructConstraintSyntax(builder, syntaxNode as ClassOrStructConstraintSyntax);
if (syntaxNode is CollectionExpressionSyntax) WriteCollectionExpressionSyntax(builder, syntaxNode as CollectionExpressionSyntax);
if (syntaxNode is CompilationUnitSyntax) WriteCompilationUnitSyntax(builder, syntaxNode as CompilationUnitSyntax);
if (syntaxNode is ConditionalAccessExpressionSyntax) WriteConditionalAccessExpressionSyntax(builder, syntaxNode as ConditionalAccessExpressionSyntax);
if (syntaxNode is ConditionalExpressionSyntax) WriteConditionalExpressionSyntax(builder, syntaxNode as ConditionalExpressionSyntax);
Expand Down Expand Up @@ -91,6 +92,7 @@ public static void WriteSyntaxNode(StringBuilder builder, SyntaxNode syntaxNode)
if (syntaxNode is EventFieldDeclarationSyntax) WriteEventFieldDeclarationSyntax(builder, syntaxNode as EventFieldDeclarationSyntax);
if (syntaxNode is ExplicitInterfaceSpecifierSyntax) WriteExplicitInterfaceSpecifierSyntax(builder, syntaxNode as ExplicitInterfaceSpecifierSyntax);
if (syntaxNode is ExpressionColonSyntax) WriteExpressionColonSyntax(builder, syntaxNode as ExpressionColonSyntax);
if (syntaxNode is ExpressionElementSyntax) WriteExpressionElementSyntax(builder, syntaxNode as ExpressionElementSyntax);
if (syntaxNode is ExpressionStatementSyntax) WriteExpressionStatementSyntax(builder, syntaxNode as ExpressionStatementSyntax);
if (syntaxNode is ExternAliasDirectiveSyntax) WriteExternAliasDirectiveSyntax(builder, syntaxNode as ExternAliasDirectiveSyntax);
if (syntaxNode is FieldDeclarationSyntax) WriteFieldDeclarationSyntax(builder, syntaxNode as FieldDeclarationSyntax);
Expand Down Expand Up @@ -201,6 +203,7 @@ public static void WriteSyntaxNode(StringBuilder builder, SyntaxNode syntaxNode)
if (syntaxNode is SizeOfExpressionSyntax) WriteSizeOfExpressionSyntax(builder, syntaxNode as SizeOfExpressionSyntax);
if (syntaxNode is SkippedTokensTriviaSyntax) WriteSkippedTokensTriviaSyntax(builder, syntaxNode as SkippedTokensTriviaSyntax);
if (syntaxNode is SlicePatternSyntax) WriteSlicePatternSyntax(builder, syntaxNode as SlicePatternSyntax);
if (syntaxNode is SpreadElementSyntax) WriteSpreadElementSyntax(builder, syntaxNode as SpreadElementSyntax);
if (syntaxNode is StackAllocArrayCreationExpressionSyntax) WriteStackAllocArrayCreationExpressionSyntax(builder, syntaxNode as StackAllocArrayCreationExpressionSyntax);
if (syntaxNode is StructDeclarationSyntax) WriteStructDeclarationSyntax(builder, syntaxNode as StructDeclarationSyntax);
if (syntaxNode is SubpatternSyntax) WriteSubpatternSyntax(builder, syntaxNode as SubpatternSyntax);
Expand Down Expand Up @@ -1550,6 +1553,38 @@ public static void WriteClassOrStructConstraintSyntax(StringBuilder builder, Cla
builder.Append(string.Join(",", properties.Where(o => o != null)));
builder.Append("}");
}
public static void WriteCollectionExpressionSyntax(StringBuilder builder, CollectionExpressionSyntax syntaxNode)
{
builder.Append("{");
var properties = new List<string>();
properties.Add($"\"nodeType\":\"{GetNodeType(syntaxNode.GetType())}\"");
properties.Add($"\"kind\":\"{syntaxNode.Kind().ToString()}\"");
if (syntaxNode.CloseBracketToken != default(SyntaxToken))
{
var closeBracketTokenBuilder = new StringBuilder();
WriteSyntaxToken(closeBracketTokenBuilder, syntaxNode.CloseBracketToken);
properties.Add($"\"closeBracketToken\":{closeBracketTokenBuilder.ToString()}");
}
var elements = new List<string>();
foreach(var node in syntaxNode.Elements)
{
var innerBuilder = new StringBuilder();
WriteSyntaxNode(innerBuilder, node);
elements.Add(innerBuilder.ToString());
}
properties.Add($"\"elements\":[{string.Join(",", elements)}]");
properties.Add(WriteBoolean("hasLeadingTrivia", syntaxNode.HasLeadingTrivia));
properties.Add(WriteBoolean("hasTrailingTrivia", syntaxNode.HasTrailingTrivia));
properties.Add(WriteBoolean("isMissing", syntaxNode.IsMissing));
if (syntaxNode.OpenBracketToken != default(SyntaxToken))
{
var openBracketTokenBuilder = new StringBuilder();
WriteSyntaxToken(openBracketTokenBuilder, syntaxNode.OpenBracketToken);
properties.Add($"\"openBracketToken\":{openBracketTokenBuilder.ToString()}");
}
builder.Append(string.Join(",", properties.Where(o => o != null)));
builder.Append("}");
}
public static void WriteCompilationUnitSyntax(StringBuilder builder, CompilationUnitSyntax syntaxNode)
{
builder.Append("{");
Expand Down Expand Up @@ -3074,6 +3109,24 @@ public static void WriteExpressionColonSyntax(StringBuilder builder, ExpressionC
builder.Append(string.Join(",", properties.Where(o => o != null)));
builder.Append("}");
}
public static void WriteExpressionElementSyntax(StringBuilder builder, ExpressionElementSyntax syntaxNode)
{
builder.Append("{");
var properties = new List<string>();
properties.Add($"\"nodeType\":\"{GetNodeType(syntaxNode.GetType())}\"");
properties.Add($"\"kind\":\"{syntaxNode.Kind().ToString()}\"");
if (syntaxNode.Expression != default(ExpressionSyntax))
{
var expressionBuilder = new StringBuilder();
WriteSyntaxNode(expressionBuilder, syntaxNode.Expression);
properties.Add($"\"expression\":{expressionBuilder.ToString()}");
}
properties.Add(WriteBoolean("hasLeadingTrivia", syntaxNode.HasLeadingTrivia));
properties.Add(WriteBoolean("hasTrailingTrivia", syntaxNode.HasTrailingTrivia));
properties.Add(WriteBoolean("isMissing", syntaxNode.IsMissing));
builder.Append(string.Join(",", properties.Where(o => o != null)));
builder.Append("}");
}
public static void WriteExpressionStatementSyntax(StringBuilder builder, ExpressionStatementSyntax syntaxNode)
{
builder.Append("{");
Expand Down Expand Up @@ -7375,6 +7428,30 @@ public static void WriteSlicePatternSyntax(StringBuilder builder, SlicePatternSy
builder.Append(string.Join(",", properties.Where(o => o != null)));
builder.Append("}");
}
public static void WriteSpreadElementSyntax(StringBuilder builder, SpreadElementSyntax syntaxNode)
{
builder.Append("{");
var properties = new List<string>();
properties.Add($"\"nodeType\":\"{GetNodeType(syntaxNode.GetType())}\"");
properties.Add($"\"kind\":\"{syntaxNode.Kind().ToString()}\"");
if (syntaxNode.Expression != default(ExpressionSyntax))
{
var expressionBuilder = new StringBuilder();
WriteSyntaxNode(expressionBuilder, syntaxNode.Expression);
properties.Add($"\"expression\":{expressionBuilder.ToString()}");
}
properties.Add(WriteBoolean("hasLeadingTrivia", syntaxNode.HasLeadingTrivia));
properties.Add(WriteBoolean("hasTrailingTrivia", syntaxNode.HasTrailingTrivia));
properties.Add(WriteBoolean("isMissing", syntaxNode.IsMissing));
if (syntaxNode.OperatorToken != default(SyntaxToken))
{
var operatorTokenBuilder = new StringBuilder();
WriteSyntaxToken(operatorTokenBuilder, syntaxNode.OperatorToken);
properties.Add($"\"operatorToken\":{operatorTokenBuilder.ToString()}");
}
builder.Append(string.Join(",", properties.Where(o => o != null)));
builder.Append("}");
}
public static void WriteStackAllocArrayCreationExpressionSyntax(StringBuilder builder, StackAllocArrayCreationExpressionSyntax syntaxNode)
{
builder.Append("{");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static Doc Print(BaseTypeDeclarationSyntax node, FormattingContext contex
else if (node is StructDeclarationSyntax structDeclarationSyntax)
{
keyword = structDeclarationSyntax.Keyword;
parameterList = structDeclarationSyntax.ParameterList;
}
else if (node is InterfaceDeclarationSyntax interfaceDeclarationSyntax)
{
Expand Down

0 comments on commit 6bde3da

Please sign in to comment.