diff options
author | Rodrigo Moya <rodrigo.moya@xamarin.com> | 2019-06-24 19:55:48 +0300 |
---|---|---|
committer | Rodrigo Moya <rodrigo.moya@xamarin.com> | 2019-07-01 11:31:36 +0300 |
commit | 31dca318663a77fe5719f34349aa37a9ddeb99e0 (patch) | |
tree | b3ee3ba1bb53cecd5313afa4e4916f0b60297ff5 /main/src/core/MonoDevelop.Core | |
parent | c49f90901ed755db4c7328f2ac9a25c6eb597e8b (diff) |
[Projects] Pass Project to FileNestingService
Thus, we can just check inside the project's Files collection, instead
of calling File.Exists().
Diffstat (limited to 'main/src/core/MonoDevelop.Core')
4 files changed, 14 insertions, 14 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/FileNestingService.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/FileNestingService.cs index 48e5bd286b..ae7da7da54 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/FileNestingService.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/FileNestingService.cs @@ -52,10 +52,10 @@ namespace MonoDevelop.Projects.FileNesting } } - public static FilePath GetParentFile (FilePath inputFile) + public static FilePath GetParentFile (Project project, FilePath inputFile) { foreach (var rp in rulesProviders) { - var parentFile = rp.GetParentFile (inputFile); + var parentFile = rp.GetParentFile (project, inputFile); if (!string.IsNullOrEmpty (parentFile)) { return parentFile; } diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/NestingRule.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/NestingRule.cs index 48b61be3a6..67545fde04 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/NestingRule.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/NestingRule.cs @@ -59,9 +59,9 @@ namespace MonoDevelop.Projects.FileNesting public string AppliesTo { get; private set; } - bool CheckParentForFile (FilePath inputFile, FilePath parentFile) + bool CheckParentForFile (Project project, FilePath inputFile, FilePath parentFile) { - if (File.Exists (parentFile) && inputFile != parentFile) { + if (project.Files.Any (x => x.FilePath == parentFile) && inputFile != parentFile && !parentFile.IsDirectory && inputFile.ParentDirectory == parentFile.ParentDirectory) { LoggingService.LogInfo ($"Applied rule for nesting {inputFile} under {parentFile}"); return true; } @@ -69,7 +69,7 @@ namespace MonoDevelop.Projects.FileNesting return false; } - public FilePath GetParentFile (FilePath inputFile) + public FilePath GetParentFile (Project project, FilePath inputFile) { string parentFile, inputExtension; @@ -80,7 +80,7 @@ namespace MonoDevelop.Projects.FileNesting // This is the simplest rules, and applies to all files, if we find a file // with the same name minus the extension, that's the parent. parentFile = inputFile.ParentDirectory.Combine (inputFile.FileNameWithoutExtension); - if (CheckParentForFile (inputFile, parentFile)) + if (CheckParentForFile (project, inputFile, parentFile)) return parentFile; break; @@ -88,7 +88,7 @@ namespace MonoDevelop.Projects.FileNesting if (AppliesTo == AllFilesWildcard || AppliesTo == inputExtension) { foreach (var pt in patterns) { parentFile = inputFile.ParentDirectory.Combine ($"{Path.GetFileNameWithoutExtension (inputFile)}{pt}"); - if (CheckParentForFile (inputFile, parentFile)) + if (CheckParentForFile (project, inputFile, parentFile)) return parentFile; } } @@ -98,7 +98,7 @@ namespace MonoDevelop.Projects.FileNesting if (inputExtension == AppliesTo) { foreach (var pt in patterns) { parentFile = inputFile.ParentDirectory.Combine ($"{Path.GetFileNameWithoutExtension (inputFile)}{pt}"); - if (CheckParentForFile (inputFile, parentFile)) + if (CheckParentForFile (project, inputFile, parentFile)) return parentFile; } } @@ -110,7 +110,7 @@ namespace MonoDevelop.Projects.FileNesting int suffixPosition = inputFileString.LastIndexOf (AppliesTo, StringComparison.OrdinalIgnoreCase); foreach (var pt in patterns) { parentFile = inputFileString.Remove (suffixPosition, AppliesTo.Length).Insert (suffixPosition, pt); - if (CheckParentForFile (inputFile, parentFile)) { + if (CheckParentForFile (project, inputFile, parentFile)) { return parentFile; } } @@ -121,7 +121,7 @@ namespace MonoDevelop.Projects.FileNesting if (AppliesTo == Path.GetFileName (inputFile)) { foreach (var pt in patterns) { parentFile = inputFile.ParentDirectory.Combine (pt); - if (CheckParentForFile (inputFile, parentFile)) { + if (CheckParentForFile (project, inputFile, parentFile)) { return parentFile; } } @@ -133,7 +133,7 @@ namespace MonoDevelop.Projects.FileNesting foreach (var pt in patterns) { // Search for $filename.$extension for $filename.$path_segment.$extension parentFile = inputFile.ParentDirectory.Combine ($"{Path.GetFileNameWithoutExtension (Path.GetFileNameWithoutExtension (inputFile))}{inputExtension}"); - if (CheckParentForFile (inputFile, parentFile)) { + if (CheckParentForFile (project, inputFile, parentFile)) { return parentFile; } } diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/NestingRulesProvider.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/NestingRulesProvider.cs index e0d53ab7b5..6e8b186fa4 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/NestingRulesProvider.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/NestingRulesProvider.cs @@ -124,7 +124,7 @@ namespace MonoDevelop.Projects.FileNesting return false; } - public FilePath GetParentFile (FilePath inputFile) + public FilePath GetParentFile (Project project, FilePath inputFile) { if (nestingRules == null) { // Create the list here, so that we don't get this path called @@ -142,7 +142,7 @@ namespace MonoDevelop.Projects.FileNesting } foreach (var rule in nestingRules) { - FilePath parentFile = rule.GetParentFile (inputFile); + FilePath parentFile = rule.GetParentFile (project, inputFile); if (!String.IsNullOrEmpty (parentFile)) { // Stop at the 1st rule found return parentFile; diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectFile.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectFile.cs index 56ce86bfcc..d9e7a1960e 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectFile.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectFile.cs @@ -452,7 +452,7 @@ namespace MonoDevelop.Projects } } else { // File nesting - var parentPath = FileNestingService.GetParentFile (Name); + var parentPath = FileNestingService.GetParentFile (Project, Name); dependsOnFile = Project.Files.GetFile (parentPath); if (dependsOnFile != null) { if (dependsOnFile.dependentChildren == null) |