|
8 | 8 |
|
9 | 9 | namespace Arch.Bus; |
10 | 10 |
|
| 11 | +/// <summary> |
| 12 | +/// Query generator. |
| 13 | +/// </summary> |
11 | 14 | [Generator] |
12 | 15 | public class QueryGenerator : IIncrementalGenerator |
13 | 16 | { |
14 | 17 | private static EventBus _eventBus; |
15 | 18 | private static Hooks _hooks; |
16 | 19 |
|
17 | | - private static Dictionary<ITypeSymbol, (RefKind, IList<ReceivingMethod>)> _eventTypeToReceivingMethods; |
18 | | - private static Dictionary<ITypeSymbol, IList<EventHook>> _containingTypeToReceivingMethods; |
| 20 | + private static Dictionary<ITypeSymbol, (RefKind, IList<ReceivingMethod>)> _eventTypeToReceivingMethods = null!; |
| 21 | + private static Dictionary<ITypeSymbol, IList<EventHook>> _containingTypeToReceivingMethods = null!; |
19 | 22 |
|
| 23 | + /// <inheritdoc cref="IIncrementalGenerator.Initialize"/> |
20 | 24 | public void Initialize(IncrementalGeneratorInitializationContext context) |
21 | 25 | { |
22 | 26 | //if (!Debugger.IsAttached) Debugger.Launch(); |
@@ -59,7 +63,7 @@ public EventAttribute(int order = 0) |
59 | 63 |
|
60 | 64 |
|
61 | 65 | /// <summary> |
62 | | - /// Returns a <see cref="MethodDeclarationSyntax"/> if its annocated with a attribute of <see cref="name"/>. |
| 66 | + /// Returns a <see cref="MethodDeclarationSyntax"/> if its annotated with an attribute of <paramref name="name"/>. |
63 | 67 | /// </summary> |
64 | 68 | /// <param name="context">Its <see cref="GeneratorSyntaxContext"/>.</param> |
65 | 69 | /// <param name="name">The attributes name.</param> |
@@ -97,7 +101,7 @@ private static void MapMethodToEventType(IMethodSymbol methodSymbol) |
97 | 101 | { |
98 | 102 | var eventType = methodSymbol.Parameters[0]; |
99 | 103 | var param = methodSymbol.GetAttributes()[0].ConstructorArguments[0]; |
100 | | - var receivingMethod = new ReceivingMethod{ Static = methodSymbol.IsStatic, MethodSymbol = methodSymbol, Order = (int)param.Value }; |
| 104 | + var receivingMethod = new ReceivingMethod{ Static = methodSymbol.IsStatic, MethodSymbol = methodSymbol, Order = (int)param.Value! }; |
101 | 105 |
|
102 | 106 | // Either append or create a new receiving method with a new list. |
103 | 107 | if (_eventTypeToReceivingMethods.TryGetValue(eventType.Type, out var tuple)) |
@@ -189,19 +193,19 @@ private static void Generate(Compilation compilation, ImmutableArray<MethodDecla |
189 | 193 | // Init |
190 | 194 | _eventBus.Namespace = "Arch.Bus"; |
191 | 195 | _eventBus.Methods = new List<Method>(512); |
192 | | - _eventTypeToReceivingMethods = new Dictionary<ITypeSymbol, (RefKind, IList<ReceivingMethod>)>(512); |
| 196 | + _eventTypeToReceivingMethods = new Dictionary<ITypeSymbol, (RefKind, IList<ReceivingMethod>)>(512, SymbolEqualityComparer.Default); |
193 | 197 |
|
194 | 198 | _hooks.Instances = new List<ClassHooks>(512); |
195 | | - _containingTypeToReceivingMethods = new Dictionary<ITypeSymbol, IList<EventHook>>(512); |
| 199 | + _containingTypeToReceivingMethods = new Dictionary<ITypeSymbol, IList<EventHook>>(512, SymbolEqualityComparer.Default); |
196 | 200 |
|
197 | 201 | // Generate Query methods and map them to their classes |
198 | 202 | foreach (var methodSyntax in methods) |
199 | 203 | { |
200 | 204 | var semanticModel = compilation.GetSemanticModel(methodSyntax.SyntaxTree); |
201 | 205 | var methodSymbol = ModelExtensions.GetDeclaredSymbol(semanticModel, methodSyntax) as IMethodSymbol; |
202 | 206 |
|
203 | | - MapMethodToEventType(methodSymbol); |
204 | | - MapMethodToContainingType(methodSymbol); |
| 207 | + MapMethodToEventType(methodSymbol!); |
| 208 | + MapMethodToContainingType(methodSymbol!); |
205 | 209 | } |
206 | 210 |
|
207 | 211 | PrepareEventBus(); |
|
0 commit comments