Better ambiguous match handling

This commit is contained in:
Cj 2024-06-28 18:38:03 -04:00
parent 427db1ce5a
commit 6e7ac7e59a
3 changed files with 34 additions and 27 deletions

View File

@ -2,7 +2,8 @@
public enum ENoMatchReason public enum ENoMatchReason
{ {
AmbiguousMatch, AmbiguousWithPreviousMatch,
AmbiguousNewTypeNames,
IsEnum, IsEnum,
IsNested, IsNested,
IsSealed, IsSealed,

View File

@ -15,6 +15,8 @@ public class RemapModel
[JsonIgnore] [JsonIgnore]
public List<ENoMatchReason> NoMatchReasons { get; set; } = []; public List<ENoMatchReason> NoMatchReasons { get; set; } = [];
[JsonIgnore] public string AmbiguousTypeMatch { get; set; } = string.Empty;
/// <summary> /// <summary>
/// This is a list of type candidates that made it through the filter /// This is a list of type candidates that made it through the filter
/// </summary> /// </summary>

View File

@ -222,12 +222,8 @@ public class ReCodeItRemapper
if (_alreadyGivenNames.Contains(winner.FullName)) if (_alreadyGivenNames.Contains(winner.FullName))
{ {
Logger.Log("----------------------------------------------------------------------", ConsoleColor.Red); remap.NoMatchReasons.Add(ENoMatchReason.AmbiguousWithPreviousMatch);
Logger.Log("Ambiguous match with a previous match during matching. Skipping remap.", ConsoleColor.Red); remap.AmbiguousTypeMatch = winner.FullName;
Logger.Log($"Ambiguous match: {winner.FullName}");
Logger.Log("----------------------------------------------------------------------", ConsoleColor.Red);
remap.NoMatchReasons.Add(ENoMatchReason.AmbiguousMatch);
remap.Succeeded = false; remap.Succeeded = false;
return; return;
@ -308,9 +304,32 @@ public class ReCodeItRemapper
var failures = 0; var failures = 0;
var changes = 0; var changes = 0;
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
foreach (var remap in _remaps) foreach (var remap in _remaps)
{ {
if (remap.Succeeded is false) if (remap.Succeeded is false) { continue; }
var original = remap.OriginalTypeName;
var proposed = remap.NewTypeName;
Logger.Log($"Renamed {original} to {proposed}", ConsoleColor.Green);
DisplayAlternativeMatches(remap);
}
foreach (var remap in _remaps)
{
if (remap.Succeeded is false && remap.NoMatchReasons.Contains(ENoMatchReason.AmbiguousWithPreviousMatch))
{
Logger.Log("----------------------------------------------------------------------", ConsoleColor.Red);
Logger.Log("Ambiguous match with a previous match during matching. Skipping remap.", ConsoleColor.Red);
Logger.Log($"New Type Name: {remap.NewTypeName}", ConsoleColor.Red);
Logger.Log($"{remap.AmbiguousTypeMatch} already assigned to a previous match.", ConsoleColor.Red);
Logger.Log("----------------------------------------------------------------------", ConsoleColor.Red);
}
else if (remap.Succeeded is false)
{ {
Logger.Log("-----------------------------------------------", ConsoleColor.Red); Logger.Log("-----------------------------------------------", ConsoleColor.Red);
Logger.Log($"Renaming {remap.NewTypeName} failed with reason(s)", ConsoleColor.Red); Logger.Log($"Renaming {remap.NewTypeName} failed with reason(s)", ConsoleColor.Red);
@ -328,21 +347,6 @@ public class ReCodeItRemapper
changes++; changes++;
} }
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
foreach (var remap in _remaps)
{
if (remap.Succeeded is false) { continue; }
var original = remap.OriginalTypeName;
var proposed = remap.NewTypeName;
Logger.Log($"Renamed {original} to {proposed}", ConsoleColor.Green);
DisplayAlternativeMatches(remap);
}
Logger.Log("-----------------------------------------------", ConsoleColor.Green); Logger.Log("-----------------------------------------------", ConsoleColor.Green);
Logger.Log("-----------------------------------------------", ConsoleColor.Green); Logger.Log("-----------------------------------------------", ConsoleColor.Green);
Logger.Log($"Result renamed {changes} Types. Failed to rename {failures} Types", ConsoleColor.Green); Logger.Log($"Result renamed {changes} Types. Failed to rename {failures} Types", ConsoleColor.Green);