Exemplo n.º 1
0
 internal static MetricsReport Of(IEnumerable<MetricsReport> reports)
 {
     var combinedReport = new MetricsReport();
     foreach (var typeMetrics in reports.SelectMany(r => r.typeReports.Values))
         combinedReport.AddTypeReport(typeMetrics);
     return combinedReport;
 }
Exemplo n.º 2
0
 protected void OutputAnalysisMetrics(string heading, MetricsReport metrics)
 {
     var prepared = new PreparedMetricsFactory().Prepare(metrics);
     Console.WriteLine(string.Format("{0} ({1} RLOC):\tACD: {2};\tCS: {3};\tCC: {4};\tML: {5};\tPF: {6};\tCN: {7};",
                                     heading,
                                     prepared.CommonKnowledge.RelevantLinesOfCode,
                                     prepared.Rated.AverageComponentDependency,
                                     prepared.Rated.AverageRatedClassSize,
                                     prepared.Rated.AverageRatedCyclomaticComplexity,
                                     prepared.Rated.AverageRatedMethodLength,
                                     prepared.Rated.AverageRatedNumberOfNonStaticPublicFields,
                                     prepared.Rated.NamespacesWithCyclicDependencies));
     Console.WriteLine(string.Format("Hotspots:\tACD: {0};\tCS: {1};\tCC: {2};\tML: {3};\tPF: {4};\tCN: {5};",
                                     prepared.CumulativeComponentDependencyHotspots.Count(),
                                     prepared.ClassSizeHotspots.Count(),
                                     prepared.CyclomaticComplexityHotspots.Count(),
                                     prepared.MethodLengthHotspots.Count(),
                                     prepared.NumberOfNonStaticPublicFieldsHotspots.Count(),
                                     prepared.NumberOfNamespacesInCycleHotspots.Count()));
     Console.WriteLine(string.Format("Distributions:\tACD: {0};\tCS: {1};\tCC: {2};\tML: {3};\tPF: {4};\tCN: {5};",
                                     prepared.CumulativeComponentDependencyHistogram.GeometricalFit.Parameter,
                                     prepared.ClassSizeHistogram.GeometricalFit.Parameter,
                                     prepared.CyclomaticComplexityHistogram.GeometricalFit.Parameter,
                                     prepared.MethodLengthHistogram.GeometricalFit.Parameter,
                                     prepared.NumberOfNonStaticPublicFieldsHistogram.GeometricalFit.Parameter,
                                     prepared.NumberOfNamespacesInCycleHistogram.GeometricalFit.Parameter));
 }
Exemplo n.º 3
0
 public IEnumerable<MethodMetricsReport> ComparedTo(MetricsReport metrics)
 {
     if (metrics != null)
         return AllChangedMethods(metrics);
     else
         return Enumerable.Empty<MethodMetricsReport>();
 }
Exemplo n.º 4
0
 private static void AddTypesOf(MetricsReport[] reports, MetricsReport combinedReport)
 {
     foreach (var typeMetrics in reports.SelectMany(r => r.typeReports.Values))
     {
         combinedReport.AddTypeReport(typeMetrics);
     }
 }
Exemplo n.º 5
0
 public static MutableGraph<NamespaceMetricsWithTypeMetrics> WithNamespacesOf(MetricsReport metrics)
 {
     var namespaceGraph = metrics.GraphOfTypes.Cast(t => t.AsNamespaceWithTypes(), n => n.HasName);
     foreach (var namespaceGroup in namespaceGraph.Vertices.GroupBy(n => n.Namespace.Name))
         namespaceGraph.Reduce(namespaceGroup.AsNamespaceWithTypes(), namespaceGroup);
     return namespaceGraph;
 }
 public static PropertyMetricsReport ForProperty(this MetricsReport metrics, PropertyInfo property)
 {
     return(new PropertyMetricsReport
     {
         Getter = metrics.ForMethod(property.GetFullGetterName()),
         Setter = metrics.ForMethod(property.GetFullSetterName())
     });
 }
Exemplo n.º 7
0
 internal static MetricsReport Of(params MetricsReport[] reports)
 {
     var combinedReport = new MetricsReport();
     combinedReport.Remember.WhenCreated = reports.FirstCreated();
     AddTypesOf(reports, combinedReport);
     combinedReport.CommonKnowledge.SetAssemblies(reports.Length);
     return combinedReport;
 }
Exemplo n.º 8
0
 private IEnumerable<MethodMetricsReport> AllChangedMethods(MetricsReport metrics)
 {
     return from m1 in _metrics.Methods
            join m2 in metrics.Methods
                on m1.Signature equals m2.Signature
            where !m1.CompilerGenerated
            where MethodsDiffer(m1, m2)
            select m1;
 }
Exemplo n.º 9
0
        internal static MetricsReport Of(params MetricsReport[] reports)
        {
            var combinedReport = new MetricsReport();

            combinedReport.Remember.WhenCreated = reports.FirstCreated();
            AddTypesOf(reports, combinedReport);
            combinedReport.CommonKnowledge.SetAssemblies(reports.Length);
            return(combinedReport);
        }
