Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;

using ReactiveMarbles.RoslynHelpers;

Expand Down Expand Up @@ -43,10 +44,12 @@ public static List<MethodMetadata> CheckMetadata(GeneratorExecutionContext conte
{
if (childConstructor.TypeName == metadataMethod.InterfaceTypeName)
{
var location = childConstructor.Parameter.GetLocation(metadataMethod.MethodInvocation);

context.ReportDiagnostic(
Diagnostic.Create(
DiagnosticWarnings.ConstructorsMustNotHaveCircularDependency,
childConstructor.Parameter.Locations.FirstOrDefault(x => x is not null) ?? metadataMethod.MethodInvocation.GetLocation()));
location));
isError = true;
}
}
Expand All @@ -65,10 +68,12 @@ public static List<MethodMetadata> CheckMetadata(GeneratorExecutionContext conte

if (metadataDependencies.TryGetValue(lazyType.ToDisplayString(RoslynCommonHelpers.TypeFormat), out dependencyMethod) && !dependencyMethod.IsLazy)
{
var location = constructorDependency.Parameter.GetLocation(metadataMethod.MethodInvocation);

context.ReportDiagnostic(
Diagnostic.Create(
DiagnosticWarnings.LazyParameterNotRegisteredLazy,
constructorDependency.Parameter.Locations.FirstOrDefault(x => x is not null) ?? metadataMethod.MethodInvocation.GetLocation(),
location,
metadataMethod.ConcreteTypeName,
constructorDependency.Parameter.Name));
isError = true;
Expand All @@ -84,5 +89,17 @@ public static List<MethodMetadata> CheckMetadata(GeneratorExecutionContext conte

return methods;
}

private static Location GetLocation(this ISymbol symbol, InvocationExpressionSyntax backupInvocation)
{
var location = symbol.Locations.FirstOrDefault();

if (location?.Kind != LocationKind.SourceFile)
{
location = backupInvocation.GetLocation();
}

return location;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<DevelopmentDependency>true</DevelopmentDependency>
<IncludeBuildOutput>false</IncludeBuildOutput>
<!-- forces SDK to copy dependencies into build output to make packing easier -->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PackageDescription>Produces DI registration for both property and constructor injection using the Splat locators.</PackageDescription>
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);PackBuildOutputs</TargetsForTfmSpecificContentInPackage>
<NoWarn>$(NoWarn);AD0001</NoWarn>
<BuildOutputTargetFolder>analyzers</BuildOutputTargetFolder>
<GetTargetPathDependsOn>$(GetTargetPathDependsOn);GetDependencyTargetPaths</GetTargetPathDependsOn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.8.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2" PrivateAssets="all" />
<PackageReference Include="ReactiveMarbles.RoslynHelpers" Version="1.0.9" PrivateAssets="all" />
<PackageReference Include="ReactiveMarbles.RoslynHelpers" GeneratePathProperty="true" Version="1.0.9" PrivateAssets="all" />
</ItemGroup>

<Target Name="PackBuildOutputs">
<PropertyGroup>
</PropertyGroup>

<Target Name="GetDependencyTargetPaths">
<ItemGroup>
<TfmSpecificPackageFile Include="$(OutputPath)\**\*" PackagePath="analyzers/dotnet/cs" Visible="false" />
<TargetPathWithTargetPlatformMoniker Include="$(PKGReactiveMarbles_RoslynHelpers)\lib\netstandard2.0\ReactiveMarbles.RoslynHelpers.dll" IncludeRuntimeDependency="false" />
</ItemGroup>
</Target>
</Project>