mirror of
https://github.com/github/codeql.git
synced 2026-04-26 01:05:15 +02:00
Merge pull request #5340 from hvitved/csharp/null-checks
C#: Use `is [not] null` throughout in the extractor
This commit is contained in:
@@ -97,21 +97,21 @@ namespace Semmle.Autobuild.CSharp
|
||||
/// </summary>
|
||||
private CSharpBuildStrategy GetCSharpBuildStrategy()
|
||||
{
|
||||
if (Options.BuildCommand != null)
|
||||
if (Options.BuildCommand is not null)
|
||||
return CSharpBuildStrategy.CustomBuildCommand;
|
||||
|
||||
if (Options.Buildless)
|
||||
return CSharpBuildStrategy.Buildless;
|
||||
|
||||
if (Options.MsBuildArguments != null
|
||||
|| Options.MsBuildConfiguration != null
|
||||
|| Options.MsBuildPlatform != null
|
||||
|| Options.MsBuildTarget != null)
|
||||
if (Options.MsBuildArguments is not null
|
||||
|| Options.MsBuildConfiguration is not null
|
||||
|| Options.MsBuildPlatform is not null
|
||||
|| Options.MsBuildTarget is not null)
|
||||
{
|
||||
return CSharpBuildStrategy.MSBuild;
|
||||
}
|
||||
|
||||
if (Options.DotNetArguments != null || Options.DotNetVersion != null)
|
||||
if (Options.DotNetArguments is not null || Options.DotNetVersion is not null)
|
||||
return CSharpBuildStrategy.DotNet;
|
||||
|
||||
return CSharpBuildStrategy.Auto;
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Semmle.Autobuild.CSharp
|
||||
.SelectMany(p => Enumerators.Singleton(p).Concat(p.IncludedProjects))
|
||||
.OfType<Project>()
|
||||
.FirstOrDefault(p => !p.DotNetProject);
|
||||
if (notDotNetProject != null)
|
||||
if (notDotNetProject is not null)
|
||||
{
|
||||
builder.Log(Severity.Info, "Not using .NET Core because of incompatible project {0}", notDotNetProject);
|
||||
return BuildScript.Failure;
|
||||
@@ -103,7 +103,7 @@ namespace Semmle.Autobuild.CSharp
|
||||
|
||||
if (!compatibleClr)
|
||||
{
|
||||
if (env == null)
|
||||
if (env is null)
|
||||
env = new Dictionary<string, string>();
|
||||
env.Add("UseSharedCompilation", "false");
|
||||
}
|
||||
@@ -266,7 +266,7 @@ Invoke-Command -ScriptBlock $ScriptBlock";
|
||||
}
|
||||
|
||||
private static string DotNetCommand(IBuildActions actions, string? dotNetPath) =>
|
||||
dotNetPath != null ? actions.PathCombine(dotNetPath, "dotnet") : "dotnet";
|
||||
dotNetPath is not null ? actions.PathCombine(dotNetPath, "dotnet") : "dotnet";
|
||||
|
||||
private static BuildScript GetInfoCommand(IBuildActions actions, string? dotNetPath, IDictionary<string, string>? environment)
|
||||
{
|
||||
|
||||
@@ -13,11 +13,11 @@ namespace Semmle.Autobuild.CSharp
|
||||
BuildScript GetCommand(string? solution)
|
||||
{
|
||||
string standalone;
|
||||
if (builder.CodeQLExtractorLangRoot is object && builder.CodeQlPlatform is object)
|
||||
if (builder.CodeQLExtractorLangRoot is not null && builder.CodeQlPlatform is not null)
|
||||
{
|
||||
standalone = builder.Actions.PathCombine(builder.CodeQLExtractorLangRoot, "tools", builder.CodeQlPlatform, "Semmle.Extraction.CSharp.Standalone");
|
||||
}
|
||||
else if (builder.SemmlePlatformTools is object)
|
||||
else if (builder.SemmlePlatformTools is not null)
|
||||
{
|
||||
standalone = builder.Actions.PathCombine(builder.SemmlePlatformTools, "csharp", "Semmle.Extraction.CSharp.Standalone");
|
||||
}
|
||||
@@ -29,7 +29,7 @@ namespace Semmle.Autobuild.CSharp
|
||||
var cmd = new CommandBuilder(builder.Actions);
|
||||
cmd.RunCommand(standalone);
|
||||
|
||||
if (solution != null)
|
||||
if (solution is not null)
|
||||
cmd.QuoteArgument(solution);
|
||||
|
||||
cmd.Argument("--references:.");
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Semmle.Autobuild.Shared
|
||||
{
|
||||
public static bool AsBool(this string? value, string param, bool defaultValue)
|
||||
{
|
||||
if (value == null)
|
||||
if (value is null)
|
||||
return defaultValue;
|
||||
|
||||
switch (value.ToLower())
|
||||
@@ -81,7 +81,7 @@ namespace Semmle.Autobuild.Shared
|
||||
|
||||
public static string[] AsListWithExpandedEnvVars(this string? value, IBuildActions actions, string[] defaultValue)
|
||||
{
|
||||
if (value == null)
|
||||
if (value is null)
|
||||
return defaultValue;
|
||||
|
||||
return value.
|
||||
|
||||
@@ -176,12 +176,12 @@ namespace Semmle.Autobuild.Shared
|
||||
|
||||
// First look for `.proj` files
|
||||
ret = FindFiles(".proj", f => new Project(this, f))?.ToList();
|
||||
if (ret != null)
|
||||
if (ret is not null)
|
||||
return ret;
|
||||
|
||||
// Then look for `.sln` files
|
||||
ret = FindFiles(".sln", f => new Solution(this, f, false))?.ToList();
|
||||
if (ret != null)
|
||||
if (ret is not null)
|
||||
return ret;
|
||||
|
||||
// Finally look for language specific project files, e.g. `.csproj` files
|
||||
|
||||
@@ -157,11 +157,11 @@ namespace Semmle.Autobuild.Shared
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = redirectStandardOutput
|
||||
};
|
||||
if (workingDirectory != null)
|
||||
if (workingDirectory is not null)
|
||||
pi.WorkingDirectory = workingDirectory;
|
||||
|
||||
// Environment variables can only be used when not redirecting stdout
|
||||
if (!redirectStandardOutput && environment != null)
|
||||
if (!redirectStandardOutput && environment is not null)
|
||||
environment.ForEach(kvp => pi.Environment[kvp.Key] = kvp.Value);
|
||||
return pi;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Semmle.Autobuild.Shared
|
||||
var scripts = buildScripts.SelectMany(s => extensions.Select(e => s + e));
|
||||
var scriptPath = builder.Paths.Where(p => scripts.Any(p.Item1.ToLower().EndsWith)).OrderBy(p => p.Item2).Select(p => p.Item1).FirstOrDefault();
|
||||
|
||||
if (scriptPath == null)
|
||||
if (scriptPath is null)
|
||||
return BuildScript.Failure;
|
||||
|
||||
var chmod = new CommandBuilder(builder.Actions);
|
||||
@@ -55,7 +55,7 @@ namespace Semmle.Autobuild.Shared
|
||||
|
||||
// A specific Visual Studio version may be required
|
||||
var vsTools = MsBuildRule.GetVcVarsBatFile(builder);
|
||||
if (vsTools != null)
|
||||
if (vsTools is not null)
|
||||
command.CallBatFile(vsTools.Path);
|
||||
|
||||
builder.MaybeIndex(command, scriptPath);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
public BuildScript Analyse(Autobuilder builder, bool auto)
|
||||
{
|
||||
if (builder.Options.BuildCommand == null)
|
||||
if (builder.Options.BuildCommand is null)
|
||||
return BuildScript.Failure;
|
||||
|
||||
// Custom build commands may require a specific .NET Core version
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
// Custom build commands may require a specific Visual Studio version
|
||||
var vsTools = MsBuildRule.GetVcVarsBatFile(builder);
|
||||
if (vsTools != null)
|
||||
if (vsTools is not null)
|
||||
command.CallBatFile(vsTools.Path);
|
||||
builder.MaybeIndex(command, builder.Options.BuildCommand);
|
||||
|
||||
|
||||
@@ -150,13 +150,13 @@ namespace Semmle.Autobuild.Shared
|
||||
public override int Run(IBuildActions actions, Action<string, bool> startCallback, Action<int, string, bool> exitCallBack)
|
||||
{
|
||||
int ret1;
|
||||
if (s2a != null)
|
||||
if (s2a is not null)
|
||||
{
|
||||
ret1 = s1.Run(actions, startCallback, exitCallBack, out var stdout1);
|
||||
return s2a(stdout1, ret1).Run(actions, startCallback, exitCallBack);
|
||||
}
|
||||
|
||||
if (s2b != null)
|
||||
if (s2b is not null)
|
||||
{
|
||||
ret1 = s1.Run(actions, startCallback, exitCallBack);
|
||||
return s2b(ret1).Run(actions, startCallback, exitCallBack);
|
||||
@@ -168,7 +168,7 @@ namespace Semmle.Autobuild.Shared
|
||||
public override int Run(IBuildActions actions, Action<string, bool> startCallback, Action<int, string, bool> exitCallBack, out IList<string> stdout)
|
||||
{
|
||||
var ret1 = s1.Run(actions, startCallback, exitCallBack, out var stdout1);
|
||||
var ret2 = (s2a != null ? s2a(stdout1, ret1) : s2b!(ret1)).Run(actions, startCallback, exitCallBack, out var stdout2);
|
||||
var ret2 = (s2a is not null ? s2a(stdout1, ret1) : s2b!(ret1)).Run(actions, startCallback, exitCallBack, out var stdout2);
|
||||
var @out = new List<string>();
|
||||
@out.AddRange(stdout1);
|
||||
@out.AddRange(stdout2);
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Semmle.Autobuild.Shared
|
||||
public static IEnumerable<VcVarsBatFile> GetCandidateVcVarsFiles(IBuildActions actions)
|
||||
{
|
||||
var programFilesx86 = actions.GetEnvironmentVariable("ProgramFiles(x86)");
|
||||
if (programFilesx86 == null)
|
||||
if (programFilesx86 is null)
|
||||
yield break;
|
||||
|
||||
// Attempt to use vswhere to find installations of Visual Studio
|
||||
|
||||
@@ -145,7 +145,7 @@ namespace Semmle.Autobuild.Shared
|
||||
|
||||
public CommandBuilder QuoteArgument(string argumentsOpt)
|
||||
{
|
||||
if (argumentsOpt != null)
|
||||
if (argumentsOpt is not null)
|
||||
{
|
||||
NextArgument();
|
||||
ArgvQuote(argumentsOpt, false);
|
||||
@@ -161,7 +161,7 @@ namespace Semmle.Autobuild.Shared
|
||||
|
||||
public CommandBuilder Argument(string? argumentsOpt)
|
||||
{
|
||||
if (argumentsOpt != null)
|
||||
if (argumentsOpt is not null)
|
||||
{
|
||||
NextArgument();
|
||||
arguments.Append(argumentsOpt);
|
||||
@@ -185,7 +185,7 @@ namespace Semmle.Autobuild.Shared
|
||||
: (exe, null);
|
||||
|
||||
NextCommand();
|
||||
if (executable == null)
|
||||
if (executable is null)
|
||||
{
|
||||
executable = exe0;
|
||||
}
|
||||
|
||||
@@ -23,15 +23,15 @@ namespace Semmle.Autobuild.Shared
|
||||
|
||||
var vsTools = GetVcVarsBatFile(builder);
|
||||
|
||||
if (vsTools == null && builder.ProjectsOrSolutionsToBuild.Any())
|
||||
if (vsTools is null && builder.ProjectsOrSolutionsToBuild.Any())
|
||||
{
|
||||
var firstSolution = builder.ProjectsOrSolutionsToBuild.OfType<ISolution>().FirstOrDefault();
|
||||
vsTools = firstSolution != null
|
||||
vsTools = firstSolution is not null
|
||||
? BuildTools.FindCompatibleVcVars(builder.Actions, firstSolution)
|
||||
: BuildTools.VcVarsAllBatFiles(builder.Actions).OrderByDescending(b => b.ToolsVersion).FirstOrDefault();
|
||||
}
|
||||
|
||||
if (vsTools == null && builder.Actions.IsWindows())
|
||||
if (vsTools is null && builder.Actions.IsWindows())
|
||||
{
|
||||
builder.Log(Severity.Warning, "Could not find a suitable version of VsDevCmd.bat/vcvarsall.bat");
|
||||
}
|
||||
@@ -85,7 +85,7 @@ namespace Semmle.Autobuild.Shared
|
||||
|
||||
var command = new CommandBuilder(builder.Actions);
|
||||
|
||||
if (vsTools != null)
|
||||
if (vsTools is not null)
|
||||
{
|
||||
command.CallBatFile(vsTools.Path);
|
||||
// `vcvarsall.bat` sets a default Platform environment variable,
|
||||
@@ -105,9 +105,9 @@ namespace Semmle.Autobuild.Shared
|
||||
var configuration = builder.Options.MsBuildConfiguration ?? (projectOrSolution is ISolution s2 ? s2.DefaultConfigurationName : null);
|
||||
|
||||
command.Argument("/t:" + target);
|
||||
if (platform != null)
|
||||
if (platform is not null)
|
||||
command.Argument(string.Format("/p:Platform=\"{0}\"", platform));
|
||||
if (configuration != null)
|
||||
if (configuration is not null)
|
||||
command.Argument(string.Format("/p:Configuration=\"{0}\"", configuration));
|
||||
command.Argument("/p:MvcBuildViews=true");
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace Semmle.Autobuild.Shared
|
||||
{
|
||||
VcVarsBatFile? vsTools = null;
|
||||
|
||||
if (builder.Options.VsToolsVersion != null)
|
||||
if (builder.Options.VsToolsVersion is not null)
|
||||
{
|
||||
if (int.TryParse(builder.Options.VsToolsVersion, out var msToolsVersion))
|
||||
{
|
||||
@@ -140,7 +140,7 @@ namespace Semmle.Autobuild.Shared
|
||||
}
|
||||
|
||||
vsTools = BuildTools.FindCompatibleVcVars(builder.Actions, msToolsVersion);
|
||||
if (vsTools == null)
|
||||
if (vsTools is null)
|
||||
builder.Log(Severity.Warning, "Could not find build tools matching version {0}", msToolsVersion);
|
||||
else
|
||||
builder.Log(Severity.Info, "Setting Visual Studio tools to {0}", vsTools.Path);
|
||||
|
||||
@@ -49,13 +49,13 @@ namespace Semmle.Autobuild.Shared
|
||||
public override IEnumerable<IProjectOrSolution> IncludedProjects => includedProjects;
|
||||
|
||||
public IEnumerable<SolutionConfigurationInSolution> Configurations =>
|
||||
solution == null ? Enumerable.Empty<SolutionConfigurationInSolution>() : solution.SolutionConfigurations;
|
||||
solution is null ? Enumerable.Empty<SolutionConfigurationInSolution>() : solution.SolutionConfigurations;
|
||||
|
||||
public string DefaultConfigurationName =>
|
||||
solution == null ? "" : solution.GetDefaultConfigurationName();
|
||||
solution is null ? "" : solution.GetDefaultConfigurationName();
|
||||
|
||||
public string DefaultPlatformName =>
|
||||
solution == null ? "" : solution.GetDefaultPlatformName();
|
||||
solution is null ? "" : solution.GetDefaultPlatformName();
|
||||
|
||||
public Solution(Autobuilder builder, string path, bool allowProject) : base(builder, path)
|
||||
{
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Semmle.Extraction.CIL
|
||||
if (extractPdbs)
|
||||
{
|
||||
Pdb = PDB.PdbReader.Create(assemblyPath, PeReader);
|
||||
if (Pdb != null)
|
||||
if (Pdb is not null)
|
||||
{
|
||||
Extractor.Logger.Log(Util.Logging.Severity.Info, string.Format("Found PDB information for {0}", assemblyPath));
|
||||
}
|
||||
@@ -56,7 +56,7 @@ namespace Semmle.Extraction.CIL
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Pdb != null)
|
||||
if (Pdb is not null)
|
||||
Pdb.Dispose();
|
||||
PeReader.Dispose();
|
||||
stream.Dispose();
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
yield return file;
|
||||
yield return Tuples.assemblies(this, file, FullName, assemblyName.Name ?? string.Empty, assemblyName.Version?.ToString() ?? string.Empty);
|
||||
|
||||
if (Context.Pdb != null)
|
||||
if (Context.Pdb is not null)
|
||||
{
|
||||
foreach (var f in Context.Pdb.SourceFiles)
|
||||
{
|
||||
@@ -77,7 +77,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
}
|
||||
|
||||
// Limitation of C#: Cannot yield return inside a try-catch.
|
||||
if (product != null)
|
||||
if (product is not null)
|
||||
yield return product;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
Context.ExtractionError("Error processing bytecode", e.Message, GeneratedLocation.Create(Context), e.StackTrace);
|
||||
}
|
||||
|
||||
if (product != null)
|
||||
if (product is not null)
|
||||
yield return product;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
|
||||
yield return Tuples.cil_method_stack_size(Implementation, body.MaxStack);
|
||||
|
||||
if (methodDebugInformation != null)
|
||||
if (methodDebugInformation is not null)
|
||||
{
|
||||
var sourceLocation = Context.CreateSourceLocation(methodDebugInformation.Location);
|
||||
yield return sourceLocation;
|
||||
@@ -205,7 +205,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
IEnumerator<PDB.SequencePoint>? nextSequencePoint = null;
|
||||
PdbSourceLocation? instructionLocation = null;
|
||||
|
||||
if (methodDebugInformation != null)
|
||||
if (methodDebugInformation is not null)
|
||||
{
|
||||
nextSequencePoint = methodDebugInformation.SequencePoints.GetEnumerator();
|
||||
if (nextSequencePoint.MoveNext())
|
||||
@@ -225,7 +225,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
var instruction = new Instruction(Context, this, ilbytes!, offset, child++);
|
||||
yield return instruction;
|
||||
|
||||
if (nextSequencePoint != null && offset >= nextSequencePoint.Current.Offset)
|
||||
if (nextSequencePoint is not null && offset >= nextSequencePoint.Current.Offset)
|
||||
{
|
||||
instructionLocation = Context.CreateSourceLocation(nextSequencePoint.Current.Location);
|
||||
yield return instructionLocation;
|
||||
@@ -233,7 +233,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
nextSequencePoint = null;
|
||||
}
|
||||
|
||||
if (instructionLocation != null)
|
||||
if (instructionLocation is not null)
|
||||
yield return Tuples.cil_instruction_location(instruction, instructionLocation);
|
||||
|
||||
jump_table.Add(instruction.Offset, instruction);
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
|
||||
public static IEnumerable<Type> GetAllTypeParameters(Type? container, IEnumerable<TypeTypeParameter> thisTypeParameters)
|
||||
{
|
||||
if (container != null)
|
||||
if (container is not null)
|
||||
{
|
||||
foreach (var t in container.TypeParameters)
|
||||
yield return t;
|
||||
|
||||
@@ -390,7 +390,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
var handle = MetadataTokens.EntityHandle(payloadValue);
|
||||
var target = Context.CreateGeneric(Method, handle);
|
||||
yield return target;
|
||||
if (target != null)
|
||||
if (target is not null)
|
||||
{
|
||||
yield return Tuples.cil_access(this, target);
|
||||
}
|
||||
@@ -402,14 +402,14 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
}
|
||||
case Payload.Arg8:
|
||||
case Payload.Arg16:
|
||||
if (Method.Parameters is object)
|
||||
if (Method.Parameters is not null)
|
||||
{
|
||||
yield return Tuples.cil_access(this, Method.Parameters[(int)unsignedPayloadValue]);
|
||||
}
|
||||
break;
|
||||
case Payload.Local8:
|
||||
case Payload.Local16:
|
||||
if (Method.LocalVariables is object)
|
||||
if (Method.LocalVariables is not null)
|
||||
{
|
||||
yield return Tuples.cil_access(this, Method.LocalVariables[(int)unsignedPayloadValue]);
|
||||
}
|
||||
@@ -435,7 +435,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
Context.Extractor.Logger.Log(Util.Logging.Severity.Warning, $"Couldn't interpret payload of payload type {PayloadType} as a function pointer type. {exc.Message} {exc.StackTrace}");
|
||||
}
|
||||
|
||||
if (target != null)
|
||||
if (target is not null)
|
||||
{
|
||||
yield return target;
|
||||
yield return Tuples.cil_access(this, target);
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
yield return m;
|
||||
}
|
||||
|
||||
if (SourceDeclaration != null)
|
||||
if (SourceDeclaration is not null)
|
||||
yield return Tuples.cil_method_source_declaration(this, SourceDeclaration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
public override IEnumerable<Type> TypeParameters => gc.TypeParameters.Concat(DeclaringType.TypeParameters);
|
||||
|
||||
public override IEnumerable<Type> MethodParameters =>
|
||||
genericParams == null ? gc.MethodParameters : gc.MethodParameters.Concat(genericParams);
|
||||
genericParams is null ? gc.MethodParameters : gc.MethodParameters.Concat(genericParams);
|
||||
|
||||
public int GenericParameterCount => signature.GenericParameterCount;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
}
|
||||
|
||||
var ct = type.ContainingType;
|
||||
if (ct != null)
|
||||
if (ct is not null)
|
||||
{
|
||||
ct.WriteId(trapFile, inContext);
|
||||
trapFile.Write('.');
|
||||
@@ -41,7 +41,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
trapFile.Write(type.Name);
|
||||
|
||||
var thisTypeArguments = type.ThisTypeArguments;
|
||||
if (thisTypeArguments != null && thisTypeArguments.Any())
|
||||
if (thisTypeArguments is not null && thisTypeArguments.Any())
|
||||
{
|
||||
trapFile.Write('<');
|
||||
var index = 0;
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
|
||||
public override void WriteId(TextWriter trapFile)
|
||||
{
|
||||
if (ParentNamespace != null && !ParentNamespace.IsGlobalNamespace)
|
||||
if (ParentNamespace is not null && !ParentNamespace.IsGlobalNamespace)
|
||||
{
|
||||
ParentNamespace.WriteId(trapFile);
|
||||
trapFile.Write('.');
|
||||
@@ -77,7 +77,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
get
|
||||
{
|
||||
yield return Tuples.namespaces(this, Name);
|
||||
if (ParentNamespace is object)
|
||||
if (ParentNamespace is not null)
|
||||
yield return Tuples.parent_namespace(this, ParentNamespace);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,11 +36,11 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
isContainerNamespace = nameParser.IsContainerNamespace;
|
||||
containerName = nameParser.ContainerName;
|
||||
|
||||
unboundGenericType = nameParser.UnboundGenericTypeName == null
|
||||
unboundGenericType = nameParser.UnboundGenericTypeName is null
|
||||
? this
|
||||
: new NoMetadataHandleType(Context, nameParser.UnboundGenericTypeName);
|
||||
|
||||
if (nameParser.TypeArguments != null)
|
||||
if (nameParser.TypeArguments is not null)
|
||||
{
|
||||
thisTypeArguments = nameParser.TypeArguments.Select(t => new NoMetadataHandleType(Context, t)).ToArray();
|
||||
}
|
||||
@@ -66,7 +66,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
|
||||
private void Populate()
|
||||
{
|
||||
if (ContainingNamespace is object)
|
||||
if (ContainingNamespace is not null)
|
||||
{
|
||||
Context.Populate(ContainingNamespace);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
|
||||
var text = file.Contents;
|
||||
|
||||
if (text == null)
|
||||
if (text is null)
|
||||
Context.Extractor.Logger.Log(Util.Logging.Severity.Warning, string.Format("PDB source file {0} could not be found", OriginalPath));
|
||||
else
|
||||
Context.TrapWriter.Archive(TransformedPath, text);
|
||||
|
||||
@@ -124,7 +124,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ContainingType != null)
|
||||
if (ContainingType is not null)
|
||||
{
|
||||
foreach (var t in ContainingType.GenericArguments)
|
||||
yield return t;
|
||||
@@ -184,7 +184,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
|
||||
private bool TryGetPrimitiveTypeCode(out PrimitiveTypeCode code)
|
||||
{
|
||||
if (ContainingType == null &&
|
||||
if (ContainingType is null &&
|
||||
ContainingNamespace?.Name == Context.SystemNamespace.Name &&
|
||||
primitiveTypeCodeMapping.TryGetValue(Name, out code))
|
||||
{
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Semmle.Extraction.PDB
|
||||
.Where(p => !p.Document.IsNil && !p.IsHidden)
|
||||
.Select(p => new SequencePoint(p.Offset, new Location(
|
||||
new SourceFile(reader, p.Document), p.StartLine, p.StartColumn, p.EndLine, p.EndColumn)))
|
||||
.Where(p => p.Location.File.Path != null)
|
||||
.Where(p => p.Location.File.Path is not null)
|
||||
.ToArray();
|
||||
|
||||
return sequencePoints.Any() ? new Method(sequencePoints) : null;
|
||||
@@ -63,7 +63,7 @@ namespace Semmle.Extraction.PDB
|
||||
.Select(dirEntry => peReader.ReadEmbeddedPortablePdbDebugDirectoryData(dirEntry))
|
||||
.FirstOrDefault();
|
||||
|
||||
if (provider is object)
|
||||
if (provider is not null)
|
||||
{
|
||||
return new MetadataPdbReader(provider);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Semmle.Extraction.PDB
|
||||
{
|
||||
var methodToken = MetadataTokens.GetToken(h.ToDefinitionHandle());
|
||||
var method = reader.GetMethod(methodToken);
|
||||
if (method != null)
|
||||
if (method is not null)
|
||||
{
|
||||
if (method.GetSequencePointCount(out var count) != 0 || count == 0)
|
||||
return null;
|
||||
@@ -100,7 +100,7 @@ namespace Semmle.Extraction.PDB
|
||||
.Select(cv => cv.Path)
|
||||
.FirstOrDefault(File.Exists);
|
||||
|
||||
if (path is object)
|
||||
if (path is not null)
|
||||
{
|
||||
return new NativePdbReader(path);
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace Semmle.BuildAnalyser
|
||||
{
|
||||
var loadedAssembly = System.Reflection.Assembly.ReflectionOnlyLoad(id);
|
||||
|
||||
if (loadedAssembly != null)
|
||||
if (loadedAssembly is not null)
|
||||
{
|
||||
// The assembly was somewhere we haven't indexed before.
|
||||
// Add this assembly to our index so that subsequent lookups are faster.
|
||||
|
||||
@@ -46,11 +46,11 @@ namespace Semmle.BuildAnalyser
|
||||
get
|
||||
{
|
||||
var result = Name;
|
||||
if (Version != null)
|
||||
if (Version is not null)
|
||||
result = string.Format("{0}, Version={1}", result, Version);
|
||||
if (Culture != null)
|
||||
if (Culture is not null)
|
||||
result = string.Format("{0}, Culture={1}", result, Culture);
|
||||
if (PublicKeyToken != null)
|
||||
if (PublicKeyToken is not null)
|
||||
result = string.Format("{0}, PublicKeyToken={1}", result, PublicKeyToken);
|
||||
return result;
|
||||
}
|
||||
@@ -66,9 +66,9 @@ namespace Semmle.BuildAnalyser
|
||||
get
|
||||
{
|
||||
yield return Id;
|
||||
if (Version != null)
|
||||
if (Version is not null)
|
||||
{
|
||||
if (Culture != null)
|
||||
if (Culture is not null)
|
||||
yield return string.Format("{0}, Version={1}, Culture={2}", Name, Version, Culture);
|
||||
yield return string.Format("{0}, Version={1}", Name, Version);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace Semmle.BuildAnalyser
|
||||
using (new FileRenamer(sourceDir.GetFiles("global.json", SearchOption.AllDirectories)))
|
||||
using (new FileRenamer(sourceDir.GetFiles("Directory.Build.props", SearchOption.AllDirectories)))
|
||||
{
|
||||
var solutions = options.SolutionFile != null ?
|
||||
var solutions = options.SolutionFile is not null ?
|
||||
new[] { options.SolutionFile } :
|
||||
sourceDir.GetFiles("*.sln", SearchOption.AllDirectories).Select(d => d.FullName);
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Semmle.Extraction.CSharp.Standalone
|
||||
buildAnalysis = new BuildAnalysis(options, progressMonitor);
|
||||
References = buildAnalysis.ReferenceFiles;
|
||||
Extraction = new Extraction(options.SrcDir);
|
||||
Extraction.Sources.AddRange(options.SolutionFile == null ? buildAnalysis.AllSourceFiles : buildAnalysis.ProjectSourceFiles);
|
||||
Extraction.Sources.AddRange(options.SolutionFile is null ? buildAnalysis.AllSourceFiles : buildAnalysis.ProjectSourceFiles);
|
||||
}
|
||||
|
||||
public IEnumerable<string> References { get; }
|
||||
|
||||
@@ -22,13 +22,13 @@ namespace Semmle.Extraction.CSharp.Standalone
|
||||
get
|
||||
{
|
||||
var dotnetPath = FileUtils.FindProgramOnPath(Win32.IsWindows() ? "dotnet.exe" : "dotnet");
|
||||
var dotnetDirs = dotnetPath != null
|
||||
var dotnetDirs = dotnetPath is not null
|
||||
? new[] { dotnetPath }
|
||||
: new[] { "/usr/share/dotnet", @"C:\Program Files\dotnet" };
|
||||
var coreDirs = dotnetDirs.Select(d => Path.Combine(d, "shared", "Microsoft.NETCore.App"));
|
||||
|
||||
var dir = coreDirs.FirstOrDefault(Directory.Exists);
|
||||
if (dir is object)
|
||||
if (dir is not null)
|
||||
{
|
||||
return Directory.EnumerateDirectories(dir).OrderByDescending(Path.GetFileName);
|
||||
}
|
||||
@@ -46,7 +46,7 @@ namespace Semmle.Extraction.CSharp.Standalone
|
||||
get
|
||||
{
|
||||
var monoPath = FileUtils.FindProgramOnPath(Win32.IsWindows() ? "mono.exe" : "mono");
|
||||
var monoDirs = monoPath != null
|
||||
var monoDirs = monoPath is not null
|
||||
? new[] { monoPath }
|
||||
: new[] { "/usr/lib/mono", @"C:\Program Files\Mono\lib\mono" };
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace Semmle.Extraction.CSharp.Standalone
|
||||
|
||||
var dir = monoDirs.FirstOrDefault(Directory.Exists);
|
||||
|
||||
if (dir is object)
|
||||
if (dir is not null)
|
||||
{
|
||||
return Directory.EnumerateDirectories(dir)
|
||||
.Where(d => Char.IsDigit(Path.GetFileName(d)[0]))
|
||||
|
||||
@@ -48,9 +48,9 @@ namespace Semmle.Extraction.CSharp
|
||||
{
|
||||
if (object.ReferenceEquals(l1, l2))
|
||||
return 0;
|
||||
if (l1 == null)
|
||||
if (l1 is null)
|
||||
return -1;
|
||||
if (l2 == null)
|
||||
if (l2 is null)
|
||||
return 1;
|
||||
|
||||
var diff = l1.SourceTree == l2.SourceTree ? 0 : l1.SourceTree!.FilePath.CompareTo(l2.SourceTree!.FilePath);
|
||||
@@ -70,9 +70,9 @@ namespace Semmle.Extraction.CSharp
|
||||
/// <param name="loc">The location of the element.</param>
|
||||
public void AddElement(Label elementLabel, Key? duplicationGuardKey, Location? loc)
|
||||
{
|
||||
if (loc != null && loc.IsInSource)
|
||||
if (loc is not null && loc.IsInSource)
|
||||
elements[loc] = elementLabel;
|
||||
if (duplicationGuardKey != null)
|
||||
if (duplicationGuardKey is not null)
|
||||
duplicationGuardKeys[elementLabel] = duplicationGuardKey;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace Semmle.Extraction.CSharp
|
||||
// which can happen when processing multiple files.
|
||||
private static void EnsureSameFile(Comments.CommentBlock commentBlock, ref KeyValuePair<Location, Label>? element)
|
||||
{
|
||||
if (element != null && element.Value.Key.SourceTree != commentBlock.Location.SourceTree)
|
||||
if (element is not null && element.Value.Key.SourceTree != commentBlock.Location.SourceTree)
|
||||
element = null;
|
||||
}
|
||||
|
||||
@@ -106,19 +106,19 @@ namespace Semmle.Extraction.CSharp
|
||||
EnsureSameFile(commentBlock, ref nextElement);
|
||||
EnsureSameFile(commentBlock, ref parentElement);
|
||||
|
||||
if (previousElement != null)
|
||||
if (previousElement is not null)
|
||||
{
|
||||
var key = previousElement.Value.Value;
|
||||
callback(key, GetDuplicationGuardKey(key), commentBlock, CommentBinding.Before);
|
||||
}
|
||||
|
||||
if (nextElement != null)
|
||||
if (nextElement is not null)
|
||||
{
|
||||
var key = nextElement.Value.Value;
|
||||
callback(key, GetDuplicationGuardKey(key), commentBlock, CommentBinding.After);
|
||||
}
|
||||
|
||||
if (parentElement != null)
|
||||
if (parentElement is not null)
|
||||
{
|
||||
var key = parentElement.Value.Value;
|
||||
callback(key, GetDuplicationGuardKey(key), commentBlock, CommentBinding.Parent);
|
||||
@@ -127,17 +127,17 @@ namespace Semmle.Extraction.CSharp
|
||||
// Heuristic to decide which is the "best" element associated with the comment.
|
||||
KeyValuePair<Location, Label>? bestElement;
|
||||
|
||||
if (previousElement != null && previousElement.Value.Key.EndLine() == commentBlock.Location.StartLine())
|
||||
if (previousElement is not null && previousElement.Value.Key.EndLine() == commentBlock.Location.StartLine())
|
||||
{
|
||||
// 1. If the comment is on the same line as the previous element, use that
|
||||
bestElement = previousElement;
|
||||
}
|
||||
else if (nextElement != null && nextElement.Value.Key.StartLine() == commentBlock.Location.EndLine())
|
||||
else if (nextElement is not null && nextElement.Value.Key.StartLine() == commentBlock.Location.EndLine())
|
||||
{
|
||||
// 2. If the comment is on the same line as the next element, use that
|
||||
bestElement = nextElement;
|
||||
}
|
||||
else if (nextElement != null && previousElement != null &&
|
||||
else if (nextElement is not null && previousElement is not null &&
|
||||
previousElement.Value.Key.EndLine() + 1 == commentBlock.Location.StartLine() &&
|
||||
commentBlock.Location.EndLine() + 1 == nextElement.Value.Key.StartLine())
|
||||
{
|
||||
@@ -145,12 +145,12 @@ namespace Semmle.Extraction.CSharp
|
||||
// because it's ambiguous whether the comment refers to the next or previous element
|
||||
bestElement = parentElement;
|
||||
}
|
||||
else if (nextElement != null && nextElement.Value.Key.StartLine() == commentBlock.Location.EndLine() + 1)
|
||||
else if (nextElement is not null && nextElement.Value.Key.StartLine() == commentBlock.Location.EndLine() + 1)
|
||||
{
|
||||
// 4. If there is no gap after the comment, use "nextElement"
|
||||
bestElement = nextElement;
|
||||
}
|
||||
else if (previousElement != null && previousElement.Value.Key.EndLine() + 1 == commentBlock.Location.StartLine())
|
||||
else if (previousElement is not null && previousElement.Value.Key.EndLine() + 1 == commentBlock.Location.StartLine())
|
||||
{
|
||||
// 5. If there is no gap before the comment, use previousElement
|
||||
bestElement = previousElement;
|
||||
@@ -168,7 +168,7 @@ namespace Semmle.Extraction.CSharp
|
||||
*/
|
||||
}
|
||||
|
||||
if (bestElement != null)
|
||||
if (bestElement is not null)
|
||||
{
|
||||
var label = bestElement.Value.Value;
|
||||
callback(label, GetDuplicationGuardKey(label), commentBlock, CommentBinding.Best);
|
||||
@@ -268,7 +268,7 @@ namespace Semmle.Extraction.CSharp
|
||||
Comments.CommentBlock? block = null;
|
||||
|
||||
// Iterate comments until the commentEnumerator has gone past nextElement
|
||||
while (nextElement == null || Compare(commentEnumerator.Current.Value.Location, nextElement.Value.Key) < 0)
|
||||
while (nextElement is null || Compare(commentEnumerator.Current.Value.Location, nextElement.Value.Key) < 0)
|
||||
{
|
||||
if (block is null)
|
||||
block = new Comments.CommentBlock(commentEnumerator.Current.Value);
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
ContainingType!.PopulateGenerics();
|
||||
|
||||
var prop = PropertySymbol;
|
||||
if (prop == null)
|
||||
if (prop is null)
|
||||
{
|
||||
Context.ModelError(Symbol, "Unhandled accessor associated symbol");
|
||||
return;
|
||||
@@ -72,7 +72,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
Overrides(trapFile);
|
||||
|
||||
if (Symbol.FromSource() && Block == null)
|
||||
if (Symbol.FromSource() && Block is null)
|
||||
{
|
||||
trapFile.compiler_generated(this);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
private Assembly(Context cx, Microsoft.CodeAnalysis.Location? init)
|
||||
: base(cx, init)
|
||||
{
|
||||
if (init == null)
|
||||
if (init is null)
|
||||
{
|
||||
// This is the output assembly
|
||||
assemblyPath = ((TracingExtractor)cx.Extractor).OutputPath;
|
||||
@@ -31,7 +31,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
if (assemblyPath != null)
|
||||
if (assemblyPath is not null)
|
||||
{
|
||||
trapFile.assemblies(this, File.Create(Context, assemblyPath), assembly.ToString() ?? "",
|
||||
assembly.Identity.Name, assembly.Identity.Version.ToString());
|
||||
@@ -41,7 +41,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
public override bool NeedsPopulation => true;
|
||||
|
||||
public override int GetHashCode() =>
|
||||
Symbol == null ? 91187354 : Symbol.GetHashCode();
|
||||
Symbol is null ? 91187354 : Symbol.GetHashCode();
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
trapFile.attributes(this, type.TypeRef, entity);
|
||||
trapFile.attribute_location(this, Location);
|
||||
|
||||
if (attributeSyntax is object)
|
||||
if (attributeSyntax is not null)
|
||||
{
|
||||
if (!Context.Extractor.Standalone)
|
||||
{
|
||||
@@ -66,18 +66,18 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
private void ExtractArguments(TextWriter trapFile)
|
||||
{
|
||||
var ctorArguments = attributeSyntax?.ArgumentList?.Arguments.Where(a => a.NameEquals == null).ToList();
|
||||
var ctorArguments = attributeSyntax?.ArgumentList?.Arguments.Where(a => a.NameEquals is null).ToList();
|
||||
|
||||
var childIndex = 0;
|
||||
for (var i = 0; i < Symbol.ConstructorArguments.Length; i++)
|
||||
{
|
||||
var constructorArgument = Symbol.ConstructorArguments[i];
|
||||
var paramName = Symbol.AttributeConstructor?.Parameters[i].Name;
|
||||
var argSyntax = ctorArguments?.SingleOrDefault(a => a.NameColon != null && a.NameColon.Name.Identifier.Text == paramName);
|
||||
var argSyntax = ctorArguments?.SingleOrDefault(a => a.NameColon is not null && a.NameColon.Name.Identifier.Text == paramName);
|
||||
|
||||
if (argSyntax == null && // couldn't find named argument
|
||||
if (argSyntax is null && // couldn't find named argument
|
||||
ctorArguments?.Count > childIndex && // there're more arguments
|
||||
ctorArguments[childIndex].NameColon == null) // the argument is positional
|
||||
ctorArguments[childIndex].NameColon is null) // the argument is positional
|
||||
{
|
||||
argSyntax = ctorArguments[childIndex];
|
||||
}
|
||||
@@ -97,7 +97,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
this,
|
||||
childIndex++);
|
||||
|
||||
if (expr is object)
|
||||
if (expr is not null)
|
||||
{
|
||||
trapFile.expr_argument_name(expr, namedArgument.Key);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
}
|
||||
|
||||
public virtual Type? ContainingType => Symbol.ContainingType != null ? Type.Create(Context, Symbol.ContainingType) : null;
|
||||
public virtual Type? ContainingType => Symbol.ContainingType is not null ? Type.Create(Context, Symbol.ContainingType) : null;
|
||||
|
||||
public void PopulateModifiers(TextWriter trapFile)
|
||||
{
|
||||
@@ -77,7 +77,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
get
|
||||
{
|
||||
var loc = ReportingLocation;
|
||||
if (loc != null)
|
||||
if (loc is not null)
|
||||
{
|
||||
// Some built in operators lack locations, so loc is null.
|
||||
yield return Context.CreateLocation(ReportingLocation);
|
||||
@@ -151,7 +151,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
if (handleProp is null)
|
||||
{
|
||||
var underlyingSymbolProp = GetPropertyInfo(Symbol, "UnderlyingSymbol");
|
||||
if (underlyingSymbolProp is object)
|
||||
if (underlyingSymbolProp is not null)
|
||||
{
|
||||
if (underlyingSymbolProp.GetValue(Symbol) is object underlying)
|
||||
{
|
||||
@@ -161,7 +161,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
}
|
||||
}
|
||||
|
||||
if (handleProp is object)
|
||||
if (handleProp is not null)
|
||||
{
|
||||
switch (handleProp.GetValue(handleObj))
|
||||
{
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
index = 0;
|
||||
foreach (var file in Context.Compilation.References
|
||||
.OfType<PortableExecutableReference>()
|
||||
.Where(r => r.FilePath is object)
|
||||
.Where(r => r.FilePath is not null)
|
||||
.Select(r => File.Create(Context, r.FilePath!)))
|
||||
{
|
||||
trapFile.compilation_referencing_files(this, index++, file);
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
var syntax = Syntax;
|
||||
var initializer = syntax?.Initializer;
|
||||
|
||||
if (initializer == null)
|
||||
if (initializer is null)
|
||||
return;
|
||||
|
||||
ITypeSymbol initializerType;
|
||||
@@ -71,7 +71,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
var init = new Expression(initInfo);
|
||||
|
||||
var target = Constructor.Create(Context, (IMethodSymbol?)symbolInfo.Symbol);
|
||||
if (target == null)
|
||||
if (target is null)
|
||||
{
|
||||
Context.ModelError(Symbol, "Unable to resolve call");
|
||||
return;
|
||||
@@ -100,7 +100,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
[return: NotNullIfNotNull("constructor")]
|
||||
public static new Constructor? Create(Context cx, IMethodSymbol? constructor)
|
||||
{
|
||||
if (constructor == null)
|
||||
if (constructor is null)
|
||||
return null;
|
||||
|
||||
switch (constructor.MethodKind)
|
||||
@@ -132,7 +132,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
get
|
||||
{
|
||||
var syn = GetSyntax();
|
||||
if (syn != null)
|
||||
if (syn is not null)
|
||||
{
|
||||
return syn.Identifier.GetLocation();
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
private static new Destructor OriginalDefinition(Context cx, Destructor original, IMethodSymbol symbol)
|
||||
{
|
||||
return symbol.OriginalDefinition == null || SymbolEqualityComparer.Default.Equals(symbol.OriginalDefinition, symbol) ? original : Create(cx, symbol.OriginalDefinition);
|
||||
return symbol.OriginalDefinition is null || SymbolEqualityComparer.Default.Equals(symbol.OriginalDefinition, symbol) ? original : Create(cx, symbol.OriginalDefinition);
|
||||
}
|
||||
|
||||
public static new Destructor Create(Context cx, IMethodSymbol symbol) =>
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
ContainingType!.PopulateGenerics();
|
||||
|
||||
var @event = EventSymbol;
|
||||
if (@event == null)
|
||||
if (@event is null)
|
||||
{
|
||||
Context.ModelError(Symbol, "Unhandled event accessor associated symbol");
|
||||
return;
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
/// <returns>The string representation.</returns>
|
||||
public static string ValueAsString(object? value)
|
||||
{
|
||||
return value == null
|
||||
return value is null
|
||||
? "null"
|
||||
: value is bool b
|
||||
? b
|
||||
@@ -215,7 +215,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
switch (method.MethodKind)
|
||||
{
|
||||
case MethodKind.BuiltinOperator:
|
||||
if (method.ContainingType != null && method.ContainingType.TypeKind == Microsoft.CodeAnalysis.TypeKind.Delegate)
|
||||
if (method.ContainingType is not null && method.ContainingType.TypeKind == Microsoft.CodeAnalysis.TypeKind.Delegate)
|
||||
return CallType.UserOperator;
|
||||
return CallType.BuiltInOperator;
|
||||
case MethodKind.Constructor:
|
||||
@@ -234,7 +234,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
public static bool IsDynamic(Context cx, ExpressionSyntax node)
|
||||
{
|
||||
var ti = cx.GetTypeInfo(node).ConvertedType;
|
||||
return ti != null && ti.TypeKind == Microsoft.CodeAnalysis.TypeKind.Dynamic;
|
||||
return ti is not null && ti.TypeKind == Microsoft.CodeAnalysis.TypeKind.Dynamic;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -244,7 +244,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
/// <returns>The qualifier of the conditional access.</returns>
|
||||
protected static ExpressionSyntax FindConditionalQualifier(ExpressionSyntax node)
|
||||
{
|
||||
for (SyntaxNode? n = node; n != null; n = n.Parent)
|
||||
for (SyntaxNode? n = node; n is not null; n = n.Parent)
|
||||
{
|
||||
if (n.Parent is ConditionalAccessExpressionSyntax conditionalAccess &&
|
||||
conditionalAccess.WhenNotNull == n)
|
||||
@@ -290,7 +290,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
}
|
||||
trapFile.expr_argument(expr, mode);
|
||||
|
||||
if (arg.NameColon != null)
|
||||
if (arg.NameColon is not null)
|
||||
{
|
||||
trapFile.expr_argument_name(expr, arg.NameColon.Name.Identifier.Text);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
var type = ResolvedType;
|
||||
|
||||
if (type.Symbol == null)
|
||||
if (type.Symbol is null)
|
||||
type.Symbol = (TypeInfo.Type ?? TypeInfo.ConvertedType).DisambiguateType();
|
||||
|
||||
// Roslyn workaround: It can't work out the type of "new object[0]"
|
||||
@@ -59,7 +59,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
var elementType = Context.GetType(arrayCreation.Type.ElementType);
|
||||
|
||||
if (elementType.Symbol != null)
|
||||
if (elementType.Symbol is not null)
|
||||
// There seems to be no way to create an array with a nullable element at present.
|
||||
return new AnnotatedTypeSymbol(Context.Compilation.CreateArrayTypeSymbol(elementType.Symbol, arrayCreation.Type.RankSpecifiers.Count), NullableAnnotation.NotAnnotated);
|
||||
}
|
||||
@@ -80,7 +80,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
get
|
||||
{
|
||||
if (location == null)
|
||||
if (location is null)
|
||||
location = Node.FixedLocation();
|
||||
return location;
|
||||
}
|
||||
@@ -117,7 +117,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
get
|
||||
{
|
||||
if (cachedLocation == null)
|
||||
if (cachedLocation is null)
|
||||
cachedLocation = Context.CreateLocation(CodeAnalysisLocation);
|
||||
return cachedLocation;
|
||||
}
|
||||
@@ -164,7 +164,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
get
|
||||
{
|
||||
if (cachedSymbolInfo.Symbol == null && cachedSymbolInfo.CandidateReason == CandidateReason.None)
|
||||
if (cachedSymbolInfo.Symbol is null && cachedSymbolInfo.CandidateReason == CandidateReason.None)
|
||||
cachedSymbolInfo = Model.GetSymbolInfo(Node);
|
||||
return cachedSymbolInfo;
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
if (Syntax.Initializer != null)
|
||||
if (Syntax.Initializer is not null)
|
||||
{
|
||||
ArrayInitializer.Create(new ExpressionNodeInfo(Context, Syntax.Initializer, this, InitializerIndex));
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
var kind = GetAssignmentOperation(cx, syntax);
|
||||
var leftType = cx.GetType(syntax.Left);
|
||||
|
||||
if (leftType.Symbol != null && leftType.Symbol.SpecialType != SpecialType.None)
|
||||
if (leftType.Symbol is not null && leftType.Symbol.SpecialType != SpecialType.None)
|
||||
{
|
||||
// In Mono, the builtin types did not specify their operator invocation
|
||||
// even though EVERY operator has an invocation in C#. (This is a flaw in the dbscheme and should be fixed).
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
var qualifierType = cx.GetType(qualifier);
|
||||
|
||||
// This is a compilation error, so make a guess and continue.
|
||||
if (qualifierType.Symbol == null)
|
||||
if (qualifierType.Symbol is null)
|
||||
return ExprKind.ARRAY_ACCESS;
|
||||
|
||||
if (qualifierType.Symbol.TypeKind == Microsoft.CodeAnalysis.TypeKind.Pointer)
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
// to the extent that the stack has been known to overflow.
|
||||
using (info.Context.StackGuard)
|
||||
{
|
||||
if (info.Node == null)
|
||||
if (info.Node is null)
|
||||
{
|
||||
info.Context.ModelError("Attempt to create a null expression");
|
||||
return new Unknown(info);
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
Expr = Factory.Create(info.SetParent(this, 0));
|
||||
|
||||
var target = Method.Create(Context, method);
|
||||
if (target != null)
|
||||
if (target is not null)
|
||||
Context.TrapWriter.Writer.expr_call(this, target);
|
||||
else
|
||||
Context.ModelError(info.Node, "Failed to resolve target for operator invocation");
|
||||
@@ -44,7 +44,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
var convertedType = info.ConvertedType;
|
||||
var conversion = info.Conversion;
|
||||
|
||||
if (conversion.MethodSymbol != null)
|
||||
if (conversion.MethodSymbol is not null)
|
||||
{
|
||||
var convertedToDelegate = Entities.Type.IsDelegate(convertedType.Symbol);
|
||||
|
||||
@@ -65,15 +65,15 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
return Factory.Create(info);
|
||||
}
|
||||
|
||||
if (resolvedType.Symbol != null)
|
||||
if (resolvedType.Symbol is not null)
|
||||
return new ImplicitCast(info, conversion.MethodSymbol);
|
||||
}
|
||||
|
||||
var implicitUpcast = conversion.IsImplicit &&
|
||||
convertedType.Symbol != null &&
|
||||
convertedType.Symbol is not null &&
|
||||
!conversion.IsBoxing &&
|
||||
(
|
||||
resolvedType.Symbol == null ||
|
||||
resolvedType.Symbol is null ||
|
||||
conversion.IsReference ||
|
||||
convertedType.Symbol.SpecialType == SpecialType.System_Object)
|
||||
;
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
|
||||
var invocation = new Expression(new ExpressionInfo(Context, voidType, Context.CreateLocation(i.GetLocation()), ExprKind.METHOD_INVOCATION, this, child++, false, null));
|
||||
|
||||
if (addMethod != null)
|
||||
if (addMethod is not null)
|
||||
trapFile.expr_call(invocation, addMethod);
|
||||
else
|
||||
Context.ModelError(Syntax, "Unable to find an Add() method for collection initializer");
|
||||
|
||||
@@ -51,10 +51,10 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
case SimpleNameSyntax simpleName when (Kind == ExprKind.METHOD_INVOCATION):
|
||||
// Unqualified method call; `M()`
|
||||
memberName = simpleName.Identifier.Text;
|
||||
if (target != null && !target.IsStatic)
|
||||
if (target is not null && !target.IsStatic)
|
||||
{
|
||||
// Implicit `this` qualifier; add explicitly
|
||||
if (Location.Symbol is object &&
|
||||
if (Location.Symbol is not null &&
|
||||
Context.GetModel(Syntax).GetEnclosingSymbol(Location.Symbol.SourceSpan.Start) is IMethodSymbol callingMethod)
|
||||
{
|
||||
This.CreateImplicit(Context, callingMethod.ContainingType, Location, this, child++);
|
||||
@@ -79,7 +79,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
var isDynamicCall = IsDynamicCall(info);
|
||||
if (isDynamicCall)
|
||||
{
|
||||
if (memberName != null)
|
||||
if (memberName is not null)
|
||||
trapFile.dynamic_member_name(this, memberName);
|
||||
else
|
||||
Context.ModelError(Syntax, "Unable to get name for dynamic call.");
|
||||
@@ -87,7 +87,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
|
||||
PopulateArguments(trapFile, Syntax.ArgumentList, child);
|
||||
|
||||
if (target == null)
|
||||
if (target is null)
|
||||
{
|
||||
if (!isDynamicCall && !IsDelegateLikeCall(info))
|
||||
Context.ModelError(Syntax, "Unable to resolve target for call. (Compilation error?)");
|
||||
@@ -115,7 +115,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
var si = SymbolInfo;
|
||||
|
||||
if (si.Symbol != null)
|
||||
if (si.Symbol is not null)
|
||||
return si.Symbol as IMethodSymbol;
|
||||
|
||||
if (si.CandidateReason == CandidateReason.OverloadResolutionFailure)
|
||||
@@ -163,7 +163,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
if (si.CandidateReason == CandidateReason.LateBound &&
|
||||
node.Expression is IdentifierNameSyntax &&
|
||||
IsDynamic(info.Context, node.Expression) &&
|
||||
si.Symbol == null)
|
||||
si.Symbol is null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -173,13 +173,13 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
|
||||
private static bool IsFunctionPointer(ISymbol? symbol)
|
||||
{
|
||||
return symbol != null &&
|
||||
return symbol is not null &&
|
||||
symbol.Kind == SymbolKind.FunctionPointerType;
|
||||
}
|
||||
|
||||
private static bool IsDelegateInvoke(ISymbol? symbol)
|
||||
{
|
||||
return symbol != null &&
|
||||
return symbol is not null &&
|
||||
symbol.Kind == SymbolKind.Method &&
|
||||
((IMethodSymbol)symbol).MethodKind == MethodKind.DelegateInvoke;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
public static Lambda Create(ExpressionNodeInfo info, SimpleLambdaExpressionSyntax node) => new Lambda(info, node);
|
||||
|
||||
private Lambda(ExpressionNodeInfo info, AnonymousMethodExpressionSyntax node) :
|
||||
this(info.SetKind(ExprKind.ANONYMOUS_METHOD), node.Body, node.ParameterList == null ? Enumerable.Empty<ParameterSyntax>() : node.ParameterList.Parameters)
|
||||
this(info.SetKind(ExprKind.ANONYMOUS_METHOD), node.Body, node.ParameterList is null ? Enumerable.Empty<ParameterSyntax>() : node.ParameterList.Parameters)
|
||||
{ }
|
||||
|
||||
public static Lambda Create(ExpressionNodeInfo info, AnonymousMethodExpressionSyntax node) => new Lambda(info, node);
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
|
||||
case null:
|
||||
default:
|
||||
if (expr is object)
|
||||
if (expr is not null)
|
||||
context.ModelError(expr, "Unhandled literal type");
|
||||
else
|
||||
context.ModelError("Unhandled literal type");
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
var trapFile = info.Context.TrapWriter.Writer;
|
||||
Qualifier = Create(Context, qualifier, this, -1);
|
||||
|
||||
if (target == null)
|
||||
if (target is null)
|
||||
{
|
||||
if (info.Kind != ExprKind.DYNAMIC_MEMBER_ACCESS)
|
||||
Context.ModelError(info.Node, "Could not determine target for member access");
|
||||
@@ -59,14 +59,14 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
|
||||
var symbol = target.Symbol ?? info.Context.GetSymbolInfo(name).Symbol;
|
||||
|
||||
if (symbol == null && target.CandidateSymbols.Length >= 1)
|
||||
if (symbol is null && target.CandidateSymbols.Length >= 1)
|
||||
{
|
||||
// Pick the first symbol. This could occur for something like `nameof(Foo.Bar)`
|
||||
// where `Bar` is a method group. Technically, we don't know which symbol is accessed.
|
||||
symbol = target.CandidateSymbols[0];
|
||||
}
|
||||
|
||||
if (symbol == null)
|
||||
if (symbol is null)
|
||||
{
|
||||
info.Context.ModelError(info.Node, "Failed to determine symbol for member access");
|
||||
// Default to property access - this can still give useful results but
|
||||
|
||||
@@ -13,26 +13,26 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
|
||||
var target = symbolInfo.Symbol;
|
||||
|
||||
if (target == null &&
|
||||
if (target is null &&
|
||||
symbolInfo.CandidateReason == CandidateReason.OverloadResolutionFailure &&
|
||||
info.Node.Parent.IsKind(SyntaxKind.SuppressNullableWarningExpression))
|
||||
{
|
||||
target = symbolInfo.CandidateSymbols.FirstOrDefault();
|
||||
}
|
||||
|
||||
if (target == null && symbolInfo.CandidateReason == CandidateReason.OverloadResolutionFailure)
|
||||
if (target is null && symbolInfo.CandidateReason == CandidateReason.OverloadResolutionFailure)
|
||||
{
|
||||
// The expression is probably a cast
|
||||
target = info.Context.GetSymbolInfo((CSharpSyntaxNode)info.Node.Parent!).Symbol;
|
||||
}
|
||||
|
||||
if (target == null && (symbolInfo.CandidateReason == CandidateReason.Ambiguous || symbolInfo.CandidateReason == CandidateReason.MemberGroup))
|
||||
if (target is null && (symbolInfo.CandidateReason == CandidateReason.Ambiguous || symbolInfo.CandidateReason == CandidateReason.MemberGroup))
|
||||
{
|
||||
// Pick one at random - they probably resolve to the same ID
|
||||
target = symbolInfo.CandidateSymbols.First();
|
||||
}
|
||||
|
||||
if (target == null)
|
||||
if (target is null)
|
||||
{
|
||||
if (IsInsideIfDirective(info.Node))
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
var target = Context.GetSymbolInfo(Syntax);
|
||||
var method = (IMethodSymbol?)target.Symbol;
|
||||
if (method != null)
|
||||
if (method is not null)
|
||||
{
|
||||
trapFile.expr_call(this, Method.Create(Context, method));
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
if (Syntax.ArgumentList != null)
|
||||
if (Syntax.ArgumentList is not null)
|
||||
{
|
||||
PopulateArguments(trapFile, Syntax.ArgumentList, 0);
|
||||
}
|
||||
@@ -41,7 +41,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
}
|
||||
}
|
||||
|
||||
if (Syntax.Initializer != null)
|
||||
if (Syntax.Initializer is not null)
|
||||
{
|
||||
switch (Syntax.Initializer.Kind())
|
||||
{
|
||||
@@ -68,7 +68,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
|
||||
private static bool IsDynamicObjectCreation(Context cx, BaseObjectCreationExpressionSyntax node)
|
||||
{
|
||||
return node.ArgumentList != null &&
|
||||
return node.ArgumentList is not null &&
|
||||
node.ArgumentList.Arguments.Any(arg => IsDynamic(cx, arg.Expression));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
cx.CreateLocation(clause.GetLocation()),
|
||||
ExprKind.METHOD_INVOCATION, parent, child, false, null))
|
||||
{
|
||||
if (method != null)
|
||||
if (method is not null)
|
||||
cx.TrapWriter.Writer.expr_call(this, Method.Create(cx, method));
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
|
||||
public Clause AddArgument(ExpressionSyntax arg)
|
||||
{
|
||||
if (arg != null)
|
||||
if (arg is not null)
|
||||
arguments.Add(arg);
|
||||
return this;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
TypeSyntax? declTypeSyntax = null;
|
||||
if (getElement)
|
||||
{
|
||||
if (node is FromClauseSyntax from && from.Type != null)
|
||||
if (node is FromClauseSyntax from && from.Type is not null)
|
||||
{
|
||||
declTypeSyntax = from.Type;
|
||||
declType = cx.GetType(from.Type);
|
||||
@@ -116,7 +116,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
private static AnnotatedTypeSymbol? GetEnumerableElementType(Context cx, INamedTypeSymbol type)
|
||||
{
|
||||
var et = GetEnumerableType(cx, type);
|
||||
if (et != null)
|
||||
if (et is not null)
|
||||
return et;
|
||||
|
||||
return type.AllInterfaces
|
||||
@@ -182,13 +182,13 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
|
||||
private void DeclareIntoVariable(Context cx, IExpressionParentEntity parent, int intoChild, bool getElement)
|
||||
{
|
||||
if (intoDeclaration != null)
|
||||
if (intoDeclaration is not null)
|
||||
DeclareRangeVariable(cx, parent, intoChild, getElement, intoDeclaration, name);
|
||||
}
|
||||
|
||||
public override Expression Populate(Context cx, IExpressionParentEntity parent, int child)
|
||||
{
|
||||
if (method == null)
|
||||
if (method is null)
|
||||
cx.ModelError(node, "Unable to determine target of query expression");
|
||||
|
||||
var callExpr = new QueryCall(cx, method, node, parent, child);
|
||||
@@ -248,7 +248,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
|
||||
clauseExpr = clauseExpr.WithCallClause(method, orderByClause).AddArgument(ordering.Expression);
|
||||
|
||||
if (method == null)
|
||||
if (method is null)
|
||||
cx.ModelError(ordering, "Could not determine method call for orderby clause");
|
||||
}
|
||||
break;
|
||||
@@ -275,7 +275,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
AddArgument(joinClause.LeftExpression).
|
||||
AddArgument(joinClause.RightExpression);
|
||||
|
||||
if (joinClause.Into != null)
|
||||
if (joinClause.Into is not null)
|
||||
{
|
||||
var into = cx.GetModel(node).GetDeclaredSymbol(joinClause.Into)!;
|
||||
((LetClause)clauseExpr).WithInto(into);
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
var l = LocalVariable.Create(cx, symbol);
|
||||
l.PopulateManual(ret, isVar);
|
||||
if (optionalSyntax != null)
|
||||
if (optionalSyntax is not null)
|
||||
TypeMention.Create(cx, optionalSyntax, ret, type);
|
||||
});
|
||||
return ret;
|
||||
@@ -27,7 +27,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
private static VariableDeclaration CreateSingle(Context cx, DeclarationExpressionSyntax node, SingleVariableDesignationSyntax designation, IExpressionParentEntity parent, int child)
|
||||
{
|
||||
var variableSymbol = cx.GetModel(designation).GetDeclaredSymbol(designation) as ILocalSymbol;
|
||||
if (variableSymbol == null)
|
||||
if (variableSymbol is null)
|
||||
{
|
||||
cx.ModelError(node, "Failed to determine local variable");
|
||||
return Create(cx, node, (AnnotatedTypeSymbol?)null, parent, child);
|
||||
@@ -149,7 +149,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
var localVar = LocalVariable.Create(cx, declSymbol);
|
||||
localVar.PopulateManual(ret, isVar);
|
||||
|
||||
if (d.Initializer != null)
|
||||
if (d.Initializer is not null)
|
||||
{
|
||||
Create(cx, d.Initializer.Value, ret, 0);
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
foreach (var initializer in Symbol.DeclaringSyntaxReferences
|
||||
.Select(n => n.GetSyntax())
|
||||
.OfType<VariableDeclaratorSyntax>()
|
||||
.Where(n => n.Initializer != null))
|
||||
.Where(n => n.Initializer is not null))
|
||||
{
|
||||
Context.PopulateLater(() =>
|
||||
{
|
||||
@@ -79,7 +79,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
foreach (var initializer in Symbol.DeclaringSyntaxReferences
|
||||
.Select(n => n.GetSyntax())
|
||||
.OfType<EnumMemberDeclarationSyntax>()
|
||||
.Where(n => n.EqualsValue != null))
|
||||
.Where(n => n.EqualsValue is not null))
|
||||
{
|
||||
// Mark fields that have explicit initializers.
|
||||
var constValue = Symbol.HasConstantValue
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
var lineCount = 0;
|
||||
using (var sr = new StreamReader(originalPath, detectEncodingFromByteOrderMarks: true))
|
||||
{
|
||||
while (sr.ReadLine() != null)
|
||||
while (sr.ReadLine() is not null)
|
||||
{
|
||||
lineCount++;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
if (IsSourceDeclaration)
|
||||
{
|
||||
var expressionBody = ExpressionBody;
|
||||
if (expressionBody != null)
|
||||
if (expressionBody is not null)
|
||||
{
|
||||
// The expression may need to reference parameters in the getter.
|
||||
// So we need to arrange that the expression is populated after the getter.
|
||||
|
||||
@@ -74,13 +74,13 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
var block = Block;
|
||||
var expr = ExpressionBody;
|
||||
|
||||
if (block != null || expr != null)
|
||||
if (block is not null || expr is not null)
|
||||
{
|
||||
Context.PopulateLater(
|
||||
() =>
|
||||
{
|
||||
ExtractInitializers(trapFile);
|
||||
if (block != null)
|
||||
if (block is not null)
|
||||
Statements.Block.Create(Context, block, this, 0);
|
||||
else
|
||||
Expression.Create(Context, expr!, this, 0);
|
||||
@@ -96,7 +96,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
var node = (CSharpSyntaxNode)decl.GetSyntax();
|
||||
var lineCounts = node.Accept(new AstLineCounter());
|
||||
if (lineCounts is object)
|
||||
if (lineCounts is not null)
|
||||
{
|
||||
trapFile.numlines(callable, lineCounts);
|
||||
}
|
||||
@@ -118,7 +118,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
}
|
||||
}
|
||||
|
||||
if (Symbol.OverriddenMethod != null)
|
||||
if (Symbol.OverriddenMethod is not null)
|
||||
{
|
||||
trapFile.overrides(this, Method.Create(Context, Symbol.OverriddenMethod));
|
||||
}
|
||||
@@ -239,7 +239,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
[return: NotNullIfNotNull("methodDecl")]
|
||||
public static Method? Create(Context cx, IMethodSymbol? methodDecl)
|
||||
{
|
||||
if (methodDecl == null)
|
||||
if (methodDecl is null)
|
||||
return null;
|
||||
|
||||
var methodKind = methodDecl.MethodKind;
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
public static void ExtractModifiers(Context cx, TextWriter trapFile, IEntity key, ISymbol symbol)
|
||||
{
|
||||
var interfaceDefinition = symbol.ContainingType != null
|
||||
var interfaceDefinition = symbol.ContainingType is not null
|
||||
&& symbol.ContainingType.Kind == SymbolKind.NamedType
|
||||
&& symbol.ContainingType.TypeKind == TypeKind.Interface;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
trapFile.namespaces(this, Symbol.Name);
|
||||
|
||||
if (Symbol.ContainingNamespace != null)
|
||||
if (Symbol.ContainingNamespace is not null)
|
||||
{
|
||||
var parent = Create(Context, Symbol.ContainingNamespace);
|
||||
trapFile.parent_namespace(this, parent);
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
member.Accept(visitor);
|
||||
}
|
||||
|
||||
if (parent != null)
|
||||
if (parent is not null)
|
||||
{
|
||||
trapFile.parent_namespace_declaration(this, parent);
|
||||
}
|
||||
|
||||
@@ -75,10 +75,10 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
public override void WriteId(TextWriter trapFile)
|
||||
{
|
||||
if (Parent == null)
|
||||
if (Parent is null)
|
||||
Parent = Method.Create(Context, Symbol.ContainingSymbol as IMethodSymbol);
|
||||
|
||||
if (Parent == null)
|
||||
if (Parent is null)
|
||||
throw new InternalError(Symbol, "Couldn't get parent of symbol.");
|
||||
|
||||
trapFile.WriteSubId(Parent);
|
||||
@@ -134,7 +134,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
foreach (var syntax in Symbol.DeclaringSyntaxReferences
|
||||
.Select(d => d.GetSyntax())
|
||||
.OfType<ParameterSyntax>()
|
||||
.Where(s => s.Type != null))
|
||||
.Where(s => s.Type is not null))
|
||||
{
|
||||
TypeMention.Create(Context, syntax.Type!, this, type);
|
||||
}
|
||||
@@ -146,22 +146,22 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
// We should really define param_default(param, string)
|
||||
// And use parameter child #0 to encode the default expression.
|
||||
var defaultValue = GetParameterDefaultValue(Symbol);
|
||||
if (defaultValue == null)
|
||||
if (defaultValue is null)
|
||||
{
|
||||
// In case this parameter belongs to an accessor of an indexer, we need
|
||||
// to get the default value from the corresponding parameter belonging
|
||||
// to the indexer itself
|
||||
var method = (IMethodSymbol)Symbol.ContainingSymbol;
|
||||
if (method != null)
|
||||
if (method is not null)
|
||||
{
|
||||
var i = method.Parameters.IndexOf(Symbol);
|
||||
var indexer = (IPropertySymbol?)method.AssociatedSymbol;
|
||||
if (indexer != null)
|
||||
if (indexer is not null)
|
||||
defaultValue = GetParameterDefaultValue(indexer.Parameters[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (defaultValue != null)
|
||||
if (defaultValue is not null)
|
||||
{
|
||||
Context.PopulateLater(() =>
|
||||
{
|
||||
@@ -217,7 +217,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj != null && obj.GetType() == typeof(VarargsType);
|
||||
return obj is not null && obj.GetType() == typeof(VarargsType);
|
||||
}
|
||||
|
||||
public static VarargsType Create(Context cx) => VarargsTypeFactory.Instance.CreateEntity(cx, typeof(VarargsType), null);
|
||||
@@ -254,7 +254,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj != null && obj.GetType() == typeof(VarargsParam);
|
||||
return obj is not null && obj.GetType() == typeof(VarargsParam);
|
||||
}
|
||||
|
||||
public static VarargsParam Create(Context cx, Method method) => VarargsParamFactory.Instance.CreateEntity(cx, typeof(VarargsParam), method);
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
if (IsSourceDeclaration && Symbol.FromSource())
|
||||
{
|
||||
var expressionBody = ExpressionBody;
|
||||
if (expressionBody != null)
|
||||
if (expressionBody is not null)
|
||||
{
|
||||
Context.PopulateLater(() => Expression.Create(Context, expressionBody, this, 0));
|
||||
}
|
||||
@@ -80,7 +80,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
var child = 1;
|
||||
foreach (var initializer in declSyntaxReferences
|
||||
.Select(n => n.Initializer)
|
||||
.Where(i => i != null))
|
||||
.Where(i => i is not null))
|
||||
{
|
||||
Context.PopulateLater(() =>
|
||||
{
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
Expressions.Pattern.Create(Context, Stmt.Pattern, this, 0);
|
||||
|
||||
if (Stmt.WhenClause != null)
|
||||
if (Stmt.WhenClause is not null)
|
||||
{
|
||||
Expression.Create(Context, Stmt.WhenClause.Condition, this, 1);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
var isSpecificCatchClause = Stmt.Declaration != null;
|
||||
var isSpecificCatchClause = Stmt.Declaration is not null;
|
||||
var hasVariableDeclaration = isSpecificCatchClause && Stmt.Declaration!.Identifier.RawKind != 0;
|
||||
|
||||
if (hasVariableDeclaration) // A catch clause of the form 'catch(Ex ex) { ... }'
|
||||
@@ -32,7 +32,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
trapFile.catch_type(this, exception, false);
|
||||
}
|
||||
|
||||
if (Stmt.Filter != null)
|
||||
if (Stmt.Filter is not null)
|
||||
{
|
||||
// For backward compatibility, the catch filter clause is child number 2.
|
||||
Expression.Create(Context, Stmt.Filter.FilterExpression, this, 2);
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
if (Stmt.Expression != null)
|
||||
if (Stmt.Expression is not null)
|
||||
Expression.Create(Context, Stmt.Expression, this, 0);
|
||||
else
|
||||
Context.ModelError(Stmt, "Invalid expression statement");
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
var child = -1;
|
||||
|
||||
if (Stmt.Declaration != null)
|
||||
if (Stmt.Declaration is not null)
|
||||
VariableDeclarations.Populate(Context, Stmt.Declaration, this, child, childIncrement: -1);
|
||||
|
||||
foreach (var init in Stmt.Initializers)
|
||||
@@ -29,7 +29,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
Expression.Create(Context, init, this, child--);
|
||||
}
|
||||
|
||||
if (Stmt.Condition != null)
|
||||
if (Stmt.Condition is not null)
|
||||
{
|
||||
Expression.Create(Context, Stmt.Condition, this, 0);
|
||||
}
|
||||
|
||||
@@ -51,31 +51,31 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
trapFile.foreach_stmt_info(this, info.IsAsynchronous);
|
||||
|
||||
if (info.GetEnumeratorMethod != null)
|
||||
if (info.GetEnumeratorMethod is not null)
|
||||
{
|
||||
var m = Method.Create(Context, info.GetEnumeratorMethod);
|
||||
trapFile.foreach_stmt_desugar(this, m, ForeachSymbolType.GetEnumeratorMethod);
|
||||
}
|
||||
|
||||
if (info.MoveNextMethod != null)
|
||||
if (info.MoveNextMethod is not null)
|
||||
{
|
||||
var m = Method.Create(Context, info.MoveNextMethod);
|
||||
trapFile.foreach_stmt_desugar(this, m, ForeachSymbolType.MoveNextMethod);
|
||||
}
|
||||
|
||||
if (info.DisposeMethod != null)
|
||||
if (info.DisposeMethod is not null)
|
||||
{
|
||||
var m = Method.Create(Context, info.DisposeMethod);
|
||||
trapFile.foreach_stmt_desugar(this, m, ForeachSymbolType.DisposeMethod);
|
||||
}
|
||||
|
||||
if (info.CurrentProperty != null)
|
||||
if (info.CurrentProperty is not null)
|
||||
{
|
||||
var p = Property.Create(Context, info.CurrentProperty);
|
||||
trapFile.foreach_stmt_desugar(this, p, ForeachSymbolType.CurrentProperty);
|
||||
}
|
||||
|
||||
if (info.ElementType != null)
|
||||
if (info.ElementType is not null)
|
||||
{
|
||||
var t = Type.Create(Context, info.ElementType);
|
||||
trapFile.foreach_stmt_desugar(this, t, ForeachSymbolType.ElementType);
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
Create(Context, Stmt.Statement, this, 1);
|
||||
|
||||
if (Stmt.Else != null)
|
||||
if (Stmt.Else is not null)
|
||||
Create(Context, Stmt.Else.Statement, this, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
if (Stmt.Expression != null)
|
||||
if (Stmt.Expression is not null)
|
||||
Expression.Create(Context, Stmt.Expression, this, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
if (Stmt.Expression != null)
|
||||
if (Stmt.Expression is not null)
|
||||
Expression.Create(Context, Stmt.Expression, this, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
Create(Context, Stmt.Block, this, 0);
|
||||
|
||||
if (Stmt.Finally != null)
|
||||
if (Stmt.Finally is not null)
|
||||
{
|
||||
Create(Context, Stmt.Finally.Block, this, -1);
|
||||
}
|
||||
|
||||
@@ -19,13 +19,13 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
if (Stmt.Declaration != null)
|
||||
if (Stmt.Declaration is not null)
|
||||
VariableDeclarations.Populate(Context, Stmt.Declaration, this, -1, childIncrement: -1);
|
||||
|
||||
if (Stmt.Expression != null)
|
||||
if (Stmt.Expression is not null)
|
||||
Expression.Create(Context, Stmt.Expression, this, 0);
|
||||
|
||||
if (Stmt.Statement != null)
|
||||
if (Stmt.Statement is not null)
|
||||
Statement.Create(Context, Stmt.Statement, this, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
if (Stmt.Expression != null)
|
||||
if (Stmt.Expression is not null)
|
||||
{
|
||||
Expression.Create(Context, Stmt.Expression, this, 0);
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
case SyntaxKind.QualifiedName:
|
||||
var qns = (QualifiedNameSyntax)syntax;
|
||||
var right = Create(Context, qns.Right, parent, type);
|
||||
if (type.ContainingType is object)
|
||||
if (type.ContainingType is not null)
|
||||
{
|
||||
// Type qualifier
|
||||
Create(Context, qns.Left, right, type.ContainingType);
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
PopulateType(trapFile, constructUnderlyingTupleType);
|
||||
|
||||
if (Symbol.EnumUnderlyingType != null)
|
||||
if (Symbol.EnumUnderlyingType is not null)
|
||||
{
|
||||
trapFile.enum_underlying_type(this, Type.Create(Context, Symbol.EnumUnderlyingType).TypeRef);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj != null && obj.GetType() == typeof(NullType);
|
||||
return obj is not null && obj.GetType() == typeof(NullType);
|
||||
}
|
||||
|
||||
public static Type Create(Context cx) => NullTypeFactory.Instance.CreateEntity(cx, typeof(NullType), null);
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
public static bool ConstructedOrParentIsConstructed(INamedTypeSymbol symbol)
|
||||
{
|
||||
return !SymbolEqualityComparer.Default.Equals(symbol, symbol.OriginalDefinition) ||
|
||||
symbol.ContainingType != null && ConstructedOrParentIsConstructed(symbol.ContainingType);
|
||||
symbol.ContainingType is not null && ConstructedOrParentIsConstructed(symbol.ContainingType);
|
||||
}
|
||||
|
||||
private static Kinds.TypeKind GetClassType(Context cx, ITypeSymbol t, bool constructUnderlyingTupleType)
|
||||
@@ -101,12 +101,12 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
}
|
||||
|
||||
var containingType = ContainingType;
|
||||
if (containingType != null && Symbol.Kind != SymbolKind.TypeParameter)
|
||||
if (containingType is not null && Symbol.Kind != SymbolKind.TypeParameter)
|
||||
{
|
||||
var originalDefinition = Symbol.TypeKind == TypeKind.Error ? this : Create(Context, Symbol.OriginalDefinition);
|
||||
trapFile.nested_types(this, containingType, originalDefinition);
|
||||
}
|
||||
else if (Symbol.ContainingNamespace != null)
|
||||
else if (Symbol.ContainingNamespace is not null)
|
||||
{
|
||||
trapFile.parent_namespace(this, Namespace.Create(Context, Symbol.ContainingNamespace));
|
||||
}
|
||||
@@ -116,7 +116,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
// They are in the namespace of the original object
|
||||
var elementType = array.ElementType;
|
||||
var ns = elementType.TypeKind == TypeKind.TypeParameter ? Context.Compilation.GlobalNamespace : elementType.ContainingNamespace;
|
||||
if (ns != null)
|
||||
if (ns is not null)
|
||||
trapFile.parent_namespace(this, Namespace.Create(Context, ns));
|
||||
}
|
||||
|
||||
@@ -125,11 +125,11 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
var elementType = pointer.PointedAtType;
|
||||
var ns = elementType.TypeKind == TypeKind.TypeParameter ? Context.Compilation.GlobalNamespace : elementType.ContainingNamespace;
|
||||
|
||||
if (ns != null)
|
||||
if (ns is not null)
|
||||
trapFile.parent_namespace(this, Namespace.Create(Context, ns));
|
||||
}
|
||||
|
||||
if (Symbol.BaseType != null && Symbol.BaseType.SpecialType == SpecialType.System_MulticastDelegate)
|
||||
if (Symbol.BaseType is not null && Symbol.BaseType.SpecialType == SpecialType.System_MulticastDelegate)
|
||||
{
|
||||
// This is a delegate.
|
||||
// The method "Invoke" has the return type.
|
||||
@@ -155,7 +155,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
baseLists = baseLists.Concat(declSyntaxReferences.OfType<StructDeclarationSyntax>().Select(c => c.BaseList));
|
||||
|
||||
baseLists
|
||||
.Where(bl => bl != null)
|
||||
.Where(bl => bl is not null)
|
||||
.SelectMany(bl => bl!.Types)
|
||||
.Zip(
|
||||
baseTypes.Where(bt => bt.Symbol.SpecialType != SpecialType.System_Object),
|
||||
@@ -212,7 +212,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
/// </summary>
|
||||
public void PopulateGenerics()
|
||||
{
|
||||
if (Symbol == null || !NeedsPopulation || !Context.ExtractGenerics(this))
|
||||
if (Symbol is null || !NeedsPopulation || !Context.ExtractGenerics(this))
|
||||
return;
|
||||
|
||||
var members = new List<ISymbol>();
|
||||
@@ -240,7 +240,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
Context.CreateEntity(member);
|
||||
}
|
||||
|
||||
if (Symbol.BaseType != null)
|
||||
if (Symbol.BaseType is not null)
|
||||
Create(Context, Symbol.BaseType).PopulateGenerics();
|
||||
|
||||
foreach (var i in Symbol.Interfaces)
|
||||
@@ -262,7 +262,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
public static Type Create(Context cx, ITypeSymbol? type)
|
||||
{
|
||||
type = type.DisambiguateType();
|
||||
return type == null
|
||||
return type is null
|
||||
? NullType.Create(cx)
|
||||
: (Type)cx.CreateEntity(type);
|
||||
}
|
||||
@@ -273,7 +273,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
public virtual int Dimension => 0;
|
||||
|
||||
public static bool IsDelegate(ITypeSymbol? symbol) =>
|
||||
symbol != null && symbol.TypeKind == TypeKind.Delegate;
|
||||
symbol is not null && symbol.TypeKind == TypeKind.Delegate;
|
||||
|
||||
/// <summary>
|
||||
/// A copy of a delegate "Invoke" method or function pointer parameter.
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
var declSyntaxReferences = Symbol.DeclaringSyntaxReferences
|
||||
.Select(d => d.GetSyntax())
|
||||
.Select(s => s.Parent)
|
||||
.Where(p => p != null)
|
||||
.Where(p => p is not null)
|
||||
.Select(p => p!.Parent)
|
||||
.ToArray();
|
||||
var clauses = declSyntaxReferences.OfType<MethodDeclarationSyntax>().SelectMany(m => m.ConstraintClauses);
|
||||
|
||||
@@ -58,15 +58,15 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
private bool IsImplicitOperator(out ITypeSymbol containingType)
|
||||
{
|
||||
containingType = Symbol.ContainingType;
|
||||
if (containingType != null)
|
||||
if (containingType is not null)
|
||||
{
|
||||
var containingNamedType = containingType as INamedTypeSymbol;
|
||||
return containingNamedType == null ||
|
||||
return containingNamedType is null ||
|
||||
!containingNamedType.GetMembers(Symbol.Name).Contains(Symbol);
|
||||
}
|
||||
|
||||
var pointerType = Symbol.Parameters.Select(p => p.Type).OfType<IPointerTypeSymbol>().FirstOrDefault();
|
||||
if (pointerType != null)
|
||||
if (pointerType is not null)
|
||||
{
|
||||
containingType = pointerType;
|
||||
return true;
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
trapFile.using_directive_location(this, Context.CreateLocation(ReportingLocation));
|
||||
}
|
||||
|
||||
if (parent != null)
|
||||
if (parent is not null)
|
||||
{
|
||||
trapFile.parent_namespace_declaration(this, parent);
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ namespace Semmle.Extraction.CSharp
|
||||
var transformedSourcePath = PathTransformer.Transform(sourcePath);
|
||||
|
||||
var projectLayout = layout.LookupProjectOrNull(transformedSourcePath);
|
||||
var excluded = projectLayout == null;
|
||||
var excluded = projectLayout is null;
|
||||
var trapPath = excluded ? "" : projectLayout!.GetTrapPath(Logger, transformedSourcePath, options.TrapCompression);
|
||||
var upToDate = false;
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Semmle.Extraction.CSharp
|
||||
SpecifiedCompiler = options.CompilerName;
|
||||
specifiedFramework = options.Framework;
|
||||
|
||||
if (SpecifiedCompiler != null)
|
||||
if (SpecifiedCompiler is not null)
|
||||
{
|
||||
if (!File.Exists(SpecifiedCompiler))
|
||||
{
|
||||
@@ -69,7 +69,7 @@ namespace Semmle.Extraction.CSharp
|
||||
|
||||
var mscorlibExists = File.Exists(Path.Combine(compilerDir, "mscorlib.dll"));
|
||||
|
||||
if (specifiedFramework == null && mscorlibExists)
|
||||
if (specifiedFramework is null && mscorlibExists)
|
||||
{
|
||||
specifiedFramework = compilerDir;
|
||||
}
|
||||
@@ -81,7 +81,7 @@ namespace Semmle.Extraction.CSharp
|
||||
return;
|
||||
}
|
||||
|
||||
if (versionInfo.LegalCopyright == null || !versionInfo.LegalCopyright.Contains(vendor))
|
||||
if (versionInfo.LegalCopyright is null || !versionInfo.LegalCopyright.Contains(vendor))
|
||||
{
|
||||
SkipExtractionBecause($"the compiler isn't copyright {vendor}, but instead {versionInfo.LegalCopyright ?? "<null>"}");
|
||||
return;
|
||||
@@ -120,7 +120,7 @@ namespace Semmle.Extraction.CSharp
|
||||
/// <summary>
|
||||
/// Gets additional reference directories - the compiler directory.
|
||||
/// </summary>
|
||||
public string? AdditionalReferenceDirectories => SpecifiedCompiler != null ? Path.GetDirectoryName(SpecifiedCompiler) : null;
|
||||
public string? AdditionalReferenceDirectories => SpecifiedCompiler is not null ? Path.GetDirectoryName(SpecifiedCompiler) : null;
|
||||
|
||||
/// <summary>
|
||||
/// Adds @csc.rsp to the argument list to mimic csc.exe.
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Semmle.Extraction.CSharp
|
||||
// todo: when this context belongs to a SourceScope, the syntax tree can be retrieved from the scope, and
|
||||
// the node parameter could be removed. Is there any case when we pass in a node that's not from the current
|
||||
// tree?
|
||||
if (cachedModel == null || node.SyntaxTree != cachedModel.SyntaxTree)
|
||||
if (cachedModel is null || node.SyntaxTree != cachedModel.SyntaxTree)
|
||||
{
|
||||
cachedModel = Compilation.GetSemanticModel(node.SyntaxTree);
|
||||
}
|
||||
@@ -80,14 +80,14 @@ namespace Semmle.Extraction.CSharp
|
||||
|
||||
public override Extraction.Entities.Location CreateLocation()
|
||||
{
|
||||
return SourceTree == null
|
||||
return SourceTree is null
|
||||
? GeneratedLocation.Create(this)
|
||||
: CreateLocation(Microsoft.CodeAnalysis.Location.Create(SourceTree, Microsoft.CodeAnalysis.Text.TextSpan.FromBounds(0, 0)));
|
||||
}
|
||||
|
||||
public override Extraction.Entities.Location CreateLocation(Microsoft.CodeAnalysis.Location? location)
|
||||
{
|
||||
return (location == null || location.Kind == LocationKind.None)
|
||||
return (location is null || location.Kind == LocationKind.None)
|
||||
? GeneratedLocation.Create(this)
|
||||
: location.IsInSource
|
||||
? Entities.NonGeneratedSourceLocation.Create(this, location)
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace Semmle.Extraction.CSharp
|
||||
compilerVersion.AdditionalReferenceDirectories
|
||||
);
|
||||
|
||||
if (compilerArguments == null)
|
||||
if (compilerArguments is null)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append(" Failed to parse command line: ").AppendList(" ", Entities.Compilation.Settings.Args);
|
||||
@@ -143,7 +143,7 @@ namespace Semmle.Extraction.CSharp
|
||||
// 3) Directories specified by / lib.
|
||||
// 4) Directories specified by the LIB environment variable.
|
||||
|
||||
if (args.BaseDirectory is object)
|
||||
if (args.BaseDirectory is not null)
|
||||
{
|
||||
yield return args.BaseDirectory;
|
||||
}
|
||||
@@ -152,7 +152,7 @@ namespace Semmle.Extraction.CSharp
|
||||
yield return r;
|
||||
|
||||
var lib = System.Environment.GetEnvironmentVariable("LIB");
|
||||
if (lib != null)
|
||||
if (lib is not null)
|
||||
yield return lib;
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ namespace Semmle.Extraction.CSharp
|
||||
.Select(path => canonicalPathCache.GetCanonicalPath(path))
|
||||
.FirstOrDefault();
|
||||
|
||||
if (composed is object)
|
||||
if (composed is not null)
|
||||
{
|
||||
var reference = MakeReference(clref, composed);
|
||||
ret.Add(reference);
|
||||
|
||||
@@ -133,11 +133,11 @@ namespace Semmle.Extraction.CSharp
|
||||
// There's no apparent way to access the output filename from the compilation,
|
||||
// so we need to re-parse the command line arguments.
|
||||
|
||||
if (commandLineArguments.OutputFileName == null)
|
||||
if (commandLineArguments.OutputFileName is null)
|
||||
{
|
||||
// No output specified: Use name based on first filename
|
||||
var entry = compilation.GetEntryPoint(System.Threading.CancellationToken.None);
|
||||
if (entry == null)
|
||||
if (entry is null)
|
||||
{
|
||||
if (compilation.SyntaxTrees.Length == 0)
|
||||
throw new InvalidOperationException("No source files seen");
|
||||
@@ -188,7 +188,7 @@ namespace Semmle.Extraction.CSharp
|
||||
{
|
||||
get
|
||||
{
|
||||
return extractor == null || extractor.Standalone || compilation == null ? Enumerable.Empty<Diagnostic>() :
|
||||
return extractor is null || extractor.Standalone || compilation is null ? Enumerable.Empty<Diagnostic>() :
|
||||
compilation.
|
||||
GetDiagnostics().
|
||||
Where(e => e.Severity >= DiagnosticSeverity.Error && !errorsToIgnore.Contains(e.Id));
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Semmle.Extraction.CSharp.Populators
|
||||
// When the duplication guard key exists, it means that the entity is guarded against
|
||||
// trap duplication (<see cref = "Context.BindComments(IEntity, Location)" />).
|
||||
// We must therefore also guard comment construction.
|
||||
if (duplicationGuardKey != null)
|
||||
if (duplicationGuardKey is not null)
|
||||
cx.WithDuplicationGuard(duplicationGuardKey, a);
|
||||
else
|
||||
a();
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace Semmle.Extraction.CSharp.Populators
|
||||
|
||||
for (var i = 0; i < globalStatements.Count; i++)
|
||||
{
|
||||
if (globalStatements[i].Statement is object)
|
||||
if (globalStatements[i].Statement is not null)
|
||||
{
|
||||
Statement.Create(Cx, globalStatements[i].Statement, block, i);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Semmle.Extraction.CSharp.Populators
|
||||
/// <returns>Extended location.</returns>
|
||||
public static Location ExtendLocation(this Location l1, SyntaxNode n2)
|
||||
{
|
||||
if (n2 == null)
|
||||
if (n2 is null)
|
||||
{
|
||||
return l1;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Semmle.Extraction.CSharp.Populators
|
||||
public override void VisitUsingDirective(UsingDirectiveSyntax usingDirective)
|
||||
{
|
||||
// Only deal with "using namespace" not "using X = Y"
|
||||
if (usingDirective.Alias == null)
|
||||
if (usingDirective.Alias is null)
|
||||
new UsingDirective(Cx, usingDirective, (NamespaceDeclaration)Parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace Semmle.Extraction.CSharp
|
||||
case TypeKind.Delegate:
|
||||
case TypeKind.Error:
|
||||
var named = (INamedTypeSymbol)type;
|
||||
if (named.IsTupleType && named.TupleUnderlyingType is object)
|
||||
if (named.IsTupleType && named.TupleUnderlyingType is not null)
|
||||
named = named.TupleUnderlyingType;
|
||||
if (IdDependsOnImpl(named.ContainingType))
|
||||
return true;
|
||||
@@ -306,14 +306,14 @@ namespace Semmle.Extraction.CSharp
|
||||
|
||||
void AddContaining()
|
||||
{
|
||||
if (named.ContainingType != null)
|
||||
if (named.ContainingType is not null)
|
||||
{
|
||||
named.ContainingType.BuildOrWriteId(cx, trapFile, symbolBeingDefined, addBaseClass);
|
||||
trapFile.Write('.');
|
||||
}
|
||||
else if (named.ContainingNamespace != null)
|
||||
else if (named.ContainingNamespace is not null)
|
||||
{
|
||||
if (cx.ShouldAddAssemblyTrapPrefix && named.ContainingAssembly is object)
|
||||
if (cx.ShouldAddAssemblyTrapPrefix && named.ContainingAssembly is not null)
|
||||
BuildAssembly(named.ContainingAssembly, trapFile);
|
||||
named.ContainingNamespace.BuildNamespace(cx, trapFile);
|
||||
}
|
||||
@@ -594,7 +594,7 @@ namespace Semmle.Extraction.CSharp
|
||||
/// Holds if this method is a source declaration.
|
||||
/// </summary>
|
||||
public static bool IsSourceDeclaration(this IMethodSymbol method) =>
|
||||
IsSourceDeclaration((ISymbol)method) && SymbolEqualityComparer.Default.Equals(method, method.ConstructedFrom) && method.ReducedFrom == null;
|
||||
IsSourceDeclaration((ISymbol)method) && SymbolEqualityComparer.Default.Equals(method, method.ConstructedFrom) && method.ReducedFrom is null;
|
||||
|
||||
/// <summary>
|
||||
/// Holds if this parameter is a source declaration.
|
||||
@@ -618,7 +618,7 @@ namespace Semmle.Extraction.CSharp
|
||||
[return: NotNullIfNotNull("symbol")]
|
||||
public static IEntity? CreateEntity(this Context cx, ISymbol symbol)
|
||||
{
|
||||
if (symbol == null)
|
||||
if (symbol is null)
|
||||
return null;
|
||||
|
||||
using (cx.StackGuard)
|
||||
|
||||
@@ -148,7 +148,7 @@ namespace Semmle.Extraction
|
||||
public void PopulateLater(Action a)
|
||||
{
|
||||
var key = GetCurrentTagStackKey();
|
||||
if (key is object)
|
||||
if (key is not null)
|
||||
{
|
||||
// If we are currently executing with a duplication guard, then the same
|
||||
// guard must be used for the deferred action
|
||||
@@ -425,11 +425,11 @@ namespace Semmle.Extraction
|
||||
{
|
||||
Message message;
|
||||
|
||||
if (node != null)
|
||||
if (node is not null)
|
||||
{
|
||||
message = Message.Create(this, ex.Message, node, ex.StackTrace);
|
||||
}
|
||||
else if (symbol != null)
|
||||
else if (symbol is not null)
|
||||
{
|
||||
message = Message.Create(this, ex.Message, symbol, ex.StackTrace);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Semmle.Extraction.Entities
|
||||
|
||||
public override int GetHashCode() => 98732567;
|
||||
|
||||
public override bool Equals(object? obj) => obj != null && obj.GetType() == typeof(GeneratedLocation);
|
||||
public override bool Equals(object? obj) => obj is not null && obj.GetType() == typeof(GeneratedLocation);
|
||||
|
||||
public static GeneratedLocation Create(Context cx) => GeneratedLocationFactory.Instance.CreateEntity(cx, typeof(GeneratedLocation), null);
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace Semmle.Extraction
|
||||
/// </summary>
|
||||
/// <param name="path">The absolute path of the file to query.</param>
|
||||
/// <returns>True iff there is no layout file or the layout file specifies the file.</returns>
|
||||
public bool FileInLayout(PathTransformer.ITransformedPath path) => LookupProjectOrNull(path) != null;
|
||||
public bool FileInLayout(PathTransformer.ITransformedPath path) => LookupProjectOrNull(path) is not null;
|
||||
|
||||
private void ReadLayoutFile(string layout)
|
||||
{
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Semmle.Util
|
||||
{
|
||||
var parent = Directory.GetParent(path);
|
||||
|
||||
return parent != null ?
|
||||
return parent is not null ?
|
||||
Path.Combine(cache.GetCanonicalPath(parent.FullName), Path.GetFileName(path)) :
|
||||
path.ToUpperInvariant();
|
||||
}
|
||||
@@ -122,7 +122,7 @@ namespace Semmle.Util
|
||||
{
|
||||
var parent = Directory.GetParent(path);
|
||||
|
||||
if (parent == null)
|
||||
if (parent is null)
|
||||
{
|
||||
// We are at a root of the filesystem.
|
||||
// Convert drive letters, UNC paths etc. to uppercase.
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Semmle.Util
|
||||
{
|
||||
string? line;
|
||||
using var file = new StreamReader(arg);
|
||||
while ((line = file.ReadLine()) != null)
|
||||
while ((line = file.ReadLine()) is not null)
|
||||
textWriter.WriteLine(line);
|
||||
found = true;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user