-
-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add RMG072 and RMG073 diagnostics for named existing target map…
…pings
- Loading branch information
Showing
7 changed files
with
338 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...Riok.Mapperly/Descriptors/Mappings/MemberMappings/CompositeMemberExistingTargetMapping.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using Riok.Mapperly.Descriptors.Mappings.ExistingTarget; | ||
using Riok.Mapperly.Symbols.Members; | ||
|
||
namespace Riok.Mapperly.Descriptors.Mappings.MemberMappings; | ||
|
||
/// <summary> | ||
/// Creates a composite mapping for existing target | ||
/// <code> | ||
/// OutputMapping(SourceMapping(source), TargetMapping(target)); | ||
/// </code> | ||
/// </summary> | ||
public class CompositeMemberExistingTargetMapping( | ||
IExistingTargetMapping delegateMapping, | ||
INewInstanceMapping sourceMapping, | ||
MemberPathGetter sourcePath, | ||
INewInstanceMapping targetMapping, | ||
MemberPathGetter targetPath, | ||
MemberMappingInfo memberInfo | ||
) : IMemberAssignmentMapping | ||
{ | ||
public MemberMappingInfo MemberInfo { get; } = memberInfo; | ||
|
||
public IEnumerable<StatementSyntax> Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) | ||
{ | ||
var sourcePathAccess = sourcePath.BuildAccess(ctx.Source); | ||
var source = sourceMapping.Build(ctx.WithSource(sourcePathAccess)); | ||
|
||
var targetPathAccess = targetPath.BuildAccess(targetAccess); | ||
var target = targetMapping.Build(ctx.WithSource(targetPathAccess)); | ||
|
||
return delegateMapping.Build(ctx.WithSource(source), target); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...pingTest.UserImplementedExistingTargetMappingWithDifferentSourceType#Mapper.g.verified.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//HintName: Mapper.g.cs | ||
// <auto-generated /> | ||
#nullable enable | ||
public partial class Mapper | ||
{ | ||
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")] | ||
public partial void Map(global::A source, global::B target) | ||
{ | ||
MapValues(MapToF(source.Value), target.Value); | ||
} | ||
|
||
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")] | ||
private global::F MapToF(global::C source) | ||
{ | ||
var target = new global::F(); | ||
target.Values = source.Values; | ||
return target; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...NamedMappingTest.UserImplementedExistingTargetMappingWithDifferentSourceType.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
Diagnostics: [ | ||
{ | ||
Location: /* | ||
{ | ||
[MapProperty(nameof(A.Value), nameof(B.Value), Use = "MapValues")] | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
public partial void Map(A source, B target); | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
private void MapValues(F source, D target) {} | ||
*/ | ||
: (11,4)-(12,44), | ||
Message: The source type F of the referenced mapping MapValues does not match the expected type C, | ||
Severity: Warning, | ||
WarningLevel: 1, | ||
Descriptor: { | ||
Id: RMG072, | ||
Title: The source type of the referenced mapping does not match, | ||
MessageFormat: The source type {1} of the referenced mapping {0} does not match the expected type {2}, | ||
Category: Mapper, | ||
DefaultSeverity: Warning, | ||
IsEnabledByDefault: true | ||
} | ||
} | ||
] | ||
} |
19 changes: 19 additions & 0 deletions
19
...pingTest.UserImplementedExistingTargetMappingWithDifferentTargetType#Mapper.g.verified.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//HintName: Mapper.g.cs | ||
// <auto-generated /> | ||
#nullable enable | ||
public partial class Mapper | ||
{ | ||
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")] | ||
public partial void Map(global::A source, global::B target) | ||
{ | ||
MapValues(source.Value, MapToF(target.Value)); | ||
} | ||
|
||
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")] | ||
private global::F MapToF(global::D source) | ||
{ | ||
var target = new global::F(); | ||
target.Values = source.Values; | ||
return target; | ||
} | ||
} |
Oops, something went wrong.