private static void ProcessNode(MetricsContext ctx, ICSharpCode.OldNRefactory.Ast.INode node) { if (node is UsingStatement) { //TODO do something (something to do with afferent and efferent coupling of namespaces) } else if (node is NamespaceDeclaration) { try { PrefixName.Push(((NamespaceDeclaration)node).Name); LOCEvaluate.EvaluateNamespaceLOC(ctx, (NamespaceDeclaration)node); PrefixName.Pop(); } catch (Exception e) { } } else if (node is TypeDeclaration) { LOCEvaluate.EvaluateTypeLOC(ctx, null, (TypeDeclaration)node, node.StartLocation.Line); } }
private static void ProcessMethod(MetricsContext ctx, ICSharpCode.OldNRefactory.Ast.INode method, IProperties parentClass) { if (method == null) { return; } StringBuilder methodName = new StringBuilder(""); string[] PrefixArray = PrefixName.ToArray(); for (int i = 0; i < PrefixArray.Length; i++) { methodName.Append(PrefixArray[PrefixArray.Length - i - 1] + "."); } List <string> methodParameterList = new List <string>(0); if (method is MethodDeclaration) { methodName.Append(((MethodDeclaration)method).Name); foreach (ParameterDeclarationExpression pde in ((MethodDeclaration)method).Parameters) { string type = pde.TypeReference.Type; if (type.Contains(".")) { type = type.Substring(type.LastIndexOf(".") + 1); } methodParameterList.Add(type); } } else if (method is ConstructorDeclaration) { methodName.Append(((ConstructorDeclaration)method).Name); foreach (ParameterDeclarationExpression pde in ((ConstructorDeclaration)method).Parameters) { string type = pde.TypeReference.Type; if (type.Contains(".")) { type = type.Substring(type.LastIndexOf(".") + 1); } methodParameterList.Add(type); } } StringBuilder MethodKey = new StringBuilder(); MethodKey.Append(methodName.ToString() + " "); foreach (string paramName in methodParameterList) { MethodKey.Append(paramName + " "); } try{ if (parentClass is ClassProperties) { if (!(parentClass as ClassProperties).Methods.ContainsKey(MethodKey.ToString())) { if (method is MethodDeclaration) { (parentClass as ClassProperties).Methods.Add(MethodKey.ToString(), new MethodProperties((MethodDeclaration)method, parentClass as ClassProperties)); } else if (method is ConstructorDeclaration) { (parentClass as ClassProperties).Methods.Add(MethodKey.ToString(), new MethodProperties((ConstructorDeclaration)method, parentClass as ClassProperties)); } } var currentMethodReference = (parentClass as ClassProperties).Methods[MethodKey.ToString()]; //Calculate all metrics here ASTVisitor.EvaluateComplexityMetrics(method, currentMethodReference); LOCEvaluate.EvaluateMethodLOC(currentMethodReference, FileText, FileDoc); currentMethodReference.FilePath = File.FilePath; } } catch (NullReferenceException ex) { LoggingService.LogError("Error in '" + methodName.ToString() + "'", ex); Console.WriteLine(MethodKey.ToString() + " hoo"); } }