mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
StyleChecker works, tests dont
This commit is contained in:
@@ -8,6 +8,16 @@ namespace ScriptCoreGenerator;
|
||||
|
||||
public static class SyntaxNodeExtensions
|
||||
{
|
||||
public static string? ExtractName(NameSyntax? name)
|
||||
{
|
||||
return name switch
|
||||
{
|
||||
SimpleNameSyntax ins => ins.Identifier.Text,
|
||||
QualifiedNameSyntax qns => qns.Right.Identifier.Text,
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
public static T GetParent<T>(this SyntaxNode node)
|
||||
{
|
||||
var parent = node.Parent;
|
||||
@@ -27,6 +37,25 @@ public static class SyntaxNodeExtensions
|
||||
}
|
||||
}
|
||||
|
||||
public static T? GetParentOrNull<T>(this SyntaxNode node) where T : SyntaxNode
|
||||
{
|
||||
SyntaxNode? parent = node.Parent;
|
||||
|
||||
while (true)
|
||||
{
|
||||
switch (parent)
|
||||
{
|
||||
case null:
|
||||
return null;
|
||||
case T t:
|
||||
return t;
|
||||
default:
|
||||
parent = parent.Parent;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// determine the namespace the class/enum/struct is declared in, if any
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user