1
1
using GitVersion . Polyfill ;
2
2
3
- // ReSharper disable InconsistentNaming
4
3
namespace GitVersion ;
5
4
6
- [ Generator ( LanguageNames . CSharp ) ]
7
- public class CommandImplGenerator : IIncrementalGenerator
5
+ public abstract class CommandBaseGenerator : IIncrementalGenerator
8
6
{
9
- private const string GeneratedNamespaceName = "GitVersion.Generated" ;
10
7
private const string InfraNamespaceName = "GitVersion" ;
11
- private const string DependencyInjectionNamespaceName = "GitVersion.Infrastructure" ;
12
- private const string CommandNamespaceName = "GitVersion.Commands" ;
13
8
private const string CommandInterfaceFullName = $ "{ InfraNamespaceName } .ICommand<T>";
14
9
private const string CommandAttributeFullName = $ "{ InfraNamespaceName } .CommandAttribute";
15
10
private const string CommandAttributeGenericFullName = $ "{ InfraNamespaceName } .CommandAttribute<T>";
@@ -22,6 +17,8 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
22
17
context . RegisterImplementationSourceOutput ( commandTypes , GenerateSourceCode ) ;
23
18
}
24
19
20
+ internal abstract void GenerateSourceCode ( SourceProductionContext context , ImmutableArray < CommandInfo ? > commandInfos ) ;
21
+
25
22
private static ImmutableArray < CommandInfo ? > SelectCommandTypes ( Compilation compilation , CancellationToken ct )
26
23
{
27
24
ct . ThrowIfCancellationRequested ( ) ;
@@ -38,43 +35,7 @@ static bool SearchQuery(INamedTypeSymbol typeSymbol)
38
35
return attributeData is not null ;
39
36
}
40
37
}
41
- private static void GenerateSourceCode ( SourceProductionContext context , ImmutableArray < CommandInfo ? > commandInfos )
42
- {
43
- foreach ( var commandInfo in commandInfos )
44
- {
45
- if ( commandInfo == null )
46
- continue ;
47
-
48
- var commandHandlerTemplate = Template . Parse ( Content . CommandImplContent ) ;
49
-
50
- var commandHandlerSource = commandHandlerTemplate . Render ( new
51
- {
52
- Model = commandInfo ,
53
- Namespace = GeneratedNamespaceName
54
- } , member => member . Name ) ;
55
38
56
- context . AddSource ( $ "{ commandInfo . CommandTypeName } Impl.g.cs", string . Join ( "\n " , commandHandlerSource ) ) ;
57
- }
58
-
59
- var commandHandlersModuleTemplate = Template . Parse ( Content . CommandsModuleContent ) ;
60
- var commandHandlersModuleSource = commandHandlersModuleTemplate . Render ( new
61
- {
62
- Model = commandInfos ,
63
- Namespace = GeneratedNamespaceName ,
64
- InfraNamespaceName ,
65
- DependencyInjectionNamespaceName ,
66
- CommandNamespaceName
67
- } , member => member . Name ) ;
68
- context . AddSource ( "CommandsModule.g.cs" , string . Join ( "\n " , commandHandlersModuleSource ) ) ;
69
-
70
- var rootCommandHandlerTemplate = Template . Parse ( Content . RootCommandImplContent ) ;
71
- var rootCommandHandlerSource = rootCommandHandlerTemplate . Render ( new
72
- {
73
- Namespace = GeneratedNamespaceName ,
74
- InfraNamespaceName
75
- } , member => member . Name ) ;
76
- context . AddSource ( "RootCommandImpl.g.cs" , string . Join ( "\n " , rootCommandHandlerSource ) ) ;
77
- }
78
39
private static CommandInfo ? MapToCommandInfo ( ITypeSymbol classSymbol , CancellationToken ct )
79
40
{
80
41
ct . ThrowIfCancellationRequested ( ) ;
0 commit comments