mirror of
https://github.com/github/codeql.git
synced 2026-04-25 16:55:19 +02:00
Move TSP diagnostics related classes to separate files
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
@@ -179,64 +178,4 @@ namespace Semmle.Util
|
||||
this.PlaintextMessage = plaintextMessage;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides the ability to write diagnostic messages to some output.
|
||||
/// </summary>
|
||||
public interface IDiagnosticsWriter : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds <paramref name="message" /> as a new diagnostics entry.
|
||||
/// </summary>
|
||||
/// <param name="message">The diagnostics entry to add.</param>
|
||||
void AddEntry(DiagnosticMessage message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A wrapper around an underlying <see cref="StreamWriter" /> which allows
|
||||
/// <see cref="DiagnosticMessage" /> objects to be serialized to it.
|
||||
/// </summary>
|
||||
public sealed class DiagnosticsStream : IDiagnosticsWriter, IDisposable
|
||||
{
|
||||
private readonly JsonSerializer serializer;
|
||||
private readonly StreamWriter writer;
|
||||
|
||||
/// <summary>
|
||||
/// Initialises a new <see cref="DiagnosticsStream" /> for a file at <paramref name="path" />.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the file that should be created.</param>
|
||||
public DiagnosticsStream(string path)
|
||||
{
|
||||
this.writer = File.CreateText(path);
|
||||
|
||||
var contractResolver = new DefaultContractResolver
|
||||
{
|
||||
NamingStrategy = new CamelCaseNamingStrategy()
|
||||
};
|
||||
|
||||
serializer = new JsonSerializer
|
||||
{
|
||||
ContractResolver = contractResolver,
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds <paramref name="message" /> as a new diagnostics entry.
|
||||
/// </summary>
|
||||
/// <param name="message">The diagnostics entry to add.</param>
|
||||
public void AddEntry(DiagnosticMessage message)
|
||||
{
|
||||
serializer.Serialize(writer, message);
|
||||
writer.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases all resources used by the <see cref="DiagnosticsStream" /> object.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
writer.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace Semmle.Util
|
||||
{
|
||||
/// <summary>
|
||||
/// A wrapper around an underlying <see cref="StreamWriter" /> which allows
|
||||
/// <see cref="DiagnosticMessage" /> objects to be serialized to it.
|
||||
/// </summary>
|
||||
public sealed class DiagnosticsStream : IDiagnosticsWriter, IDisposable
|
||||
{
|
||||
private readonly JsonSerializer serializer;
|
||||
private readonly StreamWriter writer;
|
||||
|
||||
/// <summary>
|
||||
/// Initialises a new <see cref="DiagnosticsStream" /> for a file at <paramref name="path" />.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the file that should be created.</param>
|
||||
public DiagnosticsStream(string path)
|
||||
{
|
||||
this.writer = File.CreateText(path);
|
||||
|
||||
var contractResolver = new DefaultContractResolver
|
||||
{
|
||||
NamingStrategy = new CamelCaseNamingStrategy()
|
||||
};
|
||||
|
||||
serializer = new JsonSerializer
|
||||
{
|
||||
ContractResolver = contractResolver,
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds <paramref name="message" /> as a new diagnostics entry.
|
||||
/// </summary>
|
||||
/// <param name="message">The diagnostics entry to add.</param>
|
||||
public void AddEntry(DiagnosticMessage message)
|
||||
{
|
||||
serializer.Serialize(writer, message);
|
||||
writer.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases all resources used by the <see cref="DiagnosticsStream" /> object.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
writer.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace Semmle.Util
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides the ability to write diagnostic messages to some output.
|
||||
/// </summary>
|
||||
public interface IDiagnosticsWriter : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds <paramref name="message" /> as a new diagnostics entry.
|
||||
/// </summary>
|
||||
/// <param name="message">The diagnostics entry to add.</param>
|
||||
void AddEntry(DiagnosticMessage message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user