Exemplo n.º 10
0
 private void InitializeStatistics(MetricsReport metrics)
 {
     AverageRatedCyclomaticComplexity = RatedMethods.AverageAny(m => m.RatedCyclomaticComplexity, m => m.CyclomaticComplexity > 0);
     AverageRatedMethodLength = RatedMethods.AverageAny(m => m.RatedMethodLength, m => m.MethodLength > 0);
     AverageRatedClassSize = RatedTypes.AverageAny(m => m.RatedClassSize);
     AverageRatedNumberOfNonStaticPublicFields = RatedTypes.AverageAny(m => m.RatedNumberOfNonStaticPublicFields);
     AverageComponentDependency = RatedTypes.AverageAny(m => m.CumulativeComponentDependency) / metrics.CommonKnowledge.NumberOfClasses;
     NamespacesWithCyclicDependencies = (double)RatedNamespaces.CountAny(m => m.IsInCycle) / metrics.CommonKnowledge.NumberOfNamespaces;
 }
Exemplo n.º 11
0
 private IEnumerable <MethodMetricsReport> AllChangedMethods(MetricsReport metrics)
 {
     return(from m1 in _metrics.Methods
            join m2 in metrics.Methods
            on m1.Signature equals m2.Signature
            where !m1.CompilerGenerated
            where MethodsDiffer(m1, m2)
            select m1);
 }
Exemplo n.º 12
0
 public IEnumerable <MethodMetricsReport> ComparedTo(MetricsReport metrics)
 {
     if (metrics != null)
     {
         return(AllChangedMethods(metrics));
     }
     else
     {
         return(Enumerable.Empty <MethodMetricsReport>());
     }
 }
Exemplo n.º 13
0
 protected void OutputAnalysisTimes(string heading, MetricsReport metrics)
 {
     var times = new AnalyzeTimes(metrics);
     Console.WriteLine(string.Format("{0} ({1} RLOC, {2} assemblies):\t{3}s\t(analysis: {4}s\tpostprocessing: {5}s)",
                                     heading,
                                     metrics.CommonKnowledge.RelevantLinesOfCode,
                                     metrics.CommonKnowledge.NumberOfAssemblies,
                                     times.CompleteTime.TotalSeconds,
                                     times.AnalysisTime.TotalSeconds,
                                     times.PostProcessingTime.TotalSeconds));
 }
Exemplo n.º 14
0
        private void OutputMetricsReport(MetricsReport metrics)
        {
            foreach (var namespaceMetrics in metrics.Namespaces)
                OutputNamespaceMetricsReport(namespaceMetrics);

            OutputSeperator(2);

            foreach (var type in metrics.Types.Where(t => !t.CompilerGenerated))
                OutputTypeMetricsReport(type);

            OutputSeperator(2);

            foreach (var method in metrics.Methods.Where(m => !m.CompilerGenerated && !m.OnlyDeclaration))
                OutputMethodMetricsReport(method);

            OutputSeperator(3);

            OutputRatings(metrics.Rate());
            OutputHotspots(metrics.Hotspots());
        }
Exemplo n.º 15
0
 internal RatedMetrics(MetricsReport metrics)
 {
     Metrics = metrics;
     InitializeRatedLists(metrics);
     InitializeStatistics(metrics);
 }
Exemplo n.º 16
0
 public PreparedMetricsReport(MetricsReport metrics)
 {
     Report = metrics;
     ThrowExceptionWhenNoMetrics();
     Prepare();
 }
Exemplo n.º 17
0
 public void Rloc_NoMethodNoTypes_0Lines()
 {
     var emptyMetrics = new MetricsReport();
     Assert.AreEqual(0, emptyMetrics.CommonKnowledge.RelevantLinesOfCode);
 }
Exemplo n.º 18
0
 public static TypeMetricsReport ForType(this MetricsReport metrics, string typeName)
 {
     return(metrics.TypeForName(typeName));
 }
Exemplo n.º 19
0
 public static Changes Of(MetricsReport metrics)
 {
     return new Changes(metrics);
 }
 public static MethodMetricsReport ForMethod(this MetricsReport metrics, string memberName)
 {
     return((from m in metrics.Methods
             where m.Signature == memberName
             select m).FirstOrDefault());
 }
        public static MethodMetricsReport ForMethod(this MetricsReport metrics, Expression <Action> expression)
        {
            var methodName = (expression.Body as MethodCallExpression).GetCalleeName();

            return(metrics.ForMethod(methodName));
        }
Exemplo n.º 22
0
 public TypeReference(MetricsReport metrics, TypeMetricsReport source, TypeMetricsReport target)
 {
     this.metrics = metrics;
     this.Source  = source;
     this.Target  = target;
 }
Exemplo n.º 23
0
 public static TypeMetricsReport ForType <T>(this MetricsReport metrics)
 {
     return(metrics.ForType(typeof(T)));
 }
Exemplo n.º 24
0
 public static Changes Of(MetricsReport metrics)
 {
     return(new Changes(metrics));
 }
 public static PropertyMetricsReport ForProperty(this MetricsReport metrics, Expression <Func <object> > expression)
 {
     return(metrics.ForProperty(PropertyExtensions.GetPropertyInfo(expression)));
 }
