Skip to content

Commit 4f897b2

Browse files
committed
C#: Address review comments
1 parent 8f3f940 commit 4f897b2

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Analyser.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,40 +36,40 @@ public Analyser(IProgressMonitor pm, ILogger logger)
3636
CSharpCompilation compilation;
3737
Layout layout;
3838

39+
private bool init;
3940
/// <summary>
40-
/// Initialize the analyser.
41+
/// Start initialization of the analyser.
4142
/// </summary>
42-
/// <param name="commandLineArguments">Arguments passed to csc.</param>
43-
/// <param name="options">Extractor options.</param>
4443
/// <param name="roslynArgs">The arguments passed to Roslyn.</param>
45-
/// <param name="finalizeInit">A continuation for finalizing initialization based on a Roslyn compilation.</param>
4644
/// <returns>A Boolean indicating whether to proceed with extraction.</returns>
47-
public bool Initialize(
48-
CSharpCommandLineArguments commandLineArguments,
49-
Options options,
50-
string[] roslynArgs,
51-
out Action<CSharpCompilation> finalizeInit)
45+
public bool BeginInitialize(string[] roslynArgs)
5246
{
53-
if (!LogRoslynArgs(roslynArgs, Extraction.Extractor.Version))
54-
{
55-
finalizeInit = null;
56-
return false;
57-
}
47+
return init = LogRoslynArgs(roslynArgs, Extraction.Extractor.Version);
48+
}
5849

50+
/// <summary>
51+
/// End initialization of the analyser.
52+
/// </summary>
53+
/// <param name="commandLineArguments">Arguments passed to csc.</param>
54+
/// <param name="options">Extractor options.</param>
55+
/// <param name="compilation">The Roslyn compilation.</param>
56+
/// <returns>A Boolean indicating whether to proceed with extraction.</returns>
57+
public void EndInitialize(
58+
CSharpCommandLineArguments commandLineArguments,
59+
Options options,
60+
CSharpCompilation compilation)
61+
{
62+
if (!init)
63+
throw new InternalError("EndInitialize called without BeginInitialize returning true");
5964
layout = new Layout();
6065
this.options = options;
66+
this.compilation = compilation;
67+
extractor = new Extraction.Extractor(false, GetOutputName(compilation, commandLineArguments), Logger);
68+
LogDiagnostics();
6169

62-
finalizeInit = comp =>
63-
{
64-
compilation = comp;
65-
extractor = new Extraction.Extractor(false, GetOutputName(comp, commandLineArguments), Logger);
66-
LogDiagnostics();
67-
68-
SetReferencePaths();
70+
SetReferencePaths();
6971

70-
CompilationErrors += FilteredDiagnostics.Count();
71-
};
72-
return true;
72+
CompilationErrors += FilteredDiagnostics.Count();
7373
}
7474

7575
/// <summary>
@@ -444,7 +444,7 @@ public void LogExtractorInfo(string extractorVersion)
444444
/// Logs information about the extractor, as well as the arguments to Roslyn.
445445
/// </summary>
446446
/// <param name="roslynArgs">The arguments passed to Roslyn.</param>
447-
/// <returns>A Boolean indicating whether to proceed with extraction.</returns>
447+
/// <returns>A Boolean indicating whether the same arguments have been logged previously.</returns>
448448
public bool LogRoslynArgs(string[] roslynArgs, string extractorVersion)
449449
{
450450
LogExtractorInfo(extractorVersion);
@@ -456,7 +456,7 @@ public bool LogRoslynArgs(string[] roslynArgs, string extractorVersion)
456456
bool argsWritten;
457457
using (var streamWriter = new StreamWriter(new FileStream(tempFile, FileMode.Append, FileAccess.Write)))
458458
{
459-
streamWriter.WriteLine($"Arguments to Roslyn: {string.Join(' ', roslynArgs)}");
459+
streamWriter.WriteLine($"# Arguments to Roslyn: {string.Join(' ', roslynArgs)}");
460460
argsWritten = roslynArgs.WriteCommandLine(streamWriter);
461461
}
462462

csharp/extractor/Semmle.Extraction.CSharp/Extractor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public static ExitCode Run(string[] args)
109109
return ExitCode.Failed;
110110
}
111111

112-
if (!analyser.Initialize(compilerArguments, commandLineArguments, compilerVersion.ArgsWithResponse, out var finalizeInit))
112+
if (!analyser.BeginInitialize(compilerVersion.ArgsWithResponse))
113113
{
114114
logger.Log(Severity.Info, "Skipping extraction since files have already been extracted");
115115
return ExitCode.Ok;
@@ -154,7 +154,7 @@ public static ExitCode Run(string[] args)
154154
// already.
155155
);
156156

157-
finalizeInit(compilation);
157+
analyser.EndInitialize(compilerArguments, commandLineArguments, compilation);
158158
analyser.AnalyseCompilation(cwd, args);
159159
analyser.AnalyseReferences();
160160

0 commit comments

Comments
 (0)