mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-09 23:43:16 +02:00
Refactor list statement methods to use empty array checks over null checks
This commit is contained in:
@@ -225,19 +225,12 @@ public sealed class StatementRegistryGenerator : ISourceGenerator
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed class MethodRegistration
|
private sealed class MethodRegistration(INamedTypeSymbol containingType, IMethodSymbol method, AttributeData attribute)
|
||||||
{
|
{
|
||||||
public MethodRegistration(INamedTypeSymbol containingType, IMethodSymbol method, AttributeData attribute)
|
public INamedTypeSymbol ContainingType { get; } = containingType;
|
||||||
{
|
|
||||||
ContainingType = containingType;
|
|
||||||
Method = method;
|
|
||||||
Attribute = attribute;
|
|
||||||
}
|
|
||||||
|
|
||||||
public INamedTypeSymbol ContainingType { get; }
|
public IMethodSymbol Method { get; } = method;
|
||||||
|
|
||||||
public IMethodSymbol Method { get; }
|
public AttributeData Attribute { get; } = attribute;
|
||||||
|
|
||||||
public AttributeData Attribute { get; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,19 +13,19 @@ internal class ListStatements : StatementRuntimeInformation
|
|||||||
public void Create(string args)
|
public void Create(string args)
|
||||||
{
|
{
|
||||||
string[] parts = SplitTwo(args, " new");
|
string[] parts = SplitTwo(args, " new");
|
||||||
if (parts is null)
|
if (parts.Length == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string name = parts[0];
|
string name = parts[0];
|
||||||
if (!RuntimeInfo.Lists.ContainsKey(name))
|
if (!RuntimeInfo.Lists.TryGetValue(name, out List<string> value))
|
||||||
{
|
{
|
||||||
RuntimeInfo.Lists.Add(name, []);
|
RuntimeInfo.Lists.Add(name, []);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RuntimeInfo.Lists[name].Clear();
|
value.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ internal class ListStatements : StatementRuntimeInformation
|
|||||||
public void Delete(string args)
|
public void Delete(string args)
|
||||||
{
|
{
|
||||||
string[] parts = SplitTwo(args, " delete");
|
string[] parts = SplitTwo(args, " delete");
|
||||||
if (parts is null)
|
if (parts.Length == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ internal class ListStatements : StatementRuntimeInformation
|
|||||||
public void Clear(string args)
|
public void Clear(string args)
|
||||||
{
|
{
|
||||||
string[] parts = SplitTwo(args, " clear");
|
string[] parts = SplitTwo(args, " clear");
|
||||||
if (parts is null)
|
if (parts.Length == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ internal class ListStatements : StatementRuntimeInformation
|
|||||||
public void Length(string args)
|
public void Length(string args)
|
||||||
{
|
{
|
||||||
string[] parts = SplitTwo(args, " length");
|
string[] parts = SplitTwo(args, " length");
|
||||||
if (parts is null)
|
if (parts.Length == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ internal class ListStatements : StatementRuntimeInformation
|
|||||||
public void Add(string args)
|
public void Add(string args)
|
||||||
{
|
{
|
||||||
string[] parts = SplitTwo(args, " add ");
|
string[] parts = SplitTwo(args, " add ");
|
||||||
if (parts is null)
|
if (parts.Length == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -111,7 +111,7 @@ internal class ListStatements : StatementRuntimeInformation
|
|||||||
public void Get(string args)
|
public void Get(string args)
|
||||||
{
|
{
|
||||||
string[] parts = SplitTwo(args, " get ");
|
string[] parts = SplitTwo(args, " get ");
|
||||||
if (parts is null)
|
if (parts.Length == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,7 @@ internal class ListStatements : StatementRuntimeInformation
|
|||||||
public void Remove(string args)
|
public void Remove(string args)
|
||||||
{
|
{
|
||||||
string[] parts = SplitTwo(args, " remove ");
|
string[] parts = SplitTwo(args, " remove ");
|
||||||
if (parts is null)
|
if (parts.Length == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -156,7 +156,7 @@ internal class ListStatements : StatementRuntimeInformation
|
|||||||
public void Set(string args)
|
public void Set(string args)
|
||||||
{
|
{
|
||||||
string[] parts = SplitTwo(args, " set ");
|
string[] parts = SplitTwo(args, " set ");
|
||||||
if (parts is null)
|
if (parts.Length == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -167,7 +167,7 @@ internal class ListStatements : StatementRuntimeInformation
|
|||||||
}
|
}
|
||||||
|
|
||||||
string[] indexAndValue = SplitIndexAndValue(parts[1]);
|
string[] indexAndValue = SplitIndexAndValue(parts[1]);
|
||||||
if (indexAndValue is null)
|
if (indexAndValue.Length == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -184,7 +184,7 @@ internal class ListStatements : StatementRuntimeInformation
|
|||||||
public void Insert(string args)
|
public void Insert(string args)
|
||||||
{
|
{
|
||||||
string[] parts = SplitTwo(args, " insert ");
|
string[] parts = SplitTwo(args, " insert ");
|
||||||
if (parts is null)
|
if (parts.Length == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -195,7 +195,7 @@ internal class ListStatements : StatementRuntimeInformation
|
|||||||
}
|
}
|
||||||
|
|
||||||
string[] indexAndValue = SplitIndexAndValue(parts[1]);
|
string[] indexAndValue = SplitIndexAndValue(parts[1]);
|
||||||
if (indexAndValue is null)
|
if (indexAndValue.Length == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -214,7 +214,7 @@ internal class ListStatements : StatementRuntimeInformation
|
|||||||
if (parts.Length != 2)
|
if (parts.Length != 2)
|
||||||
{
|
{
|
||||||
RuntimeInfo.Exit("Invalid syntax", true);
|
RuntimeInfo.Exit("Invalid syntax", true);
|
||||||
return null;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
parts[0] = parts[0].Trim();
|
parts[0] = parts[0].Trim();
|
||||||
@@ -223,7 +223,7 @@ internal class ListStatements : StatementRuntimeInformation
|
|||||||
if (string.IsNullOrWhiteSpace(parts[0]))
|
if (string.IsNullOrWhiteSpace(parts[0]))
|
||||||
{
|
{
|
||||||
RuntimeInfo.Exit("Invalid syntax", true);
|
RuntimeInfo.Exit("Invalid syntax", true);
|
||||||
return null;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return parts;
|
return parts;
|
||||||
@@ -246,7 +246,7 @@ internal class ListStatements : StatementRuntimeInformation
|
|||||||
if (parts.Length != 2)
|
if (parts.Length != 2)
|
||||||
{
|
{
|
||||||
RuntimeInfo.Exit("Invalid syntax", true);
|
RuntimeInfo.Exit("Invalid syntax", true);
|
||||||
return null;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
parts[0] = parts[0].Trim();
|
parts[0] = parts[0].Trim();
|
||||||
|
|||||||
Reference in New Issue
Block a user