Skip to content

Commit cdca607

Browse files
committed
Rename Extractor to ExtractionContext
1 parent af2a78e commit cdca607

File tree

17 files changed

+40
-40
lines changed

17 files changed

+40
-40
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/Assembly.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ private Assembly(Context cx, Microsoft.CodeAnalysis.Location? init)
1717
isOutputAssembly = init is null;
1818
if (isOutputAssembly)
1919
{
20-
assemblyPath = cx.Extractor.OutputPath;
20+
assemblyPath = cx.ExtractionContext.OutputPath;
2121
assembly = cx.Compilation.Assembly;
2222
}
2323
else
2424
{
2525
assembly = init!.MetadataModule!.ContainingAssembly;
2626
var identity = assembly.Identity;
2727
var idString = identity.Name + " " + identity.Version;
28-
assemblyPath = cx.Extractor.GetAssemblyFile(idString);
28+
assemblyPath = cx.ExtractionContext.GetAssemblyFile(idString);
2929
}
3030
}
3131

3232
public override void Populate(TextWriter trapFile)
3333
{
3434
if (assemblyPath is not null)
3535
{
36-
var isBuildlessOutputAssembly = isOutputAssembly && Context.Extractor.Mode.HasFlag(ExtractorMode.Standalone);
36+
var isBuildlessOutputAssembly = isOutputAssembly && Context.ExtractionContext.Mode.HasFlag(ExtractorMode.Standalone);
3737
var identifier = isBuildlessOutputAssembly
3838
? ""
3939
: assembly.ToString() ?? "";
@@ -74,7 +74,7 @@ public static Assembly CreateOutputAssembly(Context cx)
7474

7575
public override void WriteId(EscapingTextWriter trapFile)
7676
{
77-
if (isOutputAssembly && Context.Extractor.Mode.HasFlag(ExtractorMode.Standalone))
77+
if (isOutputAssembly && Context.ExtractionContext.Mode.HasFlag(ExtractorMode.Standalone))
7878
{
7979
trapFile.Write("buildlessOutputAssembly");
8080
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/Compilations/Compilation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ internal class Compilation : CachedEntity<object>
1818
#nullable disable warnings
1919
private Compilation(Context cx) : base(cx, null)
2020
{
21-
cwd = cx.Extractor.Cwd;
22-
args = cx.Extractor.Args;
21+
cwd = cx.ExtractionContext.Cwd;
22+
args = cx.ExtractionContext.Args;
2323
hashCode = cwd.GetHashCode();
2424
for (var i = 0; i < args.Length; i++)
2525
{

csharp/extractor/Semmle.Extraction.CSharp/Entities/Compilations/CompilerDiagnostic.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected override void Populate(TextWriter trapFile)
2828
{
2929
if (messageCount == limit + 1)
3030
{
31-
Context.Extractor.Logger.LogWarning($"Stopped logging {key} compiler diagnostics for the current compilation after reaching {limit}");
31+
Context.ExtractionContext.Logger.LogWarning($"Stopped logging {key} compiler diagnostics for the current compilation after reaching {limit}");
3232
}
3333

3434
return;

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Invocation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public IMethodSymbol? TargetSymbol
133133
.Where(method => method.Parameters.Length >= Syntax.ArgumentList.Arguments.Count)
134134
.Where(method => method.Parameters.Count(p => !p.HasExplicitDefaultValue) <= Syntax.ArgumentList.Arguments.Count);
135135

136-
return Context.Extractor.Mode.HasFlag(ExtractorMode.Standalone) ?
136+
return Context.ExtractionContext.Mode.HasFlag(ExtractorMode.Standalone) ?
137137
candidates.FirstOrDefault() :
138138
candidates.SingleOrDefault();
139139
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/File.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public override void Populate(TextWriter trapFile)
6161
}
6262
}
6363

64-
trapFile.file_extraction_mode(this, Context.Extractor.Mode);
64+
trapFile.file_extraction_mode(this, Context.ExtractionContext.Mode);
6565
}
6666

6767
private bool IsPossiblyTextFile()

csharp/extractor/Semmle.Extraction.CSharp/Entities/OrdinaryMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Symbol.ContainingType is INamedTypeSymbol nt &&
6363
{
6464
if (method.MethodKind == MethodKind.ReducedExtension)
6565
{
66-
cx.Extractor.Logger.Log(Semmle.Util.Logging.Severity.Warning, "Reduced extension method symbols should not be directly extracted.");
66+
cx.ExtractionContext.Logger.Log(Semmle.Util.Logging.Severity.Warning, "Reduced extension method symbols should not be directly extracted.");
6767
}
6868

6969
return OrdinaryMethodFactory.Instance.CreateEntityFromSymbol(cx, method);

csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/NamedType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public override void Populate(TextWriter trapFile)
3636
if (Symbol.TypeKind == TypeKind.Error)
3737
{
3838
UnknownType.Create(Context); // make sure this exists so we can use it in `TypeRef::getReferencedType`
39-
Context.Extractor.MissingType(Symbol.ToString()!, Context.FromSource);
39+
Context.ExtractionContext.MissingType(Symbol.ToString()!, Context.FromSource);
4040
return;
4141
}
4242

csharp/extractor/Semmle.Extraction.CSharp/Entities/UsingDirective.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected override void Populate(TextWriter trapFile)
3636
}
3737
else
3838
{
39-
Context.Extractor.MissingNamespace(name.ToFullString(), Context.FromSource);
39+
Context.ExtractionContext.MissingNamespace(name.ToFullString(), Context.FromSource);
4040
Context.ModelError(node, "Namespace not found");
4141
return;
4242
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Semmle.Extraction.CSharp
1919
/// </summary>
2020
public class Analyser : IDisposable
2121
{
22-
protected Extraction.Extractor? extractor;
22+
protected ExtractionContext? ExtractionContext;
2323
protected CSharpCompilation? compilation;
2424
protected CommonOptions? options;
2525
private protected Entities.Compilation? compilationEntity;
@@ -108,12 +108,12 @@ protected void SetReferencePaths()
108108
var def = reader.GetAssemblyDefinition();
109109
assemblyIdentity = reader.GetString(def.Name) + " " + def.Version;
110110
}
111-
extractor.SetAssemblyFile(assemblyIdentity, refPath);
111+
ExtractionContext.SetAssemblyFile(assemblyIdentity, refPath);
112112

113113
}
114114
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
115115
{
116-
extractor.Message(new Message("Exception reading reference file", reference.FilePath, null, ex.StackTrace));
116+
ExtractionContext.Message(new Message("Exception reading reference file", reference.FilePath, null, ex.StackTrace));
117117
}
118118
}
119119
}
@@ -158,7 +158,7 @@ private void DoAnalyseReferenceAssembly(PortableExecutableReference r)
158158

159159
if (compilation.GetAssemblyOrModuleSymbol(r) is IAssemblySymbol assembly)
160160
{
161-
var cx = new Context(extractor, compilation, trapWriter, new AssemblyScope(assembly, assemblyPath), addAssemblyTrapPrefix);
161+
var cx = new Context(ExtractionContext, compilation, trapWriter, new AssemblyScope(assembly, assemblyPath), addAssemblyTrapPrefix);
162162

163163
foreach (var module in assembly.Modules)
164164
{
@@ -201,7 +201,7 @@ private void DoExtractTree(SyntaxTree tree)
201201

202202
if (!upToDate)
203203
{
204-
var cx = new Context(extractor, compilation, trapWriter, new SourceScope(tree), addAssemblyTrapPrefix);
204+
var cx = new Context(ExtractionContext, compilation, trapWriter, new SourceScope(tree), addAssemblyTrapPrefix);
205205
// Ensure that the file itself is populated in case the source file is totally empty
206206
var root = tree.GetRoot();
207207
Entities.File.Create(cx, root.SyntaxTree.FilePath);
@@ -223,15 +223,15 @@ private void DoExtractTree(SyntaxTree tree)
223223
}
224224
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
225225
{
226-
extractor.Message(new Message($"Unhandled exception processing syntax tree. {ex.Message}", tree.FilePath, null, ex.StackTrace));
226+
ExtractionContext.Message(new Message($"Unhandled exception processing syntax tree. {ex.Message}", tree.FilePath, null, ex.StackTrace));
227227
}
228228
}
229229

230230
private void DoAnalyseCompilation()
231231
{
232232
try
233233
{
234-
var assemblyPath = extractor.OutputPath;
234+
var assemblyPath = ExtractionContext.OutputPath;
235235
var stopwatch = new Stopwatch();
236236
stopwatch.Start();
237237
var currentTaskId = IncrementTaskCount();
@@ -241,11 +241,11 @@ private void DoAnalyseCompilation()
241241
var assembly = compilation.Assembly;
242242
var trapWriter = transformedAssemblyPath.CreateTrapWriter(Logger, options.TrapCompression, discardDuplicates: false);
243243
compilationTrapFile = trapWriter; // Dispose later
244-
var cx = new Context(extractor, compilation, trapWriter, new AssemblyScope(assembly, assemblyPath), addAssemblyTrapPrefix);
244+
var cx = new Context(ExtractionContext, compilation, trapWriter, new AssemblyScope(assembly, assemblyPath), addAssemblyTrapPrefix);
245245

246246
compilationEntity = Entities.Compilation.Create(cx);
247247

248-
extractor.CompilationInfos.ForEach(ci => trapWriter.Writer.compilation_info(compilationEntity, ci.key, ci.value));
248+
ExtractionContext.CompilationInfos.ForEach(ci => trapWriter.Writer.compilation_info(compilationEntity, ci.key, ci.value));
249249

250250
ReportProgressTaskDone(currentTaskId, assemblyPath, trapWriter.TrapFile, stopwatch.Elapsed, AnalysisAction.Extracted);
251251
}
@@ -328,7 +328,7 @@ public virtual void Dispose()
328328
/// <summary>
329329
/// Number of errors encountered during extraction.
330330
/// </summary>
331-
private int ExtractorErrors => extractor?.Errors ?? 0;
331+
private int ExtractorErrors => ExtractionContext?.Errors ?? 0;
332332

333333
/// <summary>
334334
/// Number of errors encountered by the compiler.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ internal void CacheLambdaParameterSymbol(IParameterSymbol param, SyntaxNode synt
7777

7878
internal CommentProcessor CommentGenerator { get; } = new CommentProcessor();
7979

80-
public Context(Extraction.Extractor e, Compilation c, TrapWriter trapWriter, IExtractionScope scope, bool addAssemblyTrapPrefix)
80+
public Context(ExtractionContext e, Compilation c, TrapWriter trapWriter, IExtractionScope scope, bool addAssemblyTrapPrefix)
8181
: base(e, trapWriter, addAssemblyTrapPrefix)
8282
{
8383
Compilation = c;
@@ -187,13 +187,13 @@ public string TryAdjustRelativeMappedFilePath(string mappedToPath, string mapped
187187
try
188188
{
189189
var fullPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(mappedFromPath)!, mappedToPath));
190-
Extractor.Logger.LogDebug($"Found relative path in line mapping: '{mappedToPath}', interpreting it as '{fullPath}'");
190+
ExtractionContext.Logger.LogDebug($"Found relative path in line mapping: '{mappedToPath}', interpreting it as '{fullPath}'");
191191

192192
mappedToPath = fullPath;
193193
}
194194
catch (Exception e)
195195
{
196-
Extractor.Logger.LogDebug($"Failed to compute absolute path for relative path in line mapping: '{mappedToPath}': {e}");
196+
ExtractionContext.Logger.LogDebug($"Failed to compute absolute path for relative path in line mapping: '{mappedToPath}': {e}");
197197
}
198198
}
199199

0 commit comments

Comments
 (0)