protected override void InnerRun()
            {
                int counter       = 0;
                int totalProjects = widget.projects.Count;

                try {
                    foreach (ProjectProperties projectprop in widget.projects)
                    {
                        CodeMetricsService.AddTypes(projectprop, widget.ctx);
                    }

                    foreach (ProjectProperties projectprop in widget.projects)
                    {
                        ObjectOrientedMetrics.EvaluateOOMetrics(widget.ctx, projectprop);
                        ComplexityMetrics.EvaluateComplexityMetrics(widget.ctx, projectprop);
                        CodeMetricsService.ProcessInnerTypes(projectprop);

                        Gtk.Application.Invoke(delegate {
                            FillTree(projectprop);
                        });
                        if (base.IsStopping)
                        {
                            return;
                        }
                        lock (lockCounter)
                        {
                            counter++;
                            DispatchService.GuiSyncDispatch(delegate {
                                IdeApp.Workbench.StatusBar.SetProgressFraction(counter / (double)totalProjects);
                            });
                        }
                    }
                } catch (Exception e) {
                    Console.WriteLine("Error : " + e.ToString());
                    base.Stop();
                }


                Gtk.Application.Invoke(delegate {
                    IdeApp.Workbench.StatusBar.ShowMessage("Finished calculating metrics\n");
                    IdeApp.Workbench.StatusBar.EndProgress();
                    widget.textviewReport.Buffer.Text  = GettextCatalog.GetString("Finished calculating metrics\n");
                    widget.textviewReport.Buffer.Text += CodeMetricsService.GenerateAssemblyMetricText();
                });

                base.Stop();
            }
Пример #2
0
            internal static int EvaluateTypeLOC(MetricsContext ctx, NamespaceProperties namespaceRef, TypeDeclaration node, int startIndex)
            {
                if (node == null)
                {
                    return(-1);
                }
                StringBuilder typeName = new StringBuilder("");;

                try {
                    string[] prefixArray = ComplexityMetrics.PrefixName.ToArray();
                    for (int i = 0; i < prefixArray.Length; i++)
                    {
                        typeName.Append(prefixArray[prefixArray.Length - i - 1] + ".");
                    }
                    typeName.Append(node.Name);
                    foreach (var templateDef in node.Templates)
                    {
                        foreach (var bases in templateDef.Bases)
                        {
                            if (bases.Type.Contains("constraint:"))
                            {
                                continue;
                            }
                            typeName.Append(" " + bases.Type.Substring(bases.Type.LastIndexOf(".") + 1));
                        }
                    }

                    IProperties typeRef = null;
                    switch (node.Type)
                    {
                    case ICSharpCode.OldNRefactory.Ast.ClassType.Class:
                        typeRef = ComplexityMetrics.ProjProp.GetClassReference(typeName.ToString());
                        break;

                    case ICSharpCode.OldNRefactory.Ast.ClassType.Enum:
                        typeRef = ComplexityMetrics.ProjProp.GetEnumReference(typeName.ToString(), namespaceRef);
                        break;

                    case ICSharpCode.OldNRefactory.Ast.ClassType.Struct:
                        typeRef = ComplexityMetrics.ProjProp.GetStructReference(typeName.ToString(), namespaceRef);
                        break;

                    case ICSharpCode.OldNRefactory.Ast.ClassType.Interface:
                        typeRef = ComplexityMetrics.ProjProp.GetInterfaceReference(typeName.ToString(), namespaceRef);
                        break;

                    default:
                        return(node.EndLocation.Line);
                    }

                    if (typeRef == null)
                    {
                        return(node.EndLocation.Line);
                    }

                    Dictionary <int, ICSharpCode.OldNRefactory.Ast.INode> childLocations = new Dictionary <int, ICSharpCode.OldNRefactory.Ast.INode>(0);
                    foreach (ICSharpCode.OldNRefactory.Ast.INode childNode in node.Children)
                    {
                        if ((childNode is TypeDeclaration) || (childNode is ConstructorDeclaration) || (childNode is MethodDeclaration))
                        {
                            childLocations.Add(childNode.StartLocation.Line, childNode);
                        }
                    }

                    if (typeRef.FilePath == null || typeRef.FilePath == "")
                    {
                        typeRef.FilePath = ComplexityMetrics.File.FilePath;
                    }

                    startIndex = node.StartLocation.Line;
                    int   endIndex = node.EndLocation.Line;
                    ulong totalLines = 0, totalRealLines = 0, totalCommentedLines = 0;
                    int   realLines             = 0;
                    bool  isSingleLineComment   = false;
                    bool  isMultipleLineComment = false;

                    for (int i = startIndex; i < endIndex; i++)
                    {
                        string lineText = ComplexityMetrics.FileDoc.GetTextAt(ComplexityMetrics.FileText[i]).Trim();

                        if (isMultipleLineComment)
                        {
                            totalCommentedLines++;
                            if (lineText.EndsWith("*/"))
                            {
                                isMultipleLineComment = false;
                            }
                            continue;
                        }
                        if (lineText.StartsWith("/*"))
                        {
                            isMultipleLineComment = true;
                            totalCommentedLines++;
                            continue;
                        }
                        isSingleLineComment = lineText.StartsWith("//");
                        if (isSingleLineComment)
                        {
                            totalCommentedLines++;
                        }
                        if (lineText.Length > 0 && !isSingleLineComment)
                        {
                            realLines++;
                            if (childLocations.ContainsKey(i))
                            {
                                ComplexityMetrics.PrefixName.Push(node.Name);
                                if ((childLocations[i] is MethodDeclaration) || (childLocations[i] is ConstructorDeclaration))
                                {
                                    ComplexityMetrics.ProcessMethod(ctx, childLocations[i], typeRef);
                                    i = childLocations[i].EndLocation.Line;
                                }
                                else if (childLocations[i] is TypeDeclaration)
                                {
                                    i = EvaluateTypeLOC(ctx, namespaceRef, (TypeDeclaration)childLocations[i], i);
                                }
                                ComplexityMetrics.PrefixName.Pop();
                            }
                        }
                    }

                    totalLines     += (ulong)(endIndex - startIndex + 2);
                    totalRealLines += (ulong)realLines;
                    if (typeRef is ClassProperties)
                    {
                        ((ClassProperties)typeRef).LOCReal     += totalRealLines;
                        ((ClassProperties)typeRef).LOCComments += totalCommentedLines;
                    }
                    else if (typeRef is InterfaceProperties)
                    {
                        ((InterfaceProperties)typeRef).LOCReal     += totalRealLines;
                        ((InterfaceProperties)typeRef).LOCComments += totalCommentedLines;
                    }
                    else if (typeRef is EnumProperties)
                    {
                        ((EnumProperties)typeRef).LOCReal     += totalRealLines;
                        ((EnumProperties)typeRef).LOCComments += totalCommentedLines;
                    }
                    else if (typeRef is StructProperties)
                    {
                        ((StructProperties)typeRef).LOCReal     += totalRealLines;
                        ((StructProperties)typeRef).LOCComments += totalCommentedLines;
                    }
                    else if (typeRef is DelegateProperties)
                    {
                        ((DelegateProperties)typeRef).LOCReal     += totalRealLines;
                        ((DelegateProperties)typeRef).LOCComments += totalCommentedLines;
                    }
                } catch (Exception e) {
                    Console.WriteLine("Error in class " + typeName.ToString());
                    Console.WriteLine(e.ToString());
                }
                return(node.EndLocation.Line);
            }