-
-
Notifications
You must be signed in to change notification settings - Fork 180
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
Showing
4 changed files
with
129 additions
and
85 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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
|
||
namespace VContainer.SourceGenerator; | ||
|
||
static class Analyzer | ||
{ | ||
public static bool ContainsPotentialRegisterCall(string call) | ||
{ | ||
return call.IndexOf(".Register", StringComparison.Ordinal) > 0; | ||
} | ||
|
||
public static TypeMeta? AnalyzeTypeSymbol(ITypeSymbol symbol, ReferenceSymbols referenceSymbols, CancellationToken cancellation = default) | ||
{ | ||
{ | ||
if (symbol is not INamedTypeSymbol typeSymbol) | ||
{ | ||
return null; | ||
} | ||
|
||
foreach (var baseTypeSymbol in typeSymbol.GetAllBaseTypes()) | ||
{ | ||
var name = baseTypeSymbol.ToDisplayString(); | ||
// Ignore | ||
if (name == "System.Attributes") | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
foreach (var attributeData in typeSymbol.GetAttributes()) | ||
{ | ||
if (attributeData.AttributeClass != null) | ||
{ | ||
// Ignore | ||
if (attributeData.AttributeClass.ToDisplayString() == "VContainer.InjectIgnoreAttribute") | ||
return null; | ||
} | ||
|
||
} | ||
return new TypeMeta(Syntax, typeSymbol, referenceSymbols); | ||
} | ||
} | ||
} | ||
|
||
record struct TypeDeclarationCandidate(TypeDeclarationSyntax Syntax, SemanticModel SemanticModel) | ||
{ | ||
public TypeMeta? Analyze(ReferenceSymbols referenceSymbols, CancellationToken cancellation = default) | ||
{ | ||
var symbol = SemanticModel.GetDeclaredSymbol(Syntax); | ||
if (symbol is ITypeSymbol typeSymbol) | ||
return Analyzer.AnalyzeTypeSymbol(typeSymbol, referenceSymbols); | ||
return null; | ||
} | ||
} | ||
|
||
record struct RegisterInvocationCandidate(InvocationExpressionSyntax Syntax, SemanticModel SemanticModel) | ||
{ | ||
public IEnumerable<TypeMeta> Analyze(ReferenceSymbols referenceSymbols, CancellationToken cancellation = default) | ||
{ | ||
var symbol = SemanticModel.GetSymbolInfo(Syntax).Symbol; | ||
if (symbol is IMethodSymbol methodSymbol) | ||
{ | ||
var typeSymbol = methodSymbol.ReceiverType; | ||
if (SymbolEqualityComparer.Default.Equals(typeSymbol, referenceSymbols.ContainerBuilderInterface)) | ||
{ | ||
if (methodSymbol.Arity > 0) | ||
{ | ||
foreach (var typeArgument in methodSymbol.TypeArguments) | ||
{ | ||
if (typeArgument.TypeKind is TypeKind.Interface or TypeKind.Struct) | ||
{ | ||
continue; | ||
} | ||
if (typeArgument.IsAbstract) | ||
{ | ||
continue; | ||
} | ||
|
||
yield return Analyzer.AnalyzeTypeSymbol(typeArgument.ContainingType); | ||
Check failure on line 83 in VContainer.SourceGenerator/Analyzer.cs GitHub Actions / test-dotnet
|
||
} | ||
} | ||
else | ||
{ | ||
foreach (var p in methodSymbol.Parameters) | ||
{ | ||
yield return Analyzer.AnalyzeTypeSymbol(p.Type); | ||
Check failure on line 90 in VContainer.SourceGenerator/Analyzer.cs GitHub Actions / test-dotnet
|
||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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