From ca6da56607d4e04afff570aaa88795307e4f4897 Mon Sep 17 00:00:00 2001 From: Rainer Koschke Date: Mon, 16 Sep 2024 15:31:21 +0200 Subject: [PATCH] #726 Node-type names used in more than one class must reside in Standard_Names. Avoid magic strings (and their duplicates). --- Assets/SEE/DataModel/DG/StandardNames.cs | 15 ++++++++++++ .../CityRendering/AuthorSphereRenderer.cs | 2 +- .../AllGitBranchesSingleGraphProvider.cs | 2 +- .../Evolution/GitEvolutionGraphProvider.cs | 2 +- Assets/SEE/GraphProviders/VCS/GraphUtils.cs | 23 ++----------------- 5 files changed, 20 insertions(+), 24 deletions(-) diff --git a/Assets/SEE/DataModel/DG/StandardNames.cs b/Assets/SEE/DataModel/DG/StandardNames.cs index a021b57854..1d13de5ca4 100644 --- a/Assets/SEE/DataModel/DG/StandardNames.cs +++ b/Assets/SEE/DataModel/DG/StandardNames.cs @@ -261,6 +261,7 @@ public static class VCS /// Prefix for VCS metrics. /// public const string Prefix = Metrics.Prefix + VCSPrefix; + /// /// The number of lines of code added for a file that was changed between two commits. /// @@ -285,12 +286,26 @@ public static class VCS /// The truck factor of a file (core-devs metric). /// public const string TruckNumber = Prefix + "Truck_Number"; + /// /// String attribute for the list of authors of a file. /// /// Note that this is not actually a numeric metric but a list of /// author names seperated by a comma. public const string AuthorAttributeName = VCSPrefix + "Authors"; + + /// + /// Name of node type used for files. + /// + public const string FileType = "File"; + /// + /// Name of node type used for directories. + /// + public const string DirectoryType = "Directory"; + /// + /// Name of node type used for repositories. + /// + public const string RepositoryType = "Repository"; } /// diff --git a/Assets/SEE/Game/CityRendering/AuthorSphereRenderer.cs b/Assets/SEE/Game/CityRendering/AuthorSphereRenderer.cs index 1748866140..93a275df8a 100644 --- a/Assets/SEE/Game/CityRendering/AuthorSphereRenderer.cs +++ b/Assets/SEE/Game/CityRendering/AuthorSphereRenderer.cs @@ -35,7 +35,7 @@ public partial class GraphRenderer public void DrawAuthorSpheres(IDictionary nodeMap, GameObject parent) { List authors = - nodeMap.Keys.Where(x => x.Type == "file") + nodeMap.Keys.Where(x => x.Type == DataModel.DG.VCS.FileType) .SelectMany(x => x.StringAttributes.Where(y => y.Key == DataModel.DG.VCS.AuthorAttributeName)) .SelectMany(x => x.Value.Split(",")) .Distinct() diff --git a/Assets/SEE/GraphProviders/AllGitBranchesSingleGraphProvider.cs b/Assets/SEE/GraphProviders/AllGitBranchesSingleGraphProvider.cs index 49a7da394d..5c4bb57ba4 100644 --- a/Assets/SEE/GraphProviders/AllGitBranchesSingleGraphProvider.cs +++ b/Assets/SEE/GraphProviders/AllGitBranchesSingleGraphProvider.cs @@ -195,7 +195,7 @@ private Graph GetGraph(Graph graph, Action changePercentage, BranchCity b string repositoryName = Filenames.InnermostDirectoryName(repositoryPath); - GraphUtils.NewNode(graph, repositoryName, GraphUtils.RepositoryTypeName, repositoryName); + GraphUtils.NewNode(graph, repositoryName, DataModel.DG.VCS.RepositoryType, repositoryName); // Assuming that CheckAttributes() was already executed so that the date string is neither empty nor malformed. DateTime timeLimit = DateTime.ParseExact(branchCity.Date, "dd/MM/yyyy", CultureInfo.InvariantCulture); diff --git a/Assets/SEE/GraphProviders/Evolution/GitEvolutionGraphProvider.cs b/Assets/SEE/GraphProviders/Evolution/GitEvolutionGraphProvider.cs index 07f0d13df7..bd7dfd3a5d 100644 --- a/Assets/SEE/GraphProviders/Evolution/GitEvolutionGraphProvider.cs +++ b/Assets/SEE/GraphProviders/Evolution/GitEvolutionGraphProvider.cs @@ -177,7 +177,7 @@ private Graph GetGraphOfCommit(string repoName, Commit currentCommit, List public static class GraphUtils { - #region Contants - - /// - /// Typename used for files. - /// - private const string fileType = "File"; - - /// - /// Typename used for directories. - /// - private const string directoryType = "Directory"; - - /// - /// Typename used for repositories. - /// - public const string RepositoryTypeName = "Repository"; - - #endregion - /// /// Creates and returns a new node to . /// @@ -106,7 +87,7 @@ private static Node GetOrAddNode(string fullRelativePath, string path, Node pare // Create a new file node and return it. Node addedFileNode = NewNode(graph, fullRelativePath + idSuffix, - fileType, path); + DataModel.DG.VCS.FileType, path); addedFileNode.Filename = path; addedFileNode.Directory = fileDir; parent.AddChild(addedFileNode); @@ -126,7 +107,7 @@ private static Node GetOrAddNode(string fullRelativePath, string path, Node pare // Create a new directory node. Node addedDirectoryNode = NewNode(graph, directoryName, - directoryType, directoryName); + DataModel.DG.VCS.DirectoryType, directoryName); addedDirectoryNode.Directory = directoryName; parent.AddChild(addedDirectoryNode); return GetOrAddNode(fullRelativePath, String.Join(Path.AltDirectorySeparatorChar, pathSegments.Skip(1)),