Skip to content

Commit

Permalink
Updated to use is / is not for null comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Dec 21, 2024
1 parent 7a6f4de commit c6d4da3
Show file tree
Hide file tree
Showing 64 changed files with 128 additions and 154 deletions.
2 changes: 1 addition & 1 deletion src/Mages.Core.Tests/ExtensibilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ public void FunctionTakingComplexObjectShouldBeUnwrappedIfSpecified()
{
var engine = new Engine();
engine.SetStatic(typeof(WrapUnwrapTest)).WithName("Test");
var func = new Func<WrapUnwrapTest, Boolean>((obj) => obj != null);
var func = new Func<WrapUnwrapTest, Boolean>((obj) => obj is not null);
engine.SetFunction("verify", func.Method, func.Target);

var result = engine.Interpret("x = Test.create(); verify(x)");
Expand Down
2 changes: 1 addition & 1 deletion src/Mages.Core.Tests/InvalidInputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private static ParameterDefinition Po(String v)

private static ParameterDefinition P(String v, Boolean r)
{
if (v != null)
if (v is not null)
{
return new ParameterDefinition(v, r);
}
Expand Down
1 change: 1 addition & 0 deletions src/Mages.Core.Tests/Mages.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Mages.Core.Tests</RootNamespace>
<AssemblyName>Mages.Core.Tests</AssemblyName>
<LangVersion>latest</LangVersion>
<ApplicationIcon />
<StartupObject />
<Platforms>x64</Platforms>
Expand Down
2 changes: 1 addition & 1 deletion src/Mages.Core.Tests/ObservableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void ClearObservableDictionaryEmitsEvents()
var keys = new List<String>();
obs.Changed += (s, ev) =>
{
if (ev.NewValue == null && ev.OldValue != null)
if (ev.NewValue is null && ev.OldValue is not null)
{
keys.Add(ev.Key);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Mages.Core/Ast/ExpressionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ private IExpression ParsePower(IEnumerator<IToken> tokens)
var x = ParseUnary(tokens);
expressions.Push(x);
}
while (tokens.Current.Type == TokenType.Power && tokens.NextNonIgnorable() != null);
while (tokens.Current.Type == TokenType.Power && tokens.NextNonIgnorable() is not null);

do
{
Expand Down Expand Up @@ -1247,7 +1247,7 @@ private static ConstantExpression ParseNumber(IEnumerator<IToken> tokens)
private static ParameterExpression GetParameters(IExpression x)
{
var args = x as ArgumentsExpression;
return args != null ?
return args is not null ?
new ParameterExpression(args.Arguments, args.Start, args.End) :
new ParameterExpression([x], x.Start, x.End);
}
Expand Down
6 changes: 2 additions & 4 deletions src/Mages.Core/Ast/Expressions/AssignmentExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ public sealed class AssignmentExpression(IExpression variable, IExpression value
public String VariableName
{
get
{
var variable = Variable as VariableExpression;

if (variable != null)
{
if (Variable is VariableExpression variable)
{
return variable.Name;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mages.Core/Ast/Expressions/DeleteExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void Validate(IValidationContext context)
var member = _payload as MemberExpression;
var isIdentifier = _payload is VariableExpression;

if (member != null)
if (member is not null)
{
expression = member.Member;
isIdentifier = expression is IdentifierExpression;
Expand Down
6 changes: 3 additions & 3 deletions src/Mages.Core/Ast/Expressions/ParameterExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ public ParameterDefinition[] Names
{
var identifier = _parameters[i] as VariableExpression;
var assignment = _parameters[i] as AssignmentExpression;
var required = assignment == null;
var required = assignment is null;

if (!required)
{
identifier = assignment.Variable as VariableExpression;
}

if (identifier != null)
if (identifier is not null)
{
names[i] = new ParameterDefinition(identifier.Name, required);
}
Expand Down Expand Up @@ -86,7 +86,7 @@ public void Validate(IValidationContext context)
{
var assignment = (AssignmentExpression)parameter;

if (assignment.VariableName == null)
if (assignment.VariableName is null)
{
var error = new ParseError(ErrorCode.OptionalArgumentRequired, parameter);
context.Report(error);
Expand Down
2 changes: 1 addition & 1 deletion src/Mages.Core/Ast/StatementExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static IOperation[] MakeRunnable(this IEnumerable<IStatement> statements)
public static Boolean IsEmpty(this IStatement statement)
{
var simple = statement as SimpleStatement;
return simple != null && simple.Expression.IsEmpty();
return simple is not null && simple.Expression.IsEmpty();
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Mages.Core/Ast/Statements/VarStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public void Validate(IValidationContext context)
{
var assignment = _assignment as AssignmentExpression;

if (assignment == null)
if (assignment is null)
{
//TODO Report invalid construction
}
else if (assignment.VariableName == null)
else if (assignment.VariableName is null)
{
//TODO Report invalid construction
}
Expand Down
20 changes: 10 additions & 10 deletions src/Mages.Core/Ast/Walkers/CompletionTreeWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ public override void Visit(VarStatement statement)
{
var assignment = statement.Assignment as AssignmentExpression;

if (assignment != null)
if (assignment is not null)
{
var c = _variables.Count - 1;
var variables = _variables[c];
var variable = assignment.VariableName;

if (variable != null && !variables.Contains(variable))
if (variable is not null && !variables.Contains(variable))
{
variables.Add(variable);
}
Expand Down Expand Up @@ -148,7 +148,7 @@ public override void Visit(AssignmentExpression expression)
{
var name = expression.VariableName;

if (name != null)
if (name is not null)
{
var c = _variables.Count - 1;

Expand Down Expand Up @@ -186,7 +186,7 @@ public override void Visit(ParameterExpression expression)
{
var variable = parameter as VariableExpression;

if (variable != null)
if (variable is not null)
{
var variables = _variables[_variables.Count - 1];

Expand Down Expand Up @@ -243,13 +243,13 @@ public override void Visit(MemberExpression expression)
var prefix = String.Empty;
var obj = Resolve(expression.Object);

if (member != null)
if (member is not null)
{
var length = _position.Index - member.Start.Index;
prefix = member.Name.Substring(0, length);
}

if (obj != null)
if (obj is not null)
{
AddSuggestions(prefix, obj.Select(m => m.Key));
}
Expand All @@ -273,11 +273,11 @@ private IDictionary<String, Object> Resolve(IExpression expression)
var host = _symbols;
var name = default(String);

if (member != null)
if (member is not null)
{
var child = member.Member as IdentifierExpression;

if (child != null)
if (child is not null)
{
host = Resolve(member.Object);
name = child.Name;
Expand All @@ -287,13 +287,13 @@ private IDictionary<String, Object> Resolve(IExpression expression)
{
var variable = expression as VariableExpression;

if (variable != null)
if (variable is not null)
{
name = variable.Name;
}
}

if (!String.IsNullOrEmpty(name) && host != null)
if (!String.IsNullOrEmpty(name) && host is not null)
{
host.TryGetValue(name, out value);
return value as IDictionary<String, Object>;
Expand Down
4 changes: 2 additions & 2 deletions src/Mages.Core/Ast/Walkers/SymbolTreeWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ public override void Visit(VariableExpression expression)
{
var list = Find(expression.Name, expression.Scope);

if (list == null && _assigning)
if (list is null && _assigning)
{
list = [expression];
_collector[expression] = list;
}
else if (list != null)
else if (list is not null)
{
list.Add(expression);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mages.Core/Ast/Walkers/ValidationTreeWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed class ValidationTreeWalker(List<ParseError> errors) : ITreeWalker,

#region Properties

Boolean IValidationContext.IsInLoop => _loops.Count != 0 && _loops.Peek() != null;
Boolean IValidationContext.IsInLoop => _loops.Count != 0 && _loops.Peek() is not null;

#endregion

Expand Down
6 changes: 3 additions & 3 deletions src/Mages.Core/EngineExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static IPlacement SetStatic(this Engine engine, Assembly lib, Predicate<T

foreach (var type in types)
{
if (shouldInclude == null || shouldInclude.Invoke(type))
if (shouldInclude is null || shouldInclude.Invoke(type))
{
var name = obj.Keys.FindName(type);
var value = type.Expose();
Expand Down Expand Up @@ -203,7 +203,7 @@ public static Plugin AddPlugin(this Engine engine, Type type)

var constructor = type.GetConstructor([typeof(Engine)]);

if (constructor != null)
if (constructor is not null)
{
var obj = constructor.Invoke(new[] { engine });
var plugin = ConstructInstancePlugin(obj);
Expand All @@ -230,7 +230,7 @@ public static IEnumerable<Plugin> AddPlugins(this Engine engine, Assembly assemb
{
var plugin = engine.AddPlugin(type);

if (plugin != null)
if (plugin is not null)
{
plugins.Add(plugin);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Mages.Core/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static Object Call(this Function function, params Object[] arguments)
{
var argument = arguments[i];

if (argument != null)
if (argument is not null)
{
var from = argument.GetType();
var type = from.FindPrimitive();
Expand Down Expand Up @@ -92,7 +92,7 @@ public static String[] GetParameterNames(this Function function)
var local = function.Target as LocalFunction;
var parameters = local?.Parameters;

if (parameters == null)
if (parameters is null)
{
var nativeParams = function.Method.GetParameters();
var parameterNames = new String[nativeParams.Length];
Expand Down
2 changes: 1 addition & 1 deletion src/Mages.Core/Runtime/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class Container
/// <returns>The optional lifetime controlling instance.</returns>
public static IDisposable Register<T>(T service)
{
if (service != null && !_container.Contains(service))
if (service is not null && !_container.Contains(service))
{
_container.Add(service);
return new ServiceLifeTime(service);
Expand Down
2 changes: 1 addition & 1 deletion src/Mages.Core/Runtime/Converters/CamelNameSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String Select(IEnumerable<String> registered, MemberInfo member)

private static String ConvertToCamelCase(String str)
{
if (str != null)
if (str is not null)
{
if (str.Length > 1)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Mages.Core/Runtime/Converters/ConverterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static IDictionary<String, Object> ToObject(this Object value)
{
var result = new Dictionary<String, Object>();

if (value != null)
if (value is not null)
{
result["0"] = value;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Mages.Core/Runtime/Converters/TypeConverterMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public Func<Object, Object> FindConverter(Type to)

return obj =>
{
if (obj != null)
if (obj is not null)
{
var converter = default(Func<Object, Object>);
var type = obj.GetType();
Expand Down Expand Up @@ -63,7 +63,7 @@ public Func<Object, Object> FindConverter(Type from, Type to)
var p = inv.GetParameters();
var t = TargetWrapper.Construct(inv.ReturnType, p);

if (t != null)
if (t is not null)
{
return obj =>
{
Expand Down
6 changes: 3 additions & 3 deletions src/Mages.Core/Runtime/Functions/Curry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ public static Function Shuffle(Object[] args)
var end = args.Length - 1;
var target = args[end] as Function;

if (target != null)
if (target is not null)
{
var wrapper = target.Target as LocalFunction;
var parameters = wrapper?.Parameters;

if (parameters != null)
if (parameters is not null)
{
var indices = new Int32[parameters.Length];
var result = default(Function);
Expand Down Expand Up @@ -152,7 +152,7 @@ private static Int32 ShuffleParameters(Object[] args, ParameterDefinition[] para
{
var s = arg as String;

if (s != null)
if (s is not null)
{
for (var j = 0; j < parameters.Length; j++)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Mages.Core/Runtime/Functions/SimpleRandom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ private static Int32 ToInteger(Double argument)

private static void EnsureRandom()
{
if (_random == null)
{
_random = new Random();
}
_random ??= new Random();
}
}
10 changes: 5 additions & 5 deletions src/Mages.Core/Runtime/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static Boolean Satisfies(this IDictionary<String, Object> constraints, Ob
{
var obj = value as IDictionary<String, Object>;

if (obj != null && obj.Count >= constraints.Count)
if (obj is not null && obj.Count >= constraints.Count)
{
foreach (var constraint in constraints)
{
Expand All @@ -129,8 +129,8 @@ public static Boolean Satisfies(this IDictionary<String, Object> constraints, Ob
var simple = constraint.Value as String;
var extended = constraint.Value as IDictionary<String, Object>;

if ((simple == null || val.ToType()["name"].ToString() == simple) &&
(extended == null || extended.Satisfies(val)))
if ((simple is null || val.ToType()["name"].ToString() == simple) &&
(extended is null || extended.Satisfies(val)))
{
continue;
}
Expand Down Expand Up @@ -367,7 +367,7 @@ public static Function WrapFunction(this MethodInfo method, Object target)
{
var result = Curry.Min(parameters.Length, f, args);

if (result == null && method.TryMatch(parameters, ref args))
if (result is null && method.TryMatch(parameters, ref args))
{
result = method.Call(target, args);
}
Expand All @@ -390,7 +390,7 @@ public static Object WrapObject(this Object value)
return new Future(task);
}

if (value != null)
if (value is not null)
{
var type = value.GetType();
var target = type.FindPrimitive();
Expand Down
2 changes: 1 addition & 1 deletion src/Mages.Core/Runtime/JsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void SerializeTo(IDictionary<String, Object> obj, StringBuilder buffer,

private void SerializeTo(Object value, StringBuilder buffer, Int32 level)
{
if (value == null)
if (value is null)
{
buffer.Append("null");
}
Expand Down
Loading

0 comments on commit c6d4da3

Please sign in to comment.