Skip to content

Commit

Permalink
adding an enum walker for #1492
Browse files Browse the repository at this point in the history
  • Loading branch information
belav committed Feb 23, 2025
1 parent b294d20 commit 3ab5ce8
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions Src/SyntaxFinder/Walkers/EnumWalker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Collections.Concurrent;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace SyntaxFinder.Walkers;

public class EnumWalker(string file) : SyntaxFinderWalker(file)
{
public static readonly ConcurrentDictionary<string, List<string>> MembersInType = new();
public static int Total;
public static int Matching;

public override void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
{
this.VisitType(node);
base.VisitEnumMemberDeclaration(node);
}

private void VisitType(EnumMemberDeclarationSyntax node)
{
if (!node.AttributeLists.Any() || node.AttributeLists.Span.Length > 8)
{
return;
}

Interlocked.Increment(ref Total);
if (
node.SyntaxTree.GetLineSpan(node.AttributeLists.First().Span).StartLinePosition.Line
== node.SyntaxTree.GetLineSpan(node.Identifier.Span).StartLinePosition.Line
)
{
Interlocked.Increment(ref Matching);
this.WriteCode(node);
}
}

private static bool IsMultiline(SyntaxNode syntaxNode)
{
var lineSpan = syntaxNode.SyntaxTree.GetLineSpan(syntaxNode.Span);
return lineSpan.StartLinePosition.Line != lineSpan.EndLinePosition.Line;
}

public static void WriteResult()
{
foreach (var entry in MembersInType)
{
Console.WriteLine(entry.Key);
foreach (var member in entry.Value.OrderBy(o => o))
{
Console.WriteLine(" " + member);
}
}

ResultWriter.WriteMatching(Total, Matching);
}
}

0 comments on commit 3ab5ce8

Please sign in to comment.