зеркало из https://github.com/github/codeql.git
C#: Add sealed modifier to classes to fix dispose-pattern, remove explicit IDisposable implementations
This commit is contained in:
Родитель
397be7e98f
Коммит
e73ced2275
|
@ -12,7 +12,7 @@ namespace Semmle.Extraction.CIL
|
||||||
/// Adds additional context that is specific for CIL extraction.
|
/// Adds additional context that is specific for CIL extraction.
|
||||||
/// One context = one DLL/EXE.
|
/// One context = one DLL/EXE.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
partial class Context : IDisposable
|
sealed partial class Context : IDisposable
|
||||||
{
|
{
|
||||||
readonly FileStream stream;
|
readonly FileStream stream;
|
||||||
Entities.Assembly? assemblyNull;
|
Entities.Assembly? assemblyNull;
|
||||||
|
@ -58,7 +58,7 @@ namespace Semmle.Extraction.CIL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IDisposable.Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
if (pdb != null)
|
if (pdb != null)
|
||||||
pdb.Dispose();
|
pdb.Dispose();
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace Semmle.Extraction.CIL
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides methods for creating and caching various entities.
|
/// Provides methods for creating and caching various entities.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class Context
|
public sealed partial class Context
|
||||||
{
|
{
|
||||||
readonly Dictionary<object, Label> ids = new Dictionary<object, Label>();
|
readonly Dictionary<object, Label> ids = new Dictionary<object, Label>();
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace Semmle.Extraction.PDB
|
||||||
///
|
///
|
||||||
/// PDB information can be in a separate PDB file, or embedded in the DLL.
|
/// PDB information can be in a separate PDB file, or embedded in the DLL.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class MetadataPdbReader : IPdb
|
sealed class MetadataPdbReader : IPdb
|
||||||
{
|
{
|
||||||
class SourceFile : ISourceFile
|
class SourceFile : ISourceFile
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace Semmle.Extraction.PDB
|
||||||
/// A PDB reader using Microsoft.DiaSymReader.Native.
|
/// A PDB reader using Microsoft.DiaSymReader.Native.
|
||||||
/// This is an unmanaged Windows DLL, which therefore only works on Windows.
|
/// This is an unmanaged Windows DLL, which therefore only works on Windows.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class NativePdbReader : IPdb
|
sealed class NativePdbReader : IPdb
|
||||||
{
|
{
|
||||||
sealed class Document : ISourceFile
|
sealed class Document : ISourceFile
|
||||||
{
|
{
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace Semmle.BuildAnalyser
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Main implementation of the build analysis.
|
/// Main implementation of the build analysis.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class BuildAnalysis : IBuildAnalysis, IDisposable
|
sealed class BuildAnalysis : IBuildAnalysis, IDisposable
|
||||||
{
|
{
|
||||||
private readonly AssemblyCache assemblyCache;
|
private readonly AssemblyCache assemblyCache;
|
||||||
private readonly IProgressMonitor progressMonitor;
|
private readonly IProgressMonitor progressMonitor;
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace Semmle.Extraction.CSharp.Standalone
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Searches for source/references and creates separate extractions.
|
/// Searches for source/references and creates separate extractions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class Analysis : IDisposable
|
sealed class Analysis : IDisposable
|
||||||
{
|
{
|
||||||
public Analysis(ILogger logger, Options options)
|
public Analysis(ILogger logger, Options options)
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace Semmle.Extraction.CSharp
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Encapsulates a C# analysis task.
|
/// Encapsulates a C# analysis task.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Analyser : IDisposable
|
public sealed class Analyser : IDisposable
|
||||||
{
|
{
|
||||||
IExtractor extractor;
|
IExtractor extractor;
|
||||||
|
|
||||||
|
|
|
@ -199,7 +199,7 @@ namespace Semmle.Extraction.Tests
|
||||||
new Semmle.Extraction.Layout(null, null, "layout.txt"));
|
new Semmle.Extraction.Layout(null, null, "layout.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoggerMock : ILogger
|
sealed class LoggerMock : ILogger
|
||||||
{
|
{
|
||||||
public void Dispose() { }
|
public void Dispose() { }
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ namespace Semmle.Extraction.Tests
|
||||||
Assert.Equal(@"C:\Temp\source_archive\diskstation\share\source\def.cs", TrapWriter.NestPaths(logger, @"C:\Temp\source_archive", $@"{root3}{root3}diskstation\share\source\def.cs").Replace('/', '\\'));
|
Assert.Equal(@"C:\Temp\source_archive\diskstation\share\source\def.cs", TrapWriter.NestPaths(logger, @"C:\Temp\source_archive", $@"{root3}{root3}diskstation\share\source\def.cs").Replace('/', '\\'));
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoggerMock : ILogger
|
sealed class LoggerMock : ILogger
|
||||||
{
|
{
|
||||||
public void Dispose() { }
|
public void Dispose() { }
|
||||||
|
|
||||||
|
|
|
@ -283,7 +283,7 @@ namespace Semmle.Extraction
|
||||||
|
|
||||||
public IDisposable StackGuard => new ScopeGuard(this);
|
public IDisposable StackGuard => new ScopeGuard(this);
|
||||||
|
|
||||||
private class ScopeGuard : IDisposable
|
private sealed class ScopeGuard : IDisposable
|
||||||
{
|
{
|
||||||
readonly Context cx;
|
readonly Context cx;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ using System;
|
||||||
|
|
||||||
namespace SemmleTests.Semmle.Util
|
namespace SemmleTests.Semmle.Util
|
||||||
{
|
{
|
||||||
public class CanonicalPathCacheTest : IDisposable
|
public sealed class CanonicalPathCacheTest : IDisposable
|
||||||
{
|
{
|
||||||
readonly ILogger Logger = new LoggerMock();
|
readonly ILogger Logger = new LoggerMock();
|
||||||
readonly string root;
|
readonly string root;
|
||||||
|
@ -24,9 +24,10 @@ namespace SemmleTests.Semmle.Util
|
||||||
root = Win32.IsWindows() ? @"X:\" : "/";
|
root = Win32.IsWindows() ? @"X:\" : "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
void IDisposable.Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
File.Delete("abc");
|
File.Delete("abc");
|
||||||
|
Logger.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -172,7 +173,7 @@ namespace SemmleTests.Semmle.Util
|
||||||
CanonicalPathDots();
|
CanonicalPathDots();
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoggerMock : ILogger
|
sealed class LoggerMock : ILogger
|
||||||
{
|
{
|
||||||
public void Dispose() { }
|
public void Dispose() { }
|
||||||
|
|
||||||
|
|
|
@ -10,20 +10,20 @@ namespace SemmleTests.Semmle.Util
|
||||||
/// Ensure that the Extractor works with long paths.
|
/// Ensure that the Extractor works with long paths.
|
||||||
/// These should be handled by .NET Core.
|
/// These should be handled by .NET Core.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class LongPaths : IDisposable
|
public sealed class LongPaths : IDisposable
|
||||||
{
|
{
|
||||||
static readonly string tmpDir = Path.GetTempPath();
|
static readonly string tmpDir = Path.GetTempPath();
|
||||||
static readonly string shortPath = Path.Combine(tmpDir, "test.txt");
|
static readonly string shortPath = Path.Combine(tmpDir, "test.txt");
|
||||||
static readonly string longPath = Path.Combine(tmpDir, "aaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
static readonly string longPath = Path.Combine(tmpDir, "aaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
||||||
"ccccccccccccccccccccccccccccccc", "ddddddddddddddddddddddddddddddddddddd", "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", "fffffffffffffffffffffffffffffffff",
|
"ccccccccccccccccccccccccccccccc", "ddddddddddddddddddddddddddddddddddddd", "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", "fffffffffffffffffffffffffffffffff",
|
||||||
"ggggggggggggggggggggggggggggggggggg","hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh","iiiiiiiiiiiiiiii.txt");
|
"ggggggggggggggggggggggggggggggggggg", "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", "iiiiiiiiiiiiiiii.txt");
|
||||||
|
|
||||||
public LongPaths()
|
public LongPaths()
|
||||||
{
|
{
|
||||||
CleanUp();
|
CleanUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IDisposable.Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
CleanUp();
|
CleanUp();
|
||||||
}
|
}
|
||||||
|
@ -34,14 +34,14 @@ namespace SemmleTests.Semmle.Util
|
||||||
{
|
{
|
||||||
File.Delete(shortPath);
|
File.Delete(shortPath);
|
||||||
}
|
}
|
||||||
catch(DirectoryNotFoundException)
|
catch (DirectoryNotFoundException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.Delete(longPath);
|
File.Delete(longPath);
|
||||||
}
|
}
|
||||||
catch(DirectoryNotFoundException)
|
catch (DirectoryNotFoundException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ namespace Semmle.Util.Logging
|
||||||
/// A logger that outputs to a <code>csharp.log</code>
|
/// A logger that outputs to a <code>csharp.log</code>
|
||||||
/// file.
|
/// file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class FileLogger : ILogger
|
public sealed class FileLogger : ILogger
|
||||||
{
|
{
|
||||||
readonly StreamWriter writer;
|
readonly StreamWriter writer;
|
||||||
readonly Verbosity verbosity;
|
readonly Verbosity verbosity;
|
||||||
|
@ -100,7 +100,7 @@ namespace Semmle.Util.Logging
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A logger that outputs to stdout/stderr.
|
/// A logger that outputs to stdout/stderr.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ConsoleLogger : ILogger
|
public sealed class ConsoleLogger : ILogger
|
||||||
{
|
{
|
||||||
readonly Verbosity verbosity;
|
readonly Verbosity verbosity;
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ namespace Semmle.Util.Logging
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A combined logger.
|
/// A combined logger.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CombinedLogger : ILogger
|
public sealed class CombinedLogger : ILogger
|
||||||
{
|
{
|
||||||
readonly ILogger logger1;
|
readonly ILogger logger1;
|
||||||
readonly ILogger logger2;
|
readonly ILogger logger2;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче