Skip to content

Commit 061b3a8

Browse files
committed
Massive refactor, new class names, a decent amount of working generation
1 parent 5be304e commit 061b3a8

32 files changed

+387
-285
lines changed

codehelp/CodeHelpers.Test/LogGenerator/EpilogueLogGeneratorTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class EpilogueGeneratorTest
1717
public async Task TestPrimitives(string type, string output)
1818
{
1919
string testString = @"
20-
using Epilogue;
20+
using WPILib.Logging;
2121
2222
[Logged]
2323
public partial class MyNewClass

codehelp/CodeHelpers/EpilogueGenerator/CustomLoggerType.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace WPILib.CodeHelpers.EpilogueGenerator;
55

6-
public record CustomLoggerType(TypeDeclarationModel TypeDeclarations, EquatableArray<TypeDeclarationModel> SupportedTypes);
6+
public record CustomLoggerType(TypeDeclarationModel TypeDeclaration, EquatableArray<TypeDeclarationModel> SupportedTypes);
77

88
internal static class CustomLoggerTypeExtensions
99
{

codehelp/CodeHelpers/EpilogueGenerator/LogAttributeInfo.cs

+29-44
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
using System.Collections.Immutable;
2+
using System.Diagnostics;
23
using System.Text;
3-
using Epilogue;
44
using Microsoft.CodeAnalysis;
55
using Microsoft.CodeAnalysis.CSharp;
66
using Microsoft.CodeAnalysis.PooledObjects;
7+
using WPILib.Logging;
78

89
namespace WPILib.CodeHelpers.EpilogueGenerator;
910

@@ -173,57 +174,41 @@ public record LogAttributeInfo(string? Name, LogStrategy LogStrategy, LogImporta
173174

174175
internal static class LogAttributeInfoExtensions
175176
{
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)
177178
{
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);
183181

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();
193183

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;
197187

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")
200193
{
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)
210195
{
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);
220197
}
221198
}
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+
}
224209
}
225-
return null;
226-
}
227-
228210

211+
token.ThrowIfCancellationRequested();
212+
return new LogAttributeInfo(path, logStrategyEnum, logImportanceEnum);
213+
}
229214
}

0 commit comments

Comments
 (0)