-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: globalize many using directives or force all (#71)
normalizes arguments with count command fixes duplicate globalizations Co-Authored-By: Eva Ditzelmüller <87754804+EvaDitzelmueller@users.noreply.github.com>
- Loading branch information
1 parent
3a474f7
commit 2769f56
Showing
9 changed files
with
574 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 61 additions & 5 deletions
66
src/libraries/FlashOWare.Tool.Core/UsingDirectives/UsingGlobalizationResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,79 @@ | ||
using Microsoft.CodeAnalysis; | ||
using System.Collections.Immutable; | ||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace FlashOWare.Tool.Core.UsingDirectives; | ||
|
||
public sealed class UsingGlobalizationResult | ||
{ | ||
internal UsingGlobalizationResult() | ||
private readonly Dictionary<string, UsingDirective> _usings = new(); | ||
|
||
internal UsingGlobalizationResult(Project project) | ||
{ | ||
Project = project; | ||
} | ||
|
||
[SetsRequiredMembers] | ||
internal UsingGlobalizationResult(Project project, UsingDirective @using, string targetDocument) | ||
internal UsingGlobalizationResult(Project project, string targetDocument) | ||
{ | ||
Project = project; | ||
Using = @using; | ||
TargetDocument = targetDocument; | ||
} | ||
|
||
public required Project Project { get; init; } | ||
public required UsingDirective Using { get; init; } | ||
public Project Project { get; private set; } | ||
public IReadOnlyCollection<UsingDirective> Usings => _usings.Values; | ||
public required string TargetDocument { get; init; } | ||
public int Occurrences { get; private set; } | ||
|
||
internal void Initialize(ImmutableArray<string> identifiers) | ||
{ | ||
Debug.Assert(Occurrences == 0, $"Result has already been updated."); | ||
Debug.Assert(_usings.Count == 0, $"Result has already been initialized."); | ||
|
||
foreach (string identifier in identifiers) | ||
{ | ||
_ = _usings.TryAdd(identifier, new UsingDirective(identifier)); | ||
} | ||
} | ||
|
||
internal void Update(Project project) | ||
{ | ||
Project = project; | ||
} | ||
|
||
internal void Update(string identifier) | ||
{ | ||
if (_usings.TryGetValue(identifier, out UsingDirective? usingDirective)) | ||
{ | ||
usingDirective.IncrementOccurrences(); | ||
} | ||
else | ||
{ | ||
usingDirective = new UsingDirective(identifier, 1); | ||
_usings.Add(identifier, usingDirective); | ||
} | ||
|
||
Occurrences++; | ||
} | ||
|
||
internal void Update(string[] identifiers) | ||
{ | ||
foreach (var identifier in identifiers) | ||
{ | ||
Update(identifier); | ||
} | ||
} | ||
|
||
[Conditional("DEBUG")] | ||
internal void Verify() | ||
{ | ||
int occurrences = _usings.Values.Aggregate(0, static (sum, directive) => sum + directive.Occurrences); | ||
Debug.Assert(occurrences == Occurrences, $"Verification of {nameof(UsingGlobalizationResult)} failed: {nameof(Occurrences)}={Occurrences} Aggregate={occurrences}"); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return Project.Name; | ||
} | ||
} |
Oops, something went wrong.