Skip to content

Commit

Permalink
refactor compilation passing more
Browse files Browse the repository at this point in the history
  • Loading branch information
dferretti committed Jun 20, 2024
1 parent 193254b commit 1b5a918
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private static DiagnosticModel<MethodWithAttributesModel> ParseMethodModel(Gener
var attributeData = new AttributeModel[context.Attributes.Length];
for (var i = 0; i < context.Attributes.Length; i++)
{
attributeData[i] = AttributeModel.Create(context.Attributes[i], context.SemanticModel.Compilation);
attributeData[i] = AttributeModel.Create(context.Attributes[i], context.TargetSymbol.ContainingAssembly);

if (!attributeData[i].HasSearchCriteria)
return Diagnostic.Create(MissingSearchCriteria, attributeData[i].Location);
Expand Down
8 changes: 4 additions & 4 deletions ServiceScan.SourceGenerator/Model/AttributeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ record AttributeModel(
{
public bool HasSearchCriteria => TypeNameFilter != null || AssignableToType != null;

public static AttributeModel Create(AttributeData attribute, Compilation compilation)
public static AttributeModel Create(AttributeData attribute, IAssemblySymbol currentAssembly)
{
var assemblyType = attribute.NamedArguments.FirstOrDefault(a => a.Key == "FromAssemblyOf").Value.Value as INamedTypeSymbol;
var assignableTo = attribute.NamedArguments.FirstOrDefault(a => a.Key == "AssignableTo").Value.Value as INamedTypeSymbol;
Expand All @@ -34,7 +34,7 @@ public static AttributeModel Create(AttributeData attribute, Compilation compila
};

var assignableToTypeModel = assignableTo is not null ? TypeModel.Create(assignableTo) : null;
var registrations = GetRegistrationsFromAssembly(assemblyType, compilation, typeNameFilter, asSelf, asImplementedInterfaces, assignableToTypeModel, lifetime);
var registrations = GetRegistrationsFromAssembly(assemblyType, currentAssembly, typeNameFilter, asSelf, asImplementedInterfaces, assignableToTypeModel, lifetime);

var syntax = attribute.ApplicationSyntaxReference.SyntaxTree;
var textSpan = attribute.ApplicationSyntaxReference.Span;
Expand All @@ -47,7 +47,7 @@ public static AttributeModel Create(AttributeData attribute, Compilation compila

private static EquatableArray<ServiceRegistrationModel>? GetRegistrationsFromAssembly(
INamedTypeSymbol? fromAssemblyOf,
Compilation compilation,
IAssemblySymbol currentAssembly,
string? typeNameFilter,
bool asSelf,
bool asImplementedInterfaces,
Expand All @@ -58,7 +58,7 @@ public static AttributeModel Create(AttributeData attribute, Compilation compila
return null;

// if user specifies FromAssemblyOf = typeof(SomeType), but SomeType is from the same assembly as the method with the attribute
if (SymbolEqualityComparer.Default.Equals(fromAssemblyOf.ContainingAssembly, compilation.Assembly))
if (SymbolEqualityComparer.Default.Equals(fromAssemblyOf.ContainingAssembly, currentAssembly))
return null;

var types = fromAssemblyOf.ContainingAssembly
Expand Down

0 comments on commit 1b5a918

Please sign in to comment.