Add sanity checks for existing remaps, and ambiguous matches during matching
This commit is contained in:
parent
8df90f628a
commit
95ac115306
@ -2,6 +2,7 @@
|
||||
|
||||
public enum ENoMatchReason
|
||||
{
|
||||
AmbiguousMatch,
|
||||
IsEnum,
|
||||
IsNested,
|
||||
IsSealed,
|
||||
|
@ -6,6 +6,7 @@ using ReCodeIt.ReMapper.Search;
|
||||
using ReCodeIt.Utils;
|
||||
using ReCodeItLib.Remapper.Search;
|
||||
using System.Diagnostics;
|
||||
using ReCodeIt.Enums;
|
||||
|
||||
namespace ReCodeIt.ReMapper;
|
||||
|
||||
@ -41,6 +42,8 @@ public class ReCodeItRemapper
|
||||
|
||||
private List<RemapModel> _remaps = [];
|
||||
|
||||
private List<string> _alreadyGivenNames = [];
|
||||
|
||||
/// <summary>
|
||||
/// Start the remapping process
|
||||
/// </summary>
|
||||
@ -60,6 +63,8 @@ public class ReCodeItRemapper
|
||||
|
||||
OutPath = outPath;
|
||||
|
||||
if (!Validate(_remaps)) return;
|
||||
|
||||
IsRunning = true;
|
||||
Stopwatch.Start();
|
||||
|
||||
@ -116,6 +121,29 @@ public class ReCodeItRemapper
|
||||
}
|
||||
}
|
||||
|
||||
private bool Validate(List<RemapModel> remaps)
|
||||
{
|
||||
var duplicateGroups = remaps
|
||||
.GroupBy(m => m.NewTypeName)
|
||||
.Where(g => g.Count() > 1)
|
||||
.ToList();
|
||||
|
||||
if (duplicateGroups.Count() > 1)
|
||||
{
|
||||
Logger.Log($"There were {duplicateGroups.Count()} duplicated sets of remaps.", ConsoleColor.Yellow);
|
||||
|
||||
foreach (var duplicate in duplicateGroups)
|
||||
{
|
||||
var duplicateNewTypeName = duplicate.Key;
|
||||
Logger.Log($"Ambiguous NewTypeName: {duplicateNewTypeName} found. Cancelling Remap.", ConsoleColor.Red);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// First we filter our type collection based on simple search parameters (true/false/null)
|
||||
/// where null is a third disabled state. Then we score the types based on the search parameters
|
||||
@ -192,6 +220,21 @@ public class ReCodeItRemapper
|
||||
|
||||
if (winner is null) { return; }
|
||||
|
||||
if (_alreadyGivenNames.Contains(winner.FullName))
|
||||
{
|
||||
Logger.Log("----------------------------------------------------------------------", ConsoleColor.Red);
|
||||
Logger.Log("Ambiguous match with a previous match during matching. Skipping remap.", ConsoleColor.Red);
|
||||
Logger.Log($"Ambiguous match: {winner.FullName}");
|
||||
Logger.Log("----------------------------------------------------------------------", ConsoleColor.Red);
|
||||
|
||||
remap.NoMatchReasons.Add(ENoMatchReason.AmbiguousMatch);
|
||||
remap.Succeeded = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_alreadyGivenNames.Add(winner.FullName);
|
||||
|
||||
remap.Succeeded = true;
|
||||
|
||||
remap.OriginalTypeName = winner.Name.String;
|
||||
|
Loading…
x
Reference in New Issue
Block a user