Skip to content

Commit 5a3fc50

Browse files
committed
refactor CoverageColours
1 parent e5517ae commit 5a3fc50

File tree

1 file changed

+11
-57
lines changed

1 file changed

+11
-57
lines changed

SharedProject/Editor/Management/CoverageColours.cs

Lines changed: 11 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ namespace FineCodeCoverage.Editor.Management
55
{
66
internal class CoverageColours : ICoverageColours
77
{
8-
public IFontAndColorsInfo CoverageTouchedInfo { get; }
9-
public IFontAndColorsInfo CoverageNotTouchedInfo { get; }
10-
public IFontAndColorsInfo CoveragePartiallyTouchedInfo { get; }
11-
public IFontAndColorsInfo DirtyInfo { get; }
12-
public IFontAndColorsInfo NewLineInfo { get; }
13-
public IFontAndColorsInfo NotIncludedInfo { get; }
14-
158
private readonly Dictionary<DynamicCoverageType, IFontAndColorsInfo> coverageTypeToFontAndColorsInfo;
169
public CoverageColours(
1710
IFontAndColorsInfo coverageTouchedInfo,
@@ -20,15 +13,7 @@ public CoverageColours(
2013
IFontAndColorsInfo dirtyInfo,
2114
IFontAndColorsInfo newLineInfo,
2215
IFontAndColorsInfo notIncludedInfo
23-
)
24-
{
25-
this.CoverageTouchedInfo = coverageTouchedInfo;
26-
this.CoverageNotTouchedInfo = coverageNotTouchedInfo;
27-
this.CoveragePartiallyTouchedInfo = coveragePartiallyTouchedInfo;
28-
this.DirtyInfo = dirtyInfo;
29-
this.NewLineInfo = newLineInfo;
30-
this.NotIncludedInfo = notIncludedInfo;
31-
this.coverageTypeToFontAndColorsInfo = new Dictionary<DynamicCoverageType, IFontAndColorsInfo>
16+
) => this.coverageTypeToFontAndColorsInfo = new Dictionary<DynamicCoverageType, IFontAndColorsInfo>
3217
{
3318
{ DynamicCoverageType.Covered, coverageTouchedInfo},
3419
{ DynamicCoverageType.NotCovered, coverageNotTouchedInfo },
@@ -37,52 +22,21 @@ IFontAndColorsInfo notIncludedInfo
3722
{ DynamicCoverageType.NewLine, newLineInfo},
3823
{ DynamicCoverageType.NotIncluded, notIncludedInfo}
3924
};
40-
}
4125

42-
internal Dictionary<DynamicCoverageType, IFontAndColorsInfo> GetChanges(CoverageColours lastCoverageColours)
26+
internal Dictionary<DynamicCoverageType, IFontAndColorsInfo> GetChanges(CoverageColours lastCoverageColours)
27+
=> lastCoverageColours == null
28+
? this.coverageTypeToFontAndColorsInfo
29+
: this.GetChanges(lastCoverageColours.coverageTypeToFontAndColorsInfo);
30+
31+
private Dictionary<DynamicCoverageType, IFontAndColorsInfo> GetChanges(Dictionary<DynamicCoverageType, IFontAndColorsInfo> lastCoverageTypeToFontAndColorsInfo)
4332
{
4433
var changes = new Dictionary<DynamicCoverageType, IFontAndColorsInfo>();
45-
if (lastCoverageColours == null)
34+
foreach (KeyValuePair<DynamicCoverageType, IFontAndColorsInfo> kvp in lastCoverageTypeToFontAndColorsInfo)
4635
{
47-
return new Dictionary<DynamicCoverageType, IFontAndColorsInfo>
36+
if (!this.coverageTypeToFontAndColorsInfo[kvp.Key].Equals(kvp.Value))
4837
{
49-
{ DynamicCoverageType.Covered, this.CoverageTouchedInfo},
50-
{ DynamicCoverageType.NotCovered, this.CoverageNotTouchedInfo },
51-
{ DynamicCoverageType.Partial, this.CoveragePartiallyTouchedInfo},
52-
{ DynamicCoverageType.Dirty, this.DirtyInfo},
53-
{ DynamicCoverageType.NewLine, this.NewLineInfo},
54-
{ DynamicCoverageType.NotIncluded, this.NotIncludedInfo}
55-
};
56-
}
57-
58-
if (!this.CoverageTouchedInfo.Equals(lastCoverageColours.CoverageTouchedInfo))
59-
{
60-
changes.Add(DynamicCoverageType.Covered, this.CoverageTouchedInfo);
61-
}
62-
63-
if (!this.CoverageNotTouchedInfo.Equals(lastCoverageColours.CoverageNotTouchedInfo))
64-
{
65-
changes.Add(DynamicCoverageType.NotCovered, this.CoverageNotTouchedInfo);
66-
}
67-
68-
if (!this.CoveragePartiallyTouchedInfo.Equals(lastCoverageColours.CoveragePartiallyTouchedInfo))
69-
{
70-
changes.Add(DynamicCoverageType.Partial, this.CoveragePartiallyTouchedInfo);
71-
}
72-
73-
if (!this.DirtyInfo.Equals(lastCoverageColours.DirtyInfo))
74-
{
75-
changes.Add(DynamicCoverageType.Dirty, this.DirtyInfo);
76-
}
77-
78-
if (!this.NewLineInfo.Equals(lastCoverageColours.NewLineInfo))
79-
{
80-
changes.Add(DynamicCoverageType.NewLine, this.NewLineInfo);
81-
}
82-
83-
if (!this.NotIncludedInfo.Equals(lastCoverageColours.NotIncludedInfo))
84-
{
85-
changes.Add(DynamicCoverageType.NotIncluded, this.NotIncludedInfo);
38+
changes.Add(kvp.Key, this.coverageTypeToFontAndColorsInfo[kvp.Key]);
39+
}
8640
}
8741

8842
return changes;

0 commit comments

Comments
 (0)