| | | 1 | | using System; |
| | | 2 | | using System.Collections.Concurrent; |
| | | 3 | | using System.Collections.Generic; |
| | | 4 | | using System.Linq; |
| | | 5 | | using DirectSight.Common; |
| | | 6 | | |
| | | 7 | | namespace DirectSight.Parser.Analysis; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Represents one assembly. |
| | | 11 | | /// </summary> |
| | | 12 | | public class Assembly |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// List of classes in assembly. |
| | | 16 | | /// </summary> |
| | 101 | 17 | | private readonly ConcurrentQueue<Class> classes = new ConcurrentQueue<Class>(); |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Initializes a new instance of the <see cref="Assembly"/> class. |
| | | 21 | | /// </summary> |
| | | 22 | | /// <param name="name">The name of the assembly.</param> |
| | 101 | 23 | | internal Assembly(string name) |
| | 101 | 24 | | { |
| | 101 | 25 | | this.Name = name ?? throw new ArgumentNullException(nameof(name)); |
| | 101 | 26 | | } |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Gets the list of classes in assembly. |
| | | 30 | | /// </summary> |
| | 1162 | 31 | | public IEnumerable<Class> Classes => this.classes.OrderBy(c => c.Name); |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Gets the name of the assembly. |
| | | 35 | | /// </summary> |
| | 2683 | 36 | | public string Name { get; } |
| | | 37 | | |
| | | 38 | | /// <summary> |
| | | 39 | | /// Gets the short name of the assembly. |
| | | 40 | | /// </summary> |
| | | 41 | | /// <value>The short name of the assembly.</value> |
| | | 42 | | public string ShortName |
| | | 43 | | { |
| | | 44 | | get |
| | 181 | 45 | | { |
| | 181 | 46 | | string shortName = this.Name; |
| | 181 | 47 | | return shortName.Substring(shortName.LastIndexOf('/') + 1); |
| | 181 | 48 | | } |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Gets the number of covered lines. |
| | | 53 | | /// </summary> |
| | | 54 | | /// <value>The covered lines.</value> |
| | 874 | 55 | | public int CoveredLines => this.classes.SafeSum(c => c.CoveredLines); |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// Gets the number of coverable lines. |
| | | 59 | | /// </summary> |
| | | 60 | | /// <value>The coverable lines.</value> |
| | 1406 | 61 | | public int CoverableLines => this.classes.SafeSum(c => c.CoverableLines); |
| | | 62 | | |
| | | 63 | | /// <summary> |
| | | 64 | | /// Gets the number of total lines. |
| | | 65 | | /// </summary> |
| | | 66 | | /// <value>The total lines.</value> |
| | 114 | 67 | | public int? TotalLines => this.classes.SafeSum(c => c.TotalLines); |
| | | 68 | | |
| | | 69 | | /// <summary> |
| | | 70 | | /// Gets the coverage quota of the class. |
| | | 71 | | /// </summary> |
| | | 72 | | /// <value>The coverage quota.</value> |
| | 12 | 73 | | public decimal? CoverageQuota => (this.CoverableLines == 0) ? (decimal?)null : MathExtensions.CalculatePercentage(th |
| | | 74 | | |
| | | 75 | | /// <summary> |
| | | 76 | | /// Gets the number of covered branches. |
| | | 77 | | /// </summary> |
| | | 78 | | /// <value> |
| | | 79 | | /// The number of covered branches. |
| | | 80 | | /// </value> |
| | 874 | 81 | | public int? CoveredBranches => this.classes.SafeSum(f => f.CoveredBranches); |
| | | 82 | | |
| | | 83 | | /// <summary> |
| | | 84 | | /// Gets the number of total branches. |
| | | 85 | | /// </summary> |
| | | 86 | | /// <value> |
| | | 87 | | /// The number of total branches. |
| | | 88 | | /// </value> |
| | 1406 | 89 | | public int? TotalBranches => this.classes.SafeSum(f => f.TotalBranches); |
| | | 90 | | |
| | | 91 | | /// <summary> |
| | | 92 | | /// Gets the branch coverage quota of the class. |
| | | 93 | | /// </summary> |
| | | 94 | | /// <value>The branch coverage quota.</value> |
| | 12 | 95 | | public decimal? BranchCoverageQuota => (this.TotalBranches == 0) ? (decimal?)null : MathExtensions.CalculatePercenta |
| | | 96 | | |
| | | 97 | | /// <summary> |
| | | 98 | | /// Gets the number of covered code elements. |
| | | 99 | | /// </summary> |
| | | 100 | | /// <value> |
| | | 101 | | /// The number of covered code elements. |
| | | 102 | | /// </value> |
| | 228 | 103 | | public int CoveredCodeElements => this.classes.SafeSum(f => f.CoveredCodeElements); |
| | | 104 | | |
| | | 105 | | /// <summary> |
| | | 106 | | /// Gets the number of fully covered code elements. |
| | | 107 | | /// </summary> |
| | | 108 | | /// <value> |
| | | 109 | | /// The number of fully covered code elements. |
| | | 110 | | /// </value> |
| | 228 | 111 | | public int FullCoveredCodeElements => this.classes.SafeSum(f => f.FullCoveredCodeElements); |
| | | 112 | | |
| | | 113 | | /// <summary> |
| | | 114 | | /// Gets the number of total code elements. |
| | | 115 | | /// </summary> |
| | | 116 | | /// <value> |
| | | 117 | | /// The number of total code elements. |
| | | 118 | | /// </value> |
| | 684 | 119 | | public int TotalCodeElements => this.classes.SafeSum(f => f.TotalCodeElements); |
| | | 120 | | |
| | | 121 | | /// <summary> |
| | | 122 | | /// Gets the code elements coverage quota. |
| | | 123 | | /// </summary> |
| | | 124 | | /// <value>The code elements coverage quota.</value> |
| | 4 | 125 | | public decimal? CodeElementCoverageQuota => (this.TotalCodeElements == 0) ? (decimal?)null : MathExtensions.Calculat |
| | | 126 | | |
| | | 127 | | /// <summary> |
| | | 128 | | /// Gets the full code elements coverage quota. |
| | | 129 | | /// </summary> |
| | | 130 | | /// <value>The full code elements coverage quota.</value> |
| | 4 | 131 | | public decimal? FullCodeElementCoverageQuota => (this.TotalCodeElements == 0) ? (decimal?)null : MathExtensions.Calc |
| | | 132 | | |
| | | 133 | | /// <summary> |
| | | 134 | | /// Returns a <see cref="string" /> that represents this instance. |
| | | 135 | | /// </summary> |
| | | 136 | | /// <returns> |
| | | 137 | | /// A <see cref="string" /> that represents this instance. |
| | | 138 | | /// </returns> |
| | | 139 | | public override string ToString() |
| | 0 | 140 | | { |
| | 0 | 141 | | return this.Name; |
| | 0 | 142 | | } |
| | | 143 | | |
| | | 144 | | /// <summary> |
| | | 145 | | /// Determines whether the specified <see cref="object"/> is equal to this instance. |
| | | 146 | | /// </summary> |
| | | 147 | | /// <param name="obj">The <see cref="object"/> to compare with this instance.</param> |
| | | 148 | | /// <returns> |
| | | 149 | | /// <c>true</c> if the specified <see cref="object"/> is equal to this instance; otherwise, <c>false</c>. |
| | | 150 | | /// </returns> |
| | | 151 | | public override bool Equals(object obj) |
| | 375 | 152 | | { |
| | 375 | 153 | | if (obj == null || !obj.GetType().Equals(typeof(Assembly))) |
| | 2 | 154 | | { |
| | 2 | 155 | | return false; |
| | | 156 | | } |
| | | 157 | | else |
| | 373 | 158 | | { |
| | 373 | 159 | | var assembly = (Assembly)obj; |
| | 373 | 160 | | return assembly.Name.Equals(this.Name); |
| | | 161 | | } |
| | 375 | 162 | | } |
| | | 163 | | |
| | | 164 | | /// <summary> |
| | | 165 | | /// Returns a hash code for this instance. |
| | | 166 | | /// </summary> |
| | | 167 | | /// <returns> |
| | | 168 | | /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. |
| | | 169 | | /// </returns> |
| | 0 | 170 | | public override int GetHashCode() => this.Name.GetHashCode(); |
| | | 171 | | |
| | | 172 | | /// <summary> |
| | | 173 | | /// Adds the given class to the assembly. |
| | | 174 | | /// </summary> |
| | | 175 | | /// <param name="class">The class to add.</param> |
| | | 176 | | internal void AddClass(Class @class) |
| | 1472 | 177 | | { |
| | 1472 | 178 | | this.classes.Enqueue(@class); |
| | 1472 | 179 | | } |
| | | 180 | | |
| | | 181 | | /// <summary> |
| | | 182 | | /// Merges the given assembly with the current instance. |
| | | 183 | | /// </summary> |
| | | 184 | | /// <param name="assembly">The assembly to merge.</param> |
| | | 185 | | internal void Merge(Assembly assembly) |
| | 24 | 186 | | { |
| | 24 | 187 | | if (assembly == null) |
| | 0 | 188 | | { |
| | 0 | 189 | | throw new ArgumentNullException(nameof(assembly)); |
| | | 190 | | } |
| | | 191 | | |
| | 814 | 192 | | foreach (var @class in assembly.classes) |
| | 371 | 193 | | { |
| | 3596 | 194 | | var existingClass = this.classes.FirstOrDefault(c => c.Equals(@class)); |
| | | 195 | | |
| | 371 | 196 | | if (existingClass != null) |
| | 370 | 197 | | { |
| | 370 | 198 | | existingClass.Merge(@class); |
| | 370 | 199 | | } |
| | | 200 | | else |
| | 1 | 201 | | { |
| | 1 | 202 | | this.AddClass(@class); |
| | 1 | 203 | | @class.Assembly = this; |
| | 1 | 204 | | } |
| | 371 | 205 | | } |
| | 24 | 206 | | } |
| | | 207 | | } |