|
3 | 3 | using Microsoft.CodeAnalysis.CSharp; |
4 | 4 | using Microsoft.CodeAnalysis.CSharp.Syntax; |
5 | 5 | using Riok.Mapperly.Configuration; |
6 | | -using Riok.Mapperly.Configuration.MethodReferences; |
7 | 6 | using Riok.Mapperly.Descriptors.MappingBodyBuilders.BuilderContext; |
8 | 7 | using Riok.Mapperly.Descriptors.Mappings; |
9 | 8 | using Riok.Mapperly.Descriptors.Mappings.MemberMappings; |
@@ -160,20 +159,25 @@ private static bool TryBuildMethodProvidedSourceValue( |
160 | 159 | var methodReferenceConfiguration = memberMappingInfo.ValueConfiguration!.Use!; |
161 | 160 | var targetSymbol = methodReferenceConfiguration.GetTargetType(ctx.BuilderContext); |
162 | 161 | var scope = ctx.BuilderContext.ParameterScope; |
163 | | - var namedMethodCandidates = targetSymbol is null |
| 162 | + var allNamedMethods = targetSymbol is null |
164 | 163 | ? [] |
165 | 164 | : ctx |
166 | 165 | .BuilderContext.SymbolAccessor.GetAllDirectlyAccessibleMethods(targetSymbol) |
167 | 166 | .Where(m => |
168 | 167 | m is { IsAsync: false, ReturnsVoid: false, IsGenericMethod: false } |
169 | | - && scope.CanMatchParameters(m) |
170 | 168 | && ctx.BuilderContext.AttributeAccessor.IsMappingNameEqualTo(m, methodReferenceConfiguration.Name) |
171 | 169 | ) |
172 | 170 | .ToList(); |
173 | 171 |
|
| 172 | + var namedMethodCandidates = allNamedMethods.Where(m => scope.CanMatchParameters(m)).ToList(); |
| 173 | + |
174 | 174 | if (namedMethodCandidates.Count == 0) |
175 | 175 | { |
176 | | - ReportMethodNotFoundDiagnostic(ctx.BuilderContext, targetSymbol, methodReferenceConfiguration); |
| 176 | + var descriptor = |
| 177 | + allNamedMethods.Count > 0 |
| 178 | + ? DiagnosticDescriptors.MapValueMethodParametersUnsatisfied |
| 179 | + : DiagnosticDescriptors.MapValueReferencedMethodNotFound; |
| 180 | + ctx.BuilderContext.ReportDiagnostic(descriptor, methodReferenceConfiguration.FullName); |
177 | 181 | sourceValue = null; |
178 | 182 | return false; |
179 | 183 | } |
@@ -215,29 +219,4 @@ private static bool TryBuildMethodProvidedSourceValue( |
215 | 219 | ); |
216 | 220 | return true; |
217 | 221 | } |
218 | | - |
219 | | - private static void ReportMethodNotFoundDiagnostic( |
220 | | - MappingBuilderContext builderCtx, |
221 | | - ITypeSymbol? targetSymbol, |
222 | | - IMethodReferenceConfiguration methodRef |
223 | | - ) |
224 | | - { |
225 | | - // Check if a method by name exists but with unsatisfiable parameters |
226 | | - if ( |
227 | | - targetSymbol is not null |
228 | | - && builderCtx |
229 | | - .SymbolAccessor.GetAllDirectlyAccessibleMethods(targetSymbol) |
230 | | - .Any(m => |
231 | | - m is { IsAsync: false, ReturnsVoid: false, IsGenericMethod: false, Parameters.Length: > 0 } |
232 | | - && builderCtx.AttributeAccessor.IsMappingNameEqualTo(m, methodRef.Name) |
233 | | - ) |
234 | | - ) |
235 | | - { |
236 | | - builderCtx.ReportDiagnostic(DiagnosticDescriptors.MapValueMethodParametersUnsatisfied, methodRef.FullName); |
237 | | - } |
238 | | - else |
239 | | - { |
240 | | - builderCtx.ReportDiagnostic(DiagnosticDescriptors.MapValueReferencedMethodNotFound, methodRef.FullName); |
241 | | - } |
242 | | - } |
243 | 222 | } |
0 commit comments