|
1 | 1 | using System.Collections.Immutable;
|
| 2 | +using System.Diagnostics; |
2 | 3 | using System.Text;
|
3 |
| -using Epilogue; |
4 | 4 | using Microsoft.CodeAnalysis;
|
5 | 5 | using Microsoft.CodeAnalysis.CSharp;
|
6 | 6 | using Microsoft.CodeAnalysis.PooledObjects;
|
| 7 | +using WPILib.Logging; |
7 | 8 |
|
8 | 9 | namespace WPILib.CodeHelpers.EpilogueGenerator;
|
9 | 10 |
|
@@ -173,57 +174,41 @@ public record LogAttributeInfo(string? Name, LogStrategy LogStrategy, LogImporta
|
173 | 174 |
|
174 | 175 | internal static class LogAttributeInfoExtensions
|
175 | 176 | {
|
176 |
| - public static LogAttributeInfo? ToAttributeInfo(this AttributeData attributeData, INamedTypeSymbol? attributeClass, CancellationToken token, out bool notLogged) |
| 177 | + public static LogAttributeInfo ToAttributeInfo(this AttributeData attributeData, CancellationToken token) |
177 | 178 | {
|
178 |
| - if (attributeClass is null) |
179 |
| - { |
180 |
| - notLogged = false; |
181 |
| - return null; |
182 |
| - } |
| 179 | + // At this point, we're guaranteed its a logged attribute |
| 180 | + Debug.Assert(attributeData.AttributeClass?.IsLoggedAttributeClass() ?? false); |
183 | 181 |
|
184 |
| - if (attributeClass.IsNotLoggedAttributeClass()) |
185 |
| - { |
186 |
| - notLogged = true; |
187 |
| - return null; |
188 |
| - } |
189 |
| - notLogged = false; |
190 |
| - if (attributeClass.IsLoggedAttributeClass()) |
191 |
| - { |
192 |
| - token.ThrowIfCancellationRequested(); |
| 182 | + token.ThrowIfCancellationRequested(); |
193 | 183 |
|
194 |
| - string? path = null; |
195 |
| - LogStrategy logStrategyEnum = LogStrategyExtensions.DefaultLogStrategy; |
196 |
| - LogImportance logImportanceEnum = LogImportanceExtensions.DefaultLogImportance; |
| 184 | + string? path = null; |
| 185 | + LogStrategy logStrategyEnum = LogStrategyExtensions.DefaultLogStrategy; |
| 186 | + LogImportance logImportanceEnum = LogImportanceExtensions.DefaultLogImportance; |
197 | 187 |
|
198 |
| - // Get the log attribute |
199 |
| - foreach (var named in attributeData.NamedArguments) |
| 188 | + // Get the log attribute |
| 189 | + foreach (var named in attributeData.NamedArguments) |
| 190 | + { |
| 191 | + token.ThrowIfCancellationRequested(); |
| 192 | + if (named.Key == "Name") |
200 | 193 | {
|
201 |
| - if (named.Key == "Name") |
202 |
| - { |
203 |
| - if (!named.Value.IsNull) |
204 |
| - { |
205 |
| - path = SymbolDisplay.FormatPrimitive(named.Value.Value!, false, false); |
206 |
| - } |
207 |
| - token.ThrowIfCancellationRequested(); |
208 |
| - } |
209 |
| - else if (named.Key == "Strategy") |
| 194 | + if (!named.Value.IsNull) |
210 | 195 | {
|
211 |
| - // A boxed primitive can be unboxed to an enum with the same underlying type. |
212 |
| - logStrategyEnum = (LogStrategy)named.Value.Value!; |
213 |
| - token.ThrowIfCancellationRequested(); |
214 |
| - } |
215 |
| - else if (named.Key == "Importance") |
216 |
| - { |
217 |
| - // A boxed primitive can be unboxed to an enum with the same underlying type. |
218 |
| - logImportanceEnum = (LogImportance)named.Value.Value!; |
219 |
| - token.ThrowIfCancellationRequested(); |
| 196 | + path = SymbolDisplay.FormatPrimitive(named.Value.Value!, false, false); |
220 | 197 | }
|
221 | 198 | }
|
222 |
| - |
223 |
| - return new LogAttributeInfo(path, logStrategyEnum, logImportanceEnum); |
| 199 | + else if (named.Key == "Strategy") |
| 200 | + { |
| 201 | + // A boxed primitive can be unboxed to an enum with the same underlying type. |
| 202 | + logStrategyEnum = (LogStrategy)named.Value.Value!; |
| 203 | + } |
| 204 | + else if (named.Key == "Importance") |
| 205 | + { |
| 206 | + // A boxed primitive can be unboxed to an enum with the same underlying type. |
| 207 | + logImportanceEnum = (LogImportance)named.Value.Value!; |
| 208 | + } |
224 | 209 | }
|
225 |
| - return null; |
226 |
| - } |
227 |
| - |
228 | 210 |
|
| 211 | + token.ThrowIfCancellationRequested(); |
| 212 | + return new LogAttributeInfo(path, logStrategyEnum, logImportanceEnum); |
| 213 | + } |
229 | 214 | }
|
0 commit comments