Skip to content

Commit

Permalink
Massive refactor, new class names, a decent amount of working generation
Browse files Browse the repository at this point in the history
  • Loading branch information
ThadHouse committed Aug 6, 2024
1 parent 5be304e commit 061b3a8
Show file tree
Hide file tree
Showing 32 changed files with 387 additions and 285 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class EpilogueGeneratorTest
public async Task TestPrimitives(string type, string output)
{
string testString = @"
using Epilogue;
using WPILib.Logging;
[Logged]
public partial class MyNewClass
Expand Down
2 changes: 1 addition & 1 deletion codehelp/CodeHelpers/EpilogueGenerator/CustomLoggerType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace WPILib.CodeHelpers.EpilogueGenerator;

public record CustomLoggerType(TypeDeclarationModel TypeDeclarations, EquatableArray<TypeDeclarationModel> SupportedTypes);
public record CustomLoggerType(TypeDeclarationModel TypeDeclaration, EquatableArray<TypeDeclarationModel> SupportedTypes);

internal static class CustomLoggerTypeExtensions
{
Expand Down
73 changes: 29 additions & 44 deletions codehelp/CodeHelpers/EpilogueGenerator/LogAttributeInfo.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System.Collections.Immutable;
using System.Diagnostics;
using System.Text;
using Epilogue;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.PooledObjects;
using WPILib.Logging;

namespace WPILib.CodeHelpers.EpilogueGenerator;

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

internal static class LogAttributeInfoExtensions
{
public static LogAttributeInfo? ToAttributeInfo(this AttributeData attributeData, INamedTypeSymbol? attributeClass, CancellationToken token, out bool notLogged)
public static LogAttributeInfo ToAttributeInfo(this AttributeData attributeData, CancellationToken token)
{
if (attributeClass is null)
{
notLogged = false;
return null;
}
// At this point, we're guaranteed its a logged attribute
Debug.Assert(attributeData.AttributeClass?.IsLoggedAttributeClass() ?? false);

if (attributeClass.IsNotLoggedAttributeClass())
{
notLogged = true;
return null;
}
notLogged = false;
if (attributeClass.IsLoggedAttributeClass())
{
token.ThrowIfCancellationRequested();
token.ThrowIfCancellationRequested();

string? path = null;
LogStrategy logStrategyEnum = LogStrategyExtensions.DefaultLogStrategy;
LogImportance logImportanceEnum = LogImportanceExtensions.DefaultLogImportance;
string? path = null;
LogStrategy logStrategyEnum = LogStrategyExtensions.DefaultLogStrategy;
LogImportance logImportanceEnum = LogImportanceExtensions.DefaultLogImportance;

// Get the log attribute
foreach (var named in attributeData.NamedArguments)
// Get the log attribute
foreach (var named in attributeData.NamedArguments)
{
token.ThrowIfCancellationRequested();
if (named.Key == "Name")
{
if (named.Key == "Name")
{
if (!named.Value.IsNull)
{
path = SymbolDisplay.FormatPrimitive(named.Value.Value!, false, false);
}
token.ThrowIfCancellationRequested();
}
else if (named.Key == "Strategy")
if (!named.Value.IsNull)
{
// A boxed primitive can be unboxed to an enum with the same underlying type.
logStrategyEnum = (LogStrategy)named.Value.Value!;
token.ThrowIfCancellationRequested();
}
else if (named.Key == "Importance")
{
// A boxed primitive can be unboxed to an enum with the same underlying type.
logImportanceEnum = (LogImportance)named.Value.Value!;
token.ThrowIfCancellationRequested();
path = SymbolDisplay.FormatPrimitive(named.Value.Value!, false, false);
}
}

return new LogAttributeInfo(path, logStrategyEnum, logImportanceEnum);
else if (named.Key == "Strategy")
{
// A boxed primitive can be unboxed to an enum with the same underlying type.
logStrategyEnum = (LogStrategy)named.Value.Value!;
}
else if (named.Key == "Importance")
{
// A boxed primitive can be unboxed to an enum with the same underlying type.
logImportanceEnum = (LogImportance)named.Value.Value!;
}
}
return null;
}


token.ThrowIfCancellationRequested();
return new LogAttributeInfo(path, logStrategyEnum, logImportanceEnum);
}
}
Loading

0 comments on commit 061b3a8

Please sign in to comment.