From 6e7ac7e59ad6d35f8cbf894997073b995f988a4b Mon Sep 17 00:00:00 2001 From: Cj <161484149+CJ-SPT@users.noreply.github.com> Date: Fri, 28 Jun 2024 18:38:03 -0400 Subject: [PATCH] Better ambiguous match handling --- RecodeItLib/Enums/ENoMatchReason.cs | 3 +- RecodeItLib/Models/RemapModel.cs | 2 + RecodeItLib/Remapper/ReCodeItRemapper.cs | 56 +++++++++++++----------- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/RecodeItLib/Enums/ENoMatchReason.cs b/RecodeItLib/Enums/ENoMatchReason.cs index 361e560..0e0c975 100644 --- a/RecodeItLib/Enums/ENoMatchReason.cs +++ b/RecodeItLib/Enums/ENoMatchReason.cs @@ -2,7 +2,8 @@ public enum ENoMatchReason { - AmbiguousMatch, + AmbiguousWithPreviousMatch, + AmbiguousNewTypeNames, IsEnum, IsNested, IsSealed, diff --git a/RecodeItLib/Models/RemapModel.cs b/RecodeItLib/Models/RemapModel.cs index 72ae48a..78a0fc7 100644 --- a/RecodeItLib/Models/RemapModel.cs +++ b/RecodeItLib/Models/RemapModel.cs @@ -15,6 +15,8 @@ public class RemapModel [JsonIgnore] public List NoMatchReasons { get; set; } = []; + [JsonIgnore] public string AmbiguousTypeMatch { get; set; } = string.Empty; + /// /// This is a list of type candidates that made it through the filter /// diff --git a/RecodeItLib/Remapper/ReCodeItRemapper.cs b/RecodeItLib/Remapper/ReCodeItRemapper.cs index 4209913..55d877f 100644 --- a/RecodeItLib/Remapper/ReCodeItRemapper.cs +++ b/RecodeItLib/Remapper/ReCodeItRemapper.cs @@ -222,12 +222,8 @@ public class ReCodeItRemapper 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.NoMatchReasons.Add(ENoMatchReason.AmbiguousWithPreviousMatch); + remap.AmbiguousTypeMatch = winner.FullName; remap.Succeeded = false; return; @@ -307,10 +303,33 @@ public class ReCodeItRemapper { var failures = 0; var changes = 0; - + + Logger.Log("-----------------------------------------------", ConsoleColor.Green); + Logger.Log("-----------------------------------------------", ConsoleColor.Green); + 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($"Renaming {remap.NewTypeName} failed with reason(s)", ConsoleColor.Red); @@ -324,29 +343,14 @@ public class ReCodeItRemapper failures++; continue; } - + 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($"Result renamed {changes} Types. Failed to rename {failures} Types", ConsoleColor.Green); - + if (!validate) { Logger.Log($"Assembly written to `{OutPath}`", ConsoleColor.Green);