-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3485768
commit 6381c1b
Showing
5 changed files
with
95 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,88 @@ | ||
using System.Collections.Immutable; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; | ||
|
||
namespace Pretender.SourceGenerator.Emitter | ||
{ | ||
internal class GrandEmitter | ||
{ | ||
private readonly ImmutableArray<PretendEmitter> _pretendEmitters; | ||
private readonly ImmutableArray<SetupEmitter> _setupEmitters; | ||
private readonly ImmutableArray<VerifyEmitter> _verifyEmitters; | ||
private readonly ImmutableArray<CreateEmitter> _createEmitters; | ||
|
||
public GrandEmitter(ImmutableArray<PretendEmitter> pretendEmitters) | ||
public GrandEmitter( | ||
ImmutableArray<PretendEmitter> pretendEmitters, | ||
ImmutableArray<SetupEmitter> setupEmitters, | ||
ImmutableArray<VerifyEmitter> verifyEmitters, | ||
ImmutableArray<CreateEmitter> createEmitters) | ||
{ | ||
_pretendEmitters = pretendEmitters; | ||
_setupEmitters = setupEmitters; | ||
_verifyEmitters = verifyEmitters; | ||
_createEmitters = createEmitters; | ||
} | ||
|
||
public CompilationUnitSyntax Emit(CancellationToken cancellationToken) | ||
{ | ||
throw new NotImplementedException(); | ||
var namespaceDeclaration = KnownBlocks.OurNamespace | ||
.AddUsings( | ||
UsingDirective(ParseName("System")), | ||
KnownBlocks.CompilerServicesUsing, | ||
UsingDirective(ParseName("System.Threading.Tasks")), | ||
KnownBlocks.PretenderUsing, | ||
KnownBlocks.PretenderInternalsUsing | ||
); | ||
|
||
foreach (var pretendEmitter in _pretendEmitters) | ||
{ | ||
namespaceDeclaration = namespaceDeclaration | ||
.AddMembers(pretendEmitter.Emit(cancellationToken)); | ||
} | ||
|
||
var setupInterceptorsClass = ClassDeclaration("SetupInterceptors") | ||
.WithModifiers(TokenList(Token(SyntaxKind.FileKeyword), Token(SyntaxKind.StaticKeyword))); | ||
|
||
int setupIndex = 0; | ||
foreach (var setupEmitter in _setupEmitters) | ||
{ | ||
setupInterceptorsClass = setupInterceptorsClass | ||
.AddMembers(setupEmitter.Emit(setupIndex, cancellationToken)); | ||
setupIndex++; | ||
} | ||
|
||
var verifyInterceptorsClass = ClassDeclaration("VerifyInterceptors") | ||
.AddModifiers(Token(SyntaxKind.FileKeyword), Token(SyntaxKind.StaticKeyword)); | ||
|
||
int verifyIndex = 0; | ||
foreach (var verifyEmitter in _verifyEmitters) | ||
{ | ||
verifyInterceptorsClass = verifyInterceptorsClass | ||
.AddMembers(verifyEmitter.Emit(verifyIndex, cancellationToken)); | ||
verifyIndex++; | ||
} | ||
|
||
var createInterceptorsClass = ClassDeclaration("CreateInterceptors") | ||
.AddModifiers(Token(SyntaxKind.FileKeyword), Token(SyntaxKind.StaticKeyword)); | ||
|
||
int createIndex = 0; | ||
foreach (var createEmitter in _createEmitters) | ||
{ | ||
createInterceptorsClass = createInterceptorsClass | ||
.AddMembers(createEmitter.Emit(cancellationToken)); | ||
createIndex++; | ||
} | ||
|
||
namespaceDeclaration = namespaceDeclaration | ||
.AddMembers(setupInterceptorsClass, verifyInterceptorsClass, createInterceptorsClass); | ||
|
||
return CompilationUnit() | ||
.AddMembers( | ||
KnownBlocks.InterceptsLocationAttribute, | ||
namespaceDeclaration) | ||
.NormalizeWhitespace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters