Skip to content

Commit 5876c3a

Browse files
authored
feature: Add locations not null (#15)
1 parent e92ed27 commit 5876c3a

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Splat.DependencyInjection.SourceGenerator/MetadataDependencyChecker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static List<MethodMetadata> CheckMetadata(GeneratorExecutionContext conte
4646
context.ReportDiagnostic(
4747
Diagnostic.Create(
4848
DiagnosticWarnings.ConstructorsMustNotHaveCircularDependency,
49-
childConstructor.Parameter.Locations.FirstOrDefault() ?? metadataMethod.MethodInvocation.GetLocation()));
49+
childConstructor.Parameter.Locations.FirstOrDefault(x => x is not null) ?? metadataMethod.MethodInvocation.GetLocation()));
5050
isError = true;
5151
}
5252
}
@@ -68,7 +68,7 @@ public static List<MethodMetadata> CheckMetadata(GeneratorExecutionContext conte
6868
context.ReportDiagnostic(
6969
Diagnostic.Create(
7070
DiagnosticWarnings.LazyParameterNotRegisteredLazy,
71-
constructorDependency.Parameter.Locations.FirstOrDefault() ?? metadataMethod.MethodInvocation.GetLocation(),
71+
constructorDependency.Parameter.Locations.FirstOrDefault(x => x is not null) ?? metadataMethod.MethodInvocation.GetLocation(),
7272
metadataMethod.ConcreteTypeName,
7373
constructorDependency.Parameter.Name));
7474
isError = true;

src/Splat.DependencyInjection.SourceGenerator/MetadataExtractor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private static IEnumerable<ConstructorDependencyMetadata> GetConstructorDependen
152152
{
153153
if (returnConstructor != null)
154154
{
155-
throw new ContextDiagnosticException(Diagnostic.Create(DiagnosticWarnings.MultipleConstructorsMarked, constructor.Locations.FirstOrDefault(), concreteTarget.ToDisplayString(RoslynCommonHelpers.TypeFormat)));
155+
throw new ContextDiagnosticException(Diagnostic.Create(DiagnosticWarnings.MultipleConstructorsMarked, constructor.Locations.FirstOrDefault(x => x is not null), concreteTarget.ToDisplayString(RoslynCommonHelpers.TypeFormat)));
156156
}
157157

158158
returnConstructor = constructor;
@@ -167,7 +167,7 @@ private static IEnumerable<ConstructorDependencyMetadata> GetConstructorDependen
167167

168168
if (returnConstructor.DeclaredAccessibility < Accessibility.Internal)
169169
{
170-
throw new ContextDiagnosticException(Diagnostic.Create(DiagnosticWarnings.ConstructorsMustBePublic, returnConstructor.Locations.FirstOrDefault(), concreteTarget.ToDisplayString(RoslynCommonHelpers.TypeFormat)));
170+
throw new ContextDiagnosticException(Diagnostic.Create(DiagnosticWarnings.ConstructorsMustBePublic, returnConstructor.Locations.FirstOrDefault(x => x is not null), concreteTarget.ToDisplayString(RoslynCommonHelpers.TypeFormat)));
171171
}
172172

173173
return returnConstructor.Parameters.Select(x => new ConstructorDependencyMetadata(x, x.Type));
@@ -186,7 +186,7 @@ private static IEnumerable<PropertyDependencyMetadata> GetPropertyDependencies(I
186186
{
187187
if (property.SetMethod?.DeclaredAccessibility < Accessibility.Internal)
188188
{
189-
throw new ContextDiagnosticException(Diagnostic.Create(DiagnosticWarnings.PropertyMustPublicBeSettable, property.SetMethod?.Locations.FirstOrDefault(), property.ToDisplayString(RoslynCommonHelpers.TypeFormat)));
189+
throw new ContextDiagnosticException(Diagnostic.Create(DiagnosticWarnings.PropertyMustPublicBeSettable, property.SetMethod?.Locations.FirstOrDefault(x => x is not null), property.ToDisplayString(RoslynCommonHelpers.TypeFormat)));
190190
}
191191

192192
yield return new(property);

0 commit comments

Comments
 (0)