-
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
923445a
commit 94458e6
Showing
19 changed files
with
303 additions
and
38 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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Collections.Immutable; | ||
using Microsoft.CodeAnalysis; | ||
using static Pretender.SourceGenerator.PretenderSourceGenerator; | ||
|
||
namespace Pretender.SourceGenerator.Parser | ||
{ | ||
internal class PretendParser | ||
{ | ||
|
||
public PretendParser(PretendInvocation pretendInvocation, CompilationData compilationData) | ||
{ | ||
PretendInvocation = pretendInvocation; | ||
} | ||
|
||
public PretendInvocation PretendInvocation { get; } | ||
|
||
public (object? Emitter, ImmutableArray<Diagnostic>? Diagnostics) GetEmitter(CancellationToken cancellationToken) | ||
{ | ||
|
||
return (null, null); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System.Diagnostics; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using Microsoft.CodeAnalysis.Operations; | ||
using Pretender.SourceGenerator.Parser; | ||
|
||
namespace Pretender.SourceGenerator | ||
{ | ||
internal class PretendInvocation | ||
{ | ||
public PretendInvocation(ITypeSymbol pretendType, Location location, bool fillExisting) | ||
{ | ||
PretendType = pretendType; | ||
Location = location; | ||
FillExisting = fillExisting; | ||
} | ||
|
||
public ITypeSymbol PretendType { get; } | ||
public Location Location { get; } | ||
public bool FillExisting { get; } | ||
|
||
public static bool IsCandidateSyntaxNode(SyntaxNode node) | ||
{ | ||
// Pretend.That<T>(); | ||
if (node is InvocationExpressionSyntax | ||
{ | ||
Expression: MemberAccessExpressionSyntax | ||
{ | ||
// TODO: Will this work with a using static Pretender.Pretend | ||
// ... | ||
// That<IInterface>(); | ||
Expression: IdentifierNameSyntax { Identifier.ValueText: "Pretend" }, | ||
Name: GenericNameSyntax { Identifier.ValueText: "That", TypeArgumentList.Arguments.Count: 1 }, | ||
} | ||
}) | ||
{ | ||
return true; | ||
} | ||
|
||
// TODO: Also do Attribute | ||
|
||
return false; | ||
} | ||
|
||
public static PretendInvocation? Create(GeneratorSyntaxContext context, CancellationToken cancellationToken) | ||
{ | ||
Debug.Assert(IsCandidateSyntaxNode(context.Node)); | ||
var operation = context.SemanticModel.GetOperation(context.Node, cancellationToken); | ||
if (operation is IInvocationOperation invocation) | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
return CreateFromGeneric(invocation); | ||
} | ||
// TODO: Support attribute | ||
|
||
return null; | ||
} | ||
|
||
private static PretendInvocation? CreateFromGeneric(IInvocationOperation operation) | ||
{ | ||
if (operation.TargetMethod is not IMethodSymbol | ||
{ | ||
Name: "That", | ||
ContainingType: INamedTypeSymbol namedTypeSymbol, | ||
TypeArguments.Length: 1, | ||
} || !KnownTypeSymbols.IsPretend(namedTypeSymbol)) | ||
{ | ||
return null; | ||
} | ||
|
||
return new PretendInvocation(operation.TargetMethod.TypeArguments[0], operation.Syntax.GetLocation(), false); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
namespace Pretender.Behaviors | ||
{ | ||
public delegate void Callback(ref CallInfo callInfo); | ||
|
||
internal class CallbackBehavior : Behavior | ||
{ | ||
private readonly Callback _action; | ||
private readonly Action<CallInfo> _action; | ||
|
||
public CallbackBehavior(Callback action) | ||
public CallbackBehavior(Action<CallInfo> action) | ||
{ | ||
_action = action; | ||
} | ||
|
||
public override void Execute(CallInfo callInfo) | ||
{ | ||
_action(ref callInfo); | ||
_action(callInfo); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.