/// <summary> /// Merge given metric with new metric created from parser. /// </summary> /// <param name="resolveOccurrences"></param> /// <param name="metric"></param> /// <param name="parser"></param> /// <returns></returns> private static MetricInfo MergeWithParser(bool resolveOccurrences, MetricInfo metric, SyntaxParser parser) { var metricInfo = new MetricInfo(resolveOccurrences, parser); return(metric.Merge(metricInfo)); }
/// <summary> /// Create MetricInfo which is merged from given parsers. /// </summary> /// <param name="resolveOccurrences"> /// Determine whether info will contains occurrences of nodes related to metric. /// </param> /// <param name="parsers">Parsers to be merged by metric info.</param> /// <returns>Metric info according to parsers.</returns> public static MetricInfo FromParsers(bool resolveOccurrences, params SyntaxParser[] parsers) { if (parsers.Length < 1) { throw new ArgumentException("Needs at least one syntax parser specified"); } var buffer = new MetricInfo(resolveOccurrences, parsers[0]); // merge info for all parsers together for (var i = 1; i < parsers.Length; ++i) { buffer = MergeWithParser(resolveOccurrences, buffer, parsers[i]); } return(buffer); }
/// <summary> /// Create new metric info by merging this info with given other info. /// </summary> /// <param name="other">The other <see cref="MetricInfo" /> object.</param> /// <returns><see cref="MetricInfo" /> merged from two other objects.</returns> public MetricInfo Merge(MetricInfo other) { var commonFiles = includedFiles.Keys.Intersect(other.includedFiles.Keys); if (commonFiles.Count() > 0) { var notIncludedParsers = new Queue <SyntaxParser>(); var notInlcudedFiles = other.includedFiles.Keys.Except(commonFiles); foreach (var file in notInlcudedFiles) { notIncludedParsers.Enqueue(other.includedFiles[file]); } other = FromParsers(other.HasResolvedOccurrences, notIncludedParsers.ToArray()); } var resultIndicators = ProcessingServices.MergeIndicators(indicatorBatch, other.indicatorBatch); var resultRatings = ProcessingServices.MergeRatings(ratingBatch, other.ratingBatch); var resultQuantities = ProcessingServices.MergeQuantities(quantityBatch, other.quantityBatch); var includedParsers = includedFiles.Values.Union(other.includedFiles.Values); return(new MetricInfo(resultIndicators, resultRatings, resultQuantities, includedParsers, HasResolvedOccurrences && other.HasResolvedOccurrences)); }