Exemplo n.º 26
0
 private Changes(MetricsReport metrics)
 {
     _metrics = metrics;
 }
Exemplo n.º 27
0
 public static MutableGraph<TypeMetricsReport> WithTypesOf(MetricsReport metrics)
 {
     return metrics.Types
         .ToDictionary(t => t, t => t.InterestingDirectDependencies.Select(d => metrics.TypeForName(d)))
         .ToGraph();
 }
Exemplo n.º 28
0
 private void InitializeRatedLists(MetricsReport metrics)
 {
     RatedMethods = metrics.Methods.ToList(m => m.Rate(), m => !m.CompilerGenerated && !m.OnlyDeclaration);
     RatedTypes = metrics.Types.ToList(m => m.Rate(), m => !m.CompilerGenerated);
     RatedNamespaces = metrics.Namespaces.ToList(m => m.Rate());
 }
Exemplo n.º 29
0
 public static void Of(MetricsReport metrics)
 {
     metrics.SetInterestingDirectDependencies();
     metrics.GraphOfTypes = CreateGraph.WithTypesOf(metrics);
     metrics.SetCumulativeComponentDependency();
 }
Exemplo n.º 30
0
		public OutgoingTypeReferences(MetricsReport metrics, TypeMetricsReport source)
		{
			this.metrics = metrics;
			this.source = source;
		}
 public static MethodMetricsReport ForMethod(this MetricsReport metrics, MethodInfo method)
 {
     return(metrics.ForMethod(method.GetFullName()));
 }
Exemplo n.º 32
0
 public void Analyze(string assemblyPath)
 {
     Report = new MetricsReport();
     using (var host = new PeReader.DefaultHost())
         TryToAnalyzeInHost(assemblyPath, host);
 }
Exemplo n.º 33
0
 private Changes(MetricsReport metrics)
 {
     _metrics = metrics;
 }
Exemplo n.º 34
0
 private static void AddTypesOf(MetricsReport[] reports, MetricsReport combinedReport)
 {
     foreach (var typeMetrics in reports.SelectMany(r => r.typeReports.Values))
         combinedReport.AddTypeReport(typeMetrics);
 }
Exemplo n.º 35
0
 internal MetricsHotspots(MetricsReport metrics)
 {
     Metrics = metrics;
 }
Exemplo n.º 36
0
 public static TypeMetricsReport ForTypeOf(this MetricsReport metrics, MethodMetricsReport methodMetrics)
 {
     return(metrics.TypeOf(methodMetrics));
 }
Exemplo n.º 37
0
 public HotspotCyclomaticComplexity(MethodMetricsReport method, MetricsReport metrics)
     : base(method)
 {
 	mMetrics = metrics;
 }
Exemplo n.º 38
0
 public HotspotNamespaceInCycle(NamespaceMetricsReport namespaceReport, MetricsReport metrics)
     : base(namespaceReport, metrics)
 {
 }
Exemplo n.º 39
0
 public NamespaceCycle(MetricsReport metrics, IEnumerable<NamespaceMetricsReport> namespaces)
 {
     this.metrics = metrics;
     this.namespaces = namespaces;
     Jump += type => { };
 }
Exemplo n.º 40
0
 public void Ensure_MetricsReportIsAvailable()
 {
     if (Metrics == null) Metrics = Analyze.Me();
 }
Exemplo n.º 41
0
 protected override void AnalyzeTypes(IAssembly assembly, PdbReader pdb, IMetadataHost host, MetricsReport report)
 {
     foreach (var typeMetrics in AnalyzeTypes(assembly, pdb, host))
         report.AddTypeReport(typeMetrics);
 }
 public HotspotCumulativeComponentDependency(TypeMetricsReport type, MetricsReport metrics)
     : base(type, metrics)
 {
 }
Exemplo n.º 43
0
 public static IEnumerable <TypeMetricsReport> TypesOfNamespace(this MetricsReport metrics, NamespaceMetricsReport namespaceMetrics)
 {
     return(metrics.TypesOf(namespaceMetrics));
 }
Exemplo n.º 44
0
 public static IEnumerable <MethodMetricsReport> MethodsOfType(this MetricsReport metrics, TypeMetricsReport typeMetrics)
 {
     return(metrics.MethodsOf(typeMetrics));
 }
Exemplo n.º 45
0
		public TypeReference(MetricsReport metrics, TypeMetricsReport source, TypeMetricsReport target)
		{
			this.metrics = metrics;
			this.Source = source;
			this.Target = target;
		}
Exemplo n.º 46
0
 public HotspotClassSize(TypeMetricsReport type, MetricsReport metrics)
     : base(type, metrics)
 {
 }
Exemplo n.º 47
0
 protected abstract void AnalyzeTypes(IAssembly assembly, PdbReader pdb, IMetadataHost host, MetricsReport report);
Exemplo n.º 48
0
 public static TypeMetricsReport ForType(this MetricsReport metrics, Type type)
 {
     return(metrics.ForType(type.GetFullName()));
 }