Skip to content

Commit

Permalink
fixed a bug where scanning would not properly emit the assembly attri…
Browse files Browse the repository at this point in the history
…butes (#1541)
  • Loading branch information
david-driscoll authored Apr 21, 2024
1 parent f6616b8 commit b979d38
Show file tree
Hide file tree
Showing 44 changed files with 1,749 additions and 106 deletions.
2 changes: 1 addition & 1 deletion src/Conventions.Analyzers/Support/AssemblyCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ CollectRequest request
);
}

if (cu.Members.Count == 0) return;
if (cu is { Members: [], AttributeLists: [], }) return;

context.AddSource(
"Compiled_AssemblyProvider.cs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,20 @@ IEnumerable<Assembly> IAssemblyProvider.GetAssemblies(Action<IAssemblyProviderAs

IEnumerable<Type> IAssemblyProvider.GetTypes(Func<ITypeProviderAssemblySelector, IEnumerable<Type>> selector, string filePath, string memberName, int lineNumber)
{
yield break;
switch (lineNumber)
{
// FilePath: Input0.cs Member: Register
case 18:
yield return typeof(global::Rocket.Surgery.Conventions.Configuration.ConfigurationAsyncConvention);
yield return typeof(global::Rocket.Surgery.Conventions.Configuration.ConfigurationConvention);
yield return typeof(global::Rocket.Surgery.Conventions.DependencyInjection.ServiceAsyncConvention);
yield return typeof(global::Rocket.Surgery.Conventions.DependencyInjection.ServiceConvention);
yield return typeof(global::Rocket.Surgery.Conventions.Logging.LoggingAsyncConvention);
yield return typeof(global::Rocket.Surgery.Conventions.Logging.LoggingConvention);
yield return typeof(global::Rocket.Surgery.Conventions.Setup.SetupAsyncConvention);
yield return typeof(global::Rocket.Surgery.Conventions.Setup.SetupConvention);
break;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
using Microsoft.Extensions.DependencyInjection;
using Rocket.Surgery.Conventions;
using Rocket.Surgery.Conventions.Reflection;
using System.Runtime.Loader;

namespace TestProject.Conventions
{
internal sealed partial class Imports
{
public IAssemblyProvider CreateAssemblyProvider(ConventionContextBuilder builder) => new AssemblyProvider();
public IAssemblyProvider CreateAssemblyProvider(ConventionContextBuilder builder) => new AssemblyProvider(builder.Properties.GetRequiredService<AssemblyLoadContext>());
[System.CodeDom.Compiler.GeneratedCode("Rocket.Surgery.Conventions.Analyzers", "version"), System.Runtime.CompilerServices.CompilerGenerated, System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
private class AssemblyProvider() : IAssemblyProvider
private class AssemblyProvider(AssemblyLoadContext context) : IAssemblyProvider
{
IEnumerable<Assembly> IAssemblyProvider.GetAssemblies(Action<IAssemblyProviderAssemblySelector> action, string filePath, string memberName, int lineNumber)
{
Expand All @@ -24,8 +25,96 @@ IEnumerable<Assembly> IAssemblyProvider.GetAssemblies(Action<IAssemblyProviderAs

IEnumerable<Type> IAssemblyProvider.GetTypes(Func<ITypeProviderAssemblySelector, IEnumerable<Type>> selector, string filePath, string memberName, int lineNumber)
{
yield break;
switch (lineNumber)
{
// FilePath: Input0.cs Member: Register
case 18:
yield return typeof(global::Microsoft.Extensions.Configuration.RocketSurgeryLoggingExtensions);
yield return RocketSurgeryConventions.GetType("Microsoft.Extensions.DependencyInjection.LoggingBuilder");
yield return typeof(global::Microsoft.Extensions.DependencyInjection.RocketSurgeryServiceCollectionExtensions);
yield return typeof(global::Microsoft.Extensions.Logging.RocketSurgeryLoggingExtensions);
yield return typeof(global::Rocket.Surgery.Conventions.AbstractConventionContextBuilderExtensions);
yield return RocketSurgeryConventionsAbstractions.GetType("Rocket.Surgery.Conventions.Adapters.IServiceFactoryAdapter");
yield return RocketSurgeryConventionsAbstractions.GetType("Rocket.Surgery.Conventions.Adapters.ServiceFactoryAdapter`1");
yield return RocketSurgeryConventionsAbstractions.GetType("Rocket.Surgery.Conventions.AssemblyProviderFactory");
yield return typeof(global::Rocket.Surgery.Conventions.Configuration.ConfigurationAsyncConvention);
yield return typeof(global::Rocket.Surgery.Conventions.Configuration.ConfigurationBuilderApplicationDelegate);
yield return typeof(global::Rocket.Surgery.Conventions.Configuration.ConfigurationBuilderDelegateResult);
yield return typeof(global::Rocket.Surgery.Conventions.Configuration.ConfigurationBuilderEnvironmentDelegate);
yield return typeof(global::Rocket.Surgery.Conventions.Configuration.ConfigurationConvention);
yield return typeof(global::Rocket.Surgery.Conventions.Configuration.ConfigurationOptionsExtensions);
yield return typeof(global::Rocket.Surgery.Conventions.Configuration.IConfigurationAsyncConvention);
yield return typeof(global::Rocket.Surgery.Conventions.Configuration.IConfigurationConvention);
yield return typeof(global::Rocket.Surgery.Conventions.ConventionContext);
yield return typeof(global::Rocket.Surgery.Conventions.ConventionContextBuilder);
yield return typeof(global::Rocket.Surgery.Conventions.ConventionContextBuilderExtensions);
yield return typeof(global::Rocket.Surgery.Conventions.ConventionContextExtensions);
yield return RocketSurgeryConventions.GetType("Rocket.Surgery.Conventions.ConventionContextHelpers");
yield return RocketSurgeryConventionsAbstractions.GetType("Rocket.Surgery.Conventions.ConventionDependency");
yield return typeof(global::Rocket.Surgery.Conventions.ConventionHostBuilderExtensions);
yield return RocketSurgeryConventionsAbstractions.GetType("Rocket.Surgery.Conventions.ConventionHostBuilderExtensions+ServiceProviderWrapper`1");
yield return RocketSurgeryConventionsAbstractions.GetType("Rocket.Surgery.Conventions.ConventionOrDelegate");
yield return RocketSurgeryConventionsAbstractions.GetType("Rocket.Surgery.Conventions.ConventionProvider");
yield return typeof(global::Rocket.Surgery.Conventions.ConventionWithDependencies);
yield return typeof(global::Rocket.Surgery.Conventions.DependencyDirection);
yield return typeof(global::Rocket.Surgery.Conventions.DependencyInjection.IServiceAsyncConvention);
yield return typeof(global::Rocket.Surgery.Conventions.DependencyInjection.IServiceConvention);
yield return typeof(global::Rocket.Surgery.Conventions.DependencyInjection.ServiceAsyncConvention);
yield return typeof(global::Rocket.Surgery.Conventions.DependencyInjection.ServiceConvention);
yield return RocketSurgeryConventions.GetType("Rocket.Surgery.Conventions.Extensions.RocketSurgerySetupExtensions");
yield return typeof(global::Rocket.Surgery.Conventions.HostType);
yield return typeof(global::Rocket.Surgery.Conventions.IAssemblyProvider);
yield return typeof(global::Rocket.Surgery.Conventions.IConvention);
yield return typeof(global::Rocket.Surgery.Conventions.IConventionContext);
yield return typeof(global::Rocket.Surgery.Conventions.IConventionDependency);
yield return typeof(global::Rocket.Surgery.Conventions.IConventionFactory);
yield return typeof(global::Rocket.Surgery.Conventions.IConventionProvider);
yield return typeof(global::Rocket.Surgery.Conventions.IConventionWithDependencies);
yield return RocketSurgeryConventionsAbstractions.GetType("Rocket.Surgery.Conventions.IHostBasedConvention");
yield return typeof(global::Rocket.Surgery.Conventions.IReadOnlyServiceProviderDictionary);
yield return typeof(global::Rocket.Surgery.Conventions.IServiceProviderDictionary);
yield return typeof(global::Rocket.Surgery.Conventions.Logging.ILoggingAsyncConvention);
yield return typeof(global::Rocket.Surgery.Conventions.Logging.ILoggingConvention);
yield return typeof(global::Rocket.Surgery.Conventions.Logging.LoggingAsyncConvention);
yield return typeof(global::Rocket.Surgery.Conventions.Logging.LoggingConvention);
yield return typeof(global::Rocket.Surgery.Conventions.Logging.RocketLoggingOptions);
yield return RocketSurgeryConventions.GetType("Rocket.Surgery.Conventions.LoggingExtensions");
yield return typeof(global::Rocket.Surgery.Conventions.ReadOnlyServiceProviderDictionary);
yield return RocketSurgeryConventions.GetType("Rocket.Surgery.Conventions.Reflection.AppDomainAssemblyProvider");
yield return typeof(global::Rocket.Surgery.Conventions.Reflection.AppDomainConventionFactory);
yield return RocketSurgeryConventions.GetType("Rocket.Surgery.Conventions.Reflection.AssemblyCandidateResolver");
yield return RocketSurgeryConventions.GetType("Rocket.Surgery.Conventions.Reflection.AssemblyCandidateResolver+Dependency");
yield return typeof(global::Rocket.Surgery.Conventions.Reflection.AssemblyConventionFactory);
yield return RocketSurgeryConventions.GetType("Rocket.Surgery.Conventions.Reflection.AssemblyProviderAssemblySelector");
yield return typeof(global::Rocket.Surgery.Conventions.Reflection.ConventionFactoryBase);
yield return RocketSurgeryConventions.GetType("Rocket.Surgery.Conventions.Reflection.DefaultAssemblyProvider");
yield return RocketSurgeryConventions.GetType("Rocket.Surgery.Conventions.Reflection.DependencyClassification");
yield return typeof(global::Rocket.Surgery.Conventions.Reflection.IAssemblyProviderAssemblySelector);
yield return typeof(global::Rocket.Surgery.Conventions.Reflection.ITypeFilter);
yield return typeof(global::Rocket.Surgery.Conventions.Reflection.ITypeProviderAssemblySelector);
yield return typeof(global::Rocket.Surgery.Conventions.Reflection.ITypeSelector);
yield return RocketSurgeryConventions.GetType("Rocket.Surgery.Conventions.Reflection.TypeFilter");
yield return typeof(global::Rocket.Surgery.Conventions.Reflection.TypeInfoFilter);
yield return typeof(global::Rocket.Surgery.Conventions.Reflection.TypeKindFilter);
yield return RocketSurgeryConventions.GetType("Rocket.Surgery.Conventions.Reflection.TypeProviderAssemblySelector");
yield return typeof(global::Rocket.Surgery.Conventions.ServiceProviderDictionary);
yield return typeof(global::Rocket.Surgery.Conventions.ServiceProviderDictionaryExtensions);
yield return RocketSurgeryConventionsAbstractions.GetType("Rocket.Surgery.Conventions.ServiceProviderFactoryAdapter");
yield return typeof(global::Rocket.Surgery.Conventions.Setup.ISetupAsyncConvention);
yield return typeof(global::Rocket.Surgery.Conventions.Setup.ISetupConvention);
yield return typeof(global::Rocket.Surgery.Conventions.Setup.SetupAsyncConvention);
yield return typeof(global::Rocket.Surgery.Conventions.Setup.SetupConvention);
yield return typeof(global::Rocket.Surgery.Conventions.Testing.TestConventionContextBuilderExtensions);
yield return RocketSurgeryConventionsAbstractions.GetType("Rocket.Surgery.Conventions.ThrowHelper");
break;
}
}

private Assembly _RocketSurgeryConventions;
private Assembly RocketSurgeryConventions => _RocketSurgeryConventions ??= context.LoadFromAssemblyName(new AssemblyName("Rocket.Surgery.Conventions, Version=version, Culture=neutral, PublicKeyToken=null"));

private Assembly _RocketSurgeryConventionsAbstractions;
private Assembly RocketSurgeryConventionsAbstractions => _RocketSurgeryConventionsAbstractions ??= context.LoadFromAssemblyName(new AssemblyName("Rocket.Surgery.Conventions.Abstractions, Version=version, Culture=neutral, PublicKeyToken=null"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
using Microsoft.Extensions.DependencyInjection;
using Rocket.Surgery.Conventions;
using Rocket.Surgery.Conventions.Reflection;
using System.Runtime.Loader;

namespace TestProject.Conventions
{
internal sealed partial class Imports
{
public IAssemblyProvider CreateAssemblyProvider(ConventionContextBuilder builder) => new AssemblyProvider();
public IAssemblyProvider CreateAssemblyProvider(ConventionContextBuilder builder) => new AssemblyProvider(builder.Properties.GetRequiredService<AssemblyLoadContext>());
[System.CodeDom.Compiler.GeneratedCode("Rocket.Surgery.Conventions.Analyzers", "version"), System.Runtime.CompilerServices.CompilerGenerated, System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
private class AssemblyProvider() : IAssemblyProvider
private class AssemblyProvider(AssemblyLoadContext context) : IAssemblyProvider
{
IEnumerable<Assembly> IAssemblyProvider.GetAssemblies(Action<IAssemblyProviderAssemblySelector> action, string filePath, string memberName, int lineNumber)
{
Expand All @@ -24,8 +25,31 @@ IEnumerable<Assembly> IAssemblyProvider.GetAssemblies(Action<IAssemblyProviderAs

IEnumerable<Type> IAssemblyProvider.GetTypes(Func<ITypeProviderAssemblySelector, IEnumerable<Type>> selector, string filePath, string memberName, int lineNumber)
{
yield break;
switch (lineNumber)
{
// FilePath: Input0.cs Member: Register
case 18:
yield return typeof(global::Rocket.Surgery.Conventions.Configuration.IConfigurationAsyncConvention);
yield return typeof(global::Rocket.Surgery.Conventions.Configuration.IConfigurationConvention);
yield return typeof(global::Rocket.Surgery.Conventions.DependencyInjection.IServiceAsyncConvention);
yield return typeof(global::Rocket.Surgery.Conventions.DependencyInjection.IServiceConvention);
yield return typeof(global::Rocket.Surgery.Conventions.IConvention);
yield return typeof(global::Rocket.Surgery.Conventions.IConventionContext);
yield return typeof(global::Rocket.Surgery.Conventions.IConventionDependency);
yield return typeof(global::Rocket.Surgery.Conventions.IConventionFactory);
yield return typeof(global::Rocket.Surgery.Conventions.IConventionProvider);
yield return typeof(global::Rocket.Surgery.Conventions.IConventionWithDependencies);
yield return RocketSurgeryConventionsAbstractions.GetType("Rocket.Surgery.Conventions.IHostBasedConvention");
yield return typeof(global::Rocket.Surgery.Conventions.Logging.ILoggingAsyncConvention);
yield return typeof(global::Rocket.Surgery.Conventions.Logging.ILoggingConvention);
yield return typeof(global::Rocket.Surgery.Conventions.Setup.ISetupAsyncConvention);
yield return typeof(global::Rocket.Surgery.Conventions.Setup.ISetupConvention);
break;
}
}

private Assembly _RocketSurgeryConventionsAbstractions;
private Assembly RocketSurgeryConventionsAbstractions => _RocketSurgeryConventionsAbstractions ??= context.LoadFromAssemblyName(new AssemblyName("Rocket.Surgery.Conventions.Abstractions, Version=version, Culture=neutral, PublicKeyToken=null"));
}
}
}
Loading

0 comments on commit b979d38

Please sign in to comment.