Skip to content

Commit

Permalink
continued work on removing iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
david-driscoll committed Dec 27, 2024
1 parent 254b83b commit 1c64461
Show file tree
Hide file tree
Showing 660 changed files with 62,547 additions and 3,650 deletions.
15 changes: 15 additions & 0 deletions Extensions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DependencyInjection.Analyze
.editorconfig = src\DependencyInjection.Analyzers.roslyn4.8\.editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestAssembly", "TestAssembly\TestAssembly.csproj", "{02AB8A28-1BD2-4299-8CBE-760F946399B3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -353,6 +355,18 @@ Global
{F5F65F73-DF54-4536-B9EC-1DBB08BF2876}.Release|x64.Build.0 = Release|Any CPU
{F5F65F73-DF54-4536-B9EC-1DBB08BF2876}.Release|x86.ActiveCfg = Release|Any CPU
{F5F65F73-DF54-4536-B9EC-1DBB08BF2876}.Release|x86.Build.0 = Release|Any CPU
{02AB8A28-1BD2-4299-8CBE-760F946399B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{02AB8A28-1BD2-4299-8CBE-760F946399B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{02AB8A28-1BD2-4299-8CBE-760F946399B3}.Debug|x64.ActiveCfg = Debug|Any CPU
{02AB8A28-1BD2-4299-8CBE-760F946399B3}.Debug|x64.Build.0 = Debug|Any CPU
{02AB8A28-1BD2-4299-8CBE-760F946399B3}.Debug|x86.ActiveCfg = Debug|Any CPU
{02AB8A28-1BD2-4299-8CBE-760F946399B3}.Debug|x86.Build.0 = Debug|Any CPU
{02AB8A28-1BD2-4299-8CBE-760F946399B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{02AB8A28-1BD2-4299-8CBE-760F946399B3}.Release|Any CPU.Build.0 = Release|Any CPU
{02AB8A28-1BD2-4299-8CBE-760F946399B3}.Release|x64.ActiveCfg = Release|Any CPU
{02AB8A28-1BD2-4299-8CBE-760F946399B3}.Release|x64.Build.0 = Release|Any CPU
{02AB8A28-1BD2-4299-8CBE-760F946399B3}.Release|x86.ActiveCfg = Release|Any CPU
{02AB8A28-1BD2-4299-8CBE-760F946399B3}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -383,6 +397,7 @@ Global
{F5F65F73-DF54-4536-B9EC-1DBB08BF2876} = {8FFDF555-DB50-45F9-9A2D-6410F39151C3}
{F1A11F3E-FA52-4502-8241-F71F0C6DF799} = {8FFDF555-DB50-45F9-9A2D-6410F39151C3}
{B7007E5D-3899-442C-8D3A-98907EB4BC41} = {8FFDF555-DB50-45F9-9A2D-6410F39151C3}
{02AB8A28-1BD2-4299-8CBE-760F946399B3} = {DF33E0FB-9790-4654-B60F-8AB22E0CC3D1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {439897C2-CCBD-44FE-B2DC-A3E4670ADA59}
Expand Down
42 changes: 42 additions & 0 deletions TestAssembly/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace TestAssembly;

public interface IService;

public interface IServiceB;

public class Service : IService, IServiceB;

public static class Nested
{
public class ServiceA : IService;

public class GenericServiceA : IGenericService<string>, IOther;

private record MyRecord;

private class Validator : IValidator<MyRecord>;
}

public class ServiceB : IService;

public interface IRequest<T>;

public interface IRequestHandler<T, R> where T : IRequest<R>;

public class Request : IRequest<Response>;

public class Response;

public class RequestHandler : IRequestHandler<Request, Response>;

public interface IOther;

public interface IGenericService<T>;

public class GenericService : IGenericService<int>, IGenericService<string>, IOther;

public class GenericServiceB : IGenericService<decimal>, IOther;

public interface IValidator;

public interface IValidator<T> : IValidator;
9 changes: 9 additions & 0 deletions TestAssembly/TestAssembly.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
33 changes: 1 addition & 32 deletions src/DependencyInjection.Analyzers/AssemblyCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ CancellationToken cancellationToken

var assemblyFilter = new CompiledAssemblyFilter([.. assemblies]);

var source = Helpers.CreateSourceLocation(methodCallSyntax, cancellationToken);
var source = Helpers.CreateSourceLocation(SourceLocationKind.Assemby, methodCallSyntax, cancellationToken);
// disallow list?
if (source.FileName == "ConventionContextHelpers.cs")
{
Expand Down Expand Up @@ -204,37 +204,6 @@ CancellationToken cancellationToken
return items.ToImmutable();
}

private static bool IsValidMethod(SyntaxNode node) => GetMethod(node) is { method: { }, selector: { } };

private static BlockSyntax GenerateDescriptors(Compilation compilation, IEnumerable<IAssemblySymbol> assemblies, HashSet<IAssemblySymbol> privateAssemblies)
{
var block = Block();
foreach (var assembly in assemblies.OrderBy(z => z.ToDisplayString()))
{
// TODO: Make this always use the load context?
if (StatementGeneration.GetAssemblyExpression(compilation, assembly) is not { } assemblyExpression)
{
_ = privateAssemblies.Add(assembly);
block = block.AddStatements(
ExpressionStatement(
InvocationExpression(MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName("items"), IdentifierName("Add")))
.WithArgumentList(ArgumentList(SingletonSeparatedList(Argument(StatementGeneration.GetPrivateAssembly(assembly)))))
)
);
continue;
}

block = block.AddStatements(
ExpressionStatement(
InvocationExpression(MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName("items"), IdentifierName("Add")))
.WithArgumentList(ArgumentList(SingletonSeparatedList(Argument(assemblyExpression))))
)
);
}

return block;
}

private const string IReflectionAssemblySelector = nameof(IReflectionAssemblySelector);

public record Item(SourceLocation Location, CompiledAssemblyFilter AssemblyFilter);
Expand Down
37 changes: 24 additions & 13 deletions src/DependencyInjection.Analyzers/AssemblyProviderBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,30 @@ private static MethodDeclarationSyntax GenerateMethodBody(MethodDeclarationSynta

return baseMethod
.WithBody(
Block(SyntaxList.Create(
[
..item.Except([returnStatement]),
SwitchGenerator.GenerateSwitchStatement(
[
..locations
.GroupBy(z => z.Location)
.Select(z => new ResolvedSourceLocation(z.Key, z.Aggregate("", (s, location) => s + "\n" + location.Expression), [])),
]
),
returnStatement
]
))
Block(
SyntaxList.Create(
[
..item.Except([returnStatement]),
SwitchGenerator.GenerateSwitchStatement(
[
..locations
.GroupBy(z => z.Location)
.Select(
z => z.Aggregate(
new ResolvedSourceLocation(z.First().Location, "", []),
(location, sourceLocation) => new (
location.Location,
location.Expression + "\n" + sourceLocation.Expression,
[..location.PrivateAssemblies, ..sourceLocation.PrivateAssemblies]
)
)
),
]
),
returnStatement
]
)
)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
var source = text.GetText()?.ToString();
if (source is not { Length: > 100 })
{
return (path: Path.GetFileName(text.Path), source: new([], [], [], []));
return (path: Path.GetFileName(text.Path), source: new([], [], []));
}

return (path: Path.GetFileName(text.Path),
Expand Down Expand Up @@ -138,6 +138,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
diagnostics
);

assemblyRequests = assemblyRequests.AddRange(resolvedData.InternalAssemblyRequests);
reflectionRequests = reflectionRequests.AddRange(resolvedData.InternalReflectionRequests);
serviceDescriptorRequests = serviceDescriptorRequests.AddRange(resolvedData.InternalServiceDescriptorRequests);

Expand All @@ -159,7 +160,6 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
request.compilation.Assembly
);

assemblySources = assemblySources.AddRange(resolvedData.AssemblySources);
reflectionSources = reflectionSources.AddRange(resolvedData.ReflectionSources);
serviceDescriptorSources = serviceDescriptorSources.AddRange(resolvedData.ServiceDescriptorSources);

Expand Down
Loading

0 comments on commit 1c64461

Please sign in to comment.