Skip to content

Commit 4e93de4

Browse files
Copilotdex3r
andcommitted
Address code review: remove deprecated ExecuteFluentGeneratorMethod, improve ExtractBodyGenerationData fallback, comment out dead switch code in source builder
Co-authored-by: dex3r <[email protected]> Agent-Logs-Url: https://github.com/dex3r/EasySourceGenerators/sessions/8070e196-96aa-4613-adf2-2df1ce631bfe
1 parent 03ffc3f commit 4e93de4

2 files changed

Lines changed: 28 additions & 11 deletions

File tree

EasySourceGenerators.Generators/GeneratesMethodExecutionRuntime.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,8 @@ internal static (string? value, string? error) ExecuteSimpleGeneratorMethod(
3131
return ExecuteGeneratorMethodWithArgs(generatorMethod, allPartials, compilation, null);
3232
}
3333

34-
internal static (SwitchBodyData? record, string? error) ExecuteFluentGeneratorMethod(
35-
IMethodSymbol generatorMethod,
36-
IMethodSymbol partialMethod,
37-
Compilation compilation)
38-
{
39-
// Kept for backward compatibility but no longer the primary path.
40-
// SwitchCase-based fluent generation is being replaced by the data abstraction layer.
41-
return (null, "SwitchCase-based fluent generation has been replaced by the data abstraction layer. Use ExecuteFluentBodyGeneratorMethod instead.");
42-
}
34+
// SwitchBodyData-based fluent execution has been replaced by the data abstraction layer.
35+
// Use ExecuteFluentBodyGeneratorMethod instead.
4336

4437
internal static (FluentBodyResult? result, string? error) ExecuteFluentBodyGeneratorMethod(
4538
IMethodSymbol generatorMethod,
@@ -301,8 +294,9 @@ private static FluentBodyResult ExtractBodyGenerationData(object methodResult, I
301294
PropertyInfo? dataProperty = resultType.GetProperty(Consts.BodyGenerationDataPropertyName);
302295
if (dataProperty == null)
303296
{
304-
// The method returned something that isn't a DataMethodBodyGenerator - treat it as a simple return
305-
return new FluentBodyResult(methodResult.ToString(), returnType.SpecialType == SpecialType.System_Void);
297+
// The method returned something that isn't a DataMethodBodyGenerator.
298+
// This may happen when the fluent chain is incomplete (e.g., user returned an intermediate builder).
299+
return new FluentBodyResult(null, returnType.SpecialType == SpecialType.System_Void);
306300
}
307301

308302
object? bodyGenerationData = dataProperty.GetValue(methodResult);

EasySourceGenerators.Generators/GeneratesMethodPatternSourceBuilder.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ namespace EasySourceGenerators.Generators;
99

1010
internal static class GeneratesMethodPatternSourceBuilder
1111
{
12+
// SwitchCase attribute-based and fluent switch generation are commented out pending replacement
13+
// with a data-driven approach. See DataMethodBodyBuilders.cs for details.
14+
/*
1215
internal static string GenerateFromSwitchAttributes(
1316
SourceProductionContext context,
1417
List<GeneratesMethodGenerationTarget> methods,
@@ -143,6 +146,7 @@ internal static string GenerateFromFluent(
143146
144147
return GenerateSwitchMethodSource(containingType, partialMethod, switchBodyData.CasePairs, defaultExpression);
145148
}
149+
*/
146150

147151
internal static string GenerateSimplePartialMethod(
148152
INamedTypeSymbol containingType,
@@ -163,6 +167,8 @@ internal static string GenerateSimplePartialMethod(
163167
return builder.ToString();
164168
}
165169

170+
// Switch-related helper methods are commented out pending replacement with data-driven approach
171+
/*
166172
private static string? ExtractDefaultExpressionFromSwitchDefaultMethod(MethodDeclarationSyntax method)
167173
{
168174
ExpressionSyntax? bodyExpression = method.ExpressionBody?.Expression;
@@ -259,6 +265,23 @@ private static string GenerateSwitchMethodSource(
259265
return builder.ToString();
260266
}
261267
268+
private static string FormatKeyAsCSharpLiteral(object key, ITypeSymbol? parameterType)
269+
{
270+
if (parameterType?.TypeKind == TypeKind.Enum)
271+
{
272+
return $"{parameterType.ToDisplayString()}.{key}";
273+
}
274+
275+
return key switch
276+
{
277+
bool b => b ? "true" : "false",
278+
// SyntaxFactory.Literal handles escaping and quoting (e.g. "hello" → "\"hello\"")
279+
string s => SyntaxFactory.Literal(s).Text,
280+
_ => key.ToString()!
281+
};
282+
}
283+
*/
284+
262285
private static void AppendNamespaceAndTypeHeader(StringBuilder builder, INamedTypeSymbol containingType, IMethodSymbol partialMethod)
263286
{
264287
builder.AppendLine("// <auto-generated/>");

0 commit comments

Comments
 (0)