|
1 | | -using System; |
2 | 1 | using System.Collections.Concurrent; |
3 | 2 | using System.Collections.Generic; |
4 | 3 | using System.IO; |
5 | 4 | using System.Linq; |
6 | 5 | using System.Text; |
7 | 6 | using System.Threading.Tasks; |
| 7 | + |
8 | 8 | using Microsoft.CodeAnalysis; |
9 | 9 | using Microsoft.CodeAnalysis.CSharp; |
| 10 | + |
10 | 11 | using Semmle.Util; |
11 | 12 | using Semmle.Util.Logging; |
12 | 13 |
|
@@ -56,20 +57,18 @@ private static void StubReference(ILogger logger, CSharpCompilation compilation, |
56 | 57 | if (compilation.GetAssemblyOrModuleSymbol(reference) is not IAssemblySymbol assembly) |
57 | 58 | return; |
58 | 59 |
|
59 | | - Func<StreamWriter> makeWriter = () => |
60 | | - { |
61 | | - var fileStream = new FileStream(FileUtils.NestPaths(logger, outputPath, path.Replace(".dll", ".cs")), FileMode.Create, FileAccess.Write); |
62 | | - var writer = new StreamWriter(fileStream, new UTF8Encoding(false)); |
63 | | - return writer; |
64 | | - }; |
65 | | - |
66 | | - using var visitor = new StubVisitor(assembly, makeWriter); |
| 60 | + var relevantSymbol = new RelevantSymbol(assembly); |
67 | 61 |
|
68 | | - if (!assembly.Modules.Any(m => visitor.IsRelevantNamespace(m.GlobalNamespace))) |
| 62 | + if (!assembly.Modules.Any(m => relevantSymbol.IsRelevantNamespace(m.GlobalNamespace))) |
69 | 63 | return; |
70 | 64 |
|
71 | | - visitor.StubWriter.WriteLine("// This file contains auto-generated code."); |
72 | | - visitor.StubWriter.WriteLine($"// Generated from `{assembly.Identity}`."); |
| 65 | + using var fileStream = new FileStream(FileUtils.NestPaths(logger, outputPath, path.Replace(".dll", ".cs")), FileMode.Create, FileAccess.Write); |
| 66 | + using var writer = new StreamWriter(fileStream, new UTF8Encoding(false)); |
| 67 | + |
| 68 | + var visitor = new StubVisitor(writer, relevantSymbol); |
| 69 | + |
| 70 | + writer.WriteLine("// This file contains auto-generated code."); |
| 71 | + writer.WriteLine($"// Generated from `{assembly.Identity}`."); |
73 | 72 |
|
74 | 73 | visitor.StubAttributes(assembly.GetAttributes(), "assembly: "); |
75 | 74 |
|
|
0 commit comments