Skip to content

Commit e8cfc89

Browse files
committed
Minor refactoring to remove passing SemanticModel where it is not used.
1 parent f288ec9 commit e8cfc89

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

AsyncTaskOrchestratorGenerator/Main.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ private static bool IsSyntaxTargetForGeneration(SyntaxNode syntaxNode, Cancellat
2323
return syntaxNode is TypeDeclarationSyntax;
2424
}
2525

26-
private static (INamedTypeSymbol, SemanticModel) GetSemanticTargetForGeneration(GeneratorAttributeSyntaxContext context, CancellationToken cancellationToken) {
26+
private static INamedTypeSymbol GetSemanticTargetForGeneration(GeneratorAttributeSyntaxContext context, CancellationToken cancellationToken) {
2727

28-
return (context.TargetSymbol as INamedTypeSymbol, context.SemanticModel);
28+
return context.TargetSymbol as INamedTypeSymbol;
2929
}
3030

31-
private static void Execute(SourceProductionContext context, (INamedTypeSymbol typeSymbol, SemanticModel semanticModel) typeInfo) {
32-
var (classSource, className) = OutputGenerator.GenerateClassOutputs(typeInfo);
33-
var (interfaceSource, interfaceName) = OutputGenerator.GenerateInterfaceOutputs(typeInfo.typeSymbol);
31+
private static void Execute(SourceProductionContext context, INamedTypeSymbol typeSymbol) {
32+
var (classSource, className) = OutputGenerator.GenerateClassOutputs(typeSymbol);
33+
var (interfaceSource, interfaceName) = OutputGenerator.GenerateInterfaceOutputs(typeSymbol);
3434

3535
context.AddSource($"{className}.generated.cs", SourceText.From(classSource, Encoding.UTF8, SourceHashAlgorithm.Sha256));
3636
context.AddSource($"{interfaceName}.generated.cs", SourceText.From(interfaceSource, Encoding.UTF8, SourceHashAlgorithm.Sha256));

AsyncTaskOrchestratorGenerator/OutputGenerator.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ namespace AsyncTaskOrchestratorGenerator
88
{
99
internal static class OutputGenerator
1010
{
11-
public static (string source, string className) GenerateClassOutputs((INamedTypeSymbol typeSymbol, SemanticModel semanticModel) typeInfo) {
12-
var type = typeInfo.typeSymbol;
13-
var semanticModel = typeInfo.semanticModel;
11+
public static (string source, string className) GenerateClassOutputs(INamedTypeSymbol type) {
1412
var constructorArguments = GetAttributeConstructorArguments(type);
1513
var className = constructorArguments.First().Value.ToString();
1614
var executeMethodName = constructorArguments.ElementAt(1).Value.ToString();
@@ -50,10 +48,6 @@ namespace {type.ContainingNamespace.ToDisplayString()};
5048
return (source, className);
5149
}
5250

53-
private static System.Collections.Immutable.ImmutableArray<TypedConstant> GetAttributeConstructorArguments(INamedTypeSymbol type) {
54-
return type.GetAttributes().First((a) => a.AttributeClass.Name == nameof(AsyncTaskOrchestratorAttribute)).ConstructorArguments;
55-
}
56-
5751
public static (string source, string interfaceName) GenerateInterfaceOutputs(INamedTypeSymbol type) {
5852
var constructorArguments = GetAttributeConstructorArguments(type);
5953
var className = constructorArguments.First().Value.ToString();
@@ -79,6 +73,10 @@ namespace {type.ContainingNamespace.ToDisplayString()};
7973
return (source, interfaceName);
8074
}
8175

76+
private static System.Collections.Immutable.ImmutableArray<TypedConstant> GetAttributeConstructorArguments(INamedTypeSymbol type) {
77+
return type.GetAttributes().First((a) => a.AttributeClass.Name == nameof(AsyncTaskOrchestratorAttribute)).ConstructorArguments;
78+
}
79+
8280
private static (ExecuteMethodSignatureData, Dictionary<string, TaskData>, TaskData) CreateExecuteMethodData(INamedTypeSymbol type, IEnumerable<IFieldSymbol> fields, string executeMethodName) {
8381
var executeMethod = GetExecuteMethod(type);
8482
var statements = (executeMethod.DeclaringSyntaxReferences.First().GetSyntax() as MethodDeclarationSyntax).Body.Statements;

0 commit comments

Comments
 (0)