bool IsSearchedNode(ICSharpCode.OldNRefactory.Ast.INode node)
        {
            if (node == null || node.StartLocation.IsEmpty)
            {
                return(false);
            }
            foreach (var tuple in searchedMembers)
            {
                var searchedMember         = tuple.Item1;
                var searchedMemberFile     = tuple.Item3;
                var searchedMemberLocation = tuple.Item4;

                if (searchedMember is CompoundType)
                {
                    foreach (IType part in ((CompoundType)searchedMember).Parts)
                    {
                        if (fileName == part.CompilationUnit.FileName &&
                            node.StartLocation.Line == part.Location.Line
//						&& node.StartLocation.Column == part.Location.Column
                            )
                        {
                            return(true);
                        }
                    }
                }

                return((string.IsNullOrEmpty(searchedMemberFile) || fileName == searchedMemberFile) &&
                       node.StartLocation.Line == searchedMemberLocation.Line
//					&& node.StartLocation.Column == this.searchedMemberLocation.Column
                       );
            }
            return(false);
        }
Exemplo n.º 2
0
            internal static void EvaluateComplexityMetrics(ICSharpCode.OldNRefactory.Ast.INode method, MethodProperties props)
            {
                props.CyclometricComplexity = 1;
                props.LOCReal           = 0;
                props.NumberOfVariables = 0;

                cls = props.ParentClass;

                ASTVisitor ctxAstVisitor = new ASTVisitor();

                if (method is MethodDeclaration)
                {
                    foreach (var statement in ((MethodDeclaration)method).Body.Children)
                    {
                        ctxAstVisitor.VisitStatement(statement, props);
                    }
                }
                else if (method is ConstructorDeclaration)
                {
                    foreach (var statement in ((ConstructorDeclaration)method).Body.Children)
                    {
                        ctxAstVisitor.VisitStatement(statement, props);
                    }
                }
                cls.CyclometricComplexity += props.CyclometricComplexity;
            }
        public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data)
        {
            foreach (var tuple in searchedMembers)
            {
                var searchedMember = tuple.Item1;
                if (searchedMember is LocalVariable)
                {
                    LocalVariable searchedVariable             = (LocalVariable)searchedMember;
                    ICSharpCode.OldNRefactory.Ast.INode parent = localVariableDeclaration.Parent;
                    while (parent != null && !(parent is MemberNode) && !(parent is ParametrizedNode))
                    {
                        parent = parent.Parent;
                    }

                    if (parent != null &&
                        localVariableDeclaration.StartLocation.Line == searchedVariable.Location.Line &&
                        localVariableDeclaration.StartLocation.Column == searchedVariable.Location.Column &&
                        parent.StartLocation.Line == searchedVariable.DeclaringMember.Location.Line
//					&& parent.StartLocation.Column == searchedVariable.DeclaringMember.Location.Column
                        )
                    {
                        foreach (VariableDeclaration decl in localVariableDeclaration.Variables)
                        {
                            if (decl.Name == SearchedMemberName)
                            {
                                AddUniqueReference(decl.StartLocation.Y, decl.StartLocation.X, SearchedMemberName);
                            }
                        }
                    }
                }
            }
            return(base.VisitLocalVariableDeclaration(localVariableDeclaration, data));
        }
 void CheckNode(ICSharpCode.OldNRefactory.Ast.INode node)
 {
     if (IsSearchedNode(node))
     {
         int line, column;
         if (SearchText(SearchedMemberName, node.StartLocation.Line, node.StartLocation.Column, out line, out column))
         {
             AddUniqueReference(line, column, SearchedMemberName);
         }
     }
 }
Exemplo n.º 5
0
 private void VisitStatement(ICSharpCode.OldNRefactory.Ast.INode statement, MethodProperties meth)
 {
     try{
         if (statement is BlockStatement)
         {
             VisitStatement((BlockStatement)statement, meth);
         }
         else if (statement is IfElseStatement)
         {
             VisitStatement((IfElseStatement)statement, meth);
         }
         else if (statement is ElseIfSection)
         {
             VisitStatement((ElseIfSection)statement, meth);
         }
         else if (statement is ForeachStatement)
         {
             VisitStatement((ForeachStatement)statement, meth);
         }
         else if (statement is ForStatement)
         {
             VisitStatement((ForStatement)statement, meth);
         }
         else if (statement is ForNextStatement)
         {
             VisitStatement((ForNextStatement)statement, meth);
         }
         else if (statement is DoLoopStatement)
         {
             VisitStatement((DoLoopStatement)statement, meth);
         }
         else if (statement is SwitchStatement)
         {
             VisitStatement((SwitchStatement)statement, meth);
         }
         else if (statement is LocalVariableDeclaration)
         {
             VisitStatement((LocalVariableDeclaration)statement, meth);
         }
         else if (statement is ExpressionStatement)
         {
             VisitStatement((ExpressionStatement)statement, meth);
         }
     }catch (Exception ex) {
         Console.WriteLine(ex.ToString());
     }
     //See other potential types to exploit
 }
Exemplo n.º 6
0
        public MethodProperties(IMethod m)
        {
            mthd          = m;
            mthdAst       = null;
            ParameterList = new List <string> (0);
            foreach (var param in m.Parameters)
            {
                ParameterList.Add(param.ReturnType.FullName);
            }

            AfferentCoupling = 0;
            EfferentCoupling = 0;
            FilePath         = "";
            this.FullName    = mthd.FullName;
            this.StartLine   = mthd.BodyRegion.Start.Line;
            this.EndLine     = mthd.BodyRegion.End.Line;
        }
Exemplo n.º 7
0
 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);
     }
 }
Exemplo n.º 8
0
        public MethodProperties(ICSharpCode.OldNRefactory.Ast.INode m, ClassProperties prop)
        {
            mthd          = null;
            ParameterList = new List <string> (0);
            if (m is MethodDeclaration)
            {
                mthdAst = (MethodDeclaration)m;
                VisitMethodMember((MethodDeclaration)m, prop);
                this.FullName = prop.FullName + "." + ((MethodDeclaration)m).Name.Substring(((MethodDeclaration)m).Name.LastIndexOf(".") + 1);
            }
            else if (m is ConstructorDeclaration)
            {
                mthdAst = (ConstructorDeclaration)m;
                VisitConstructorMember((ConstructorDeclaration)m, prop);
                this.FullName = prop.FullName + "." + ((ConstructorDeclaration)m).Name.Substring(((ConstructorDeclaration)m).Name.LastIndexOf(".") + 1);
            }

            AfferentCoupling = 0;
            EfferentCoupling = 0;
            FilePath         = "";
            this.ParentClass = prop;
            this.StartLine   = mthdAst.StartLocation.Line;
            this.EndLine     = mthdAst.EndLocation.Line;
        }
Exemplo n.º 9
0
        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");
            }
        }
Exemplo n.º 10
0
		public MethodProperties (ICSharpCode.OldNRefactory.Ast.INode m, ClassProperties prop)
		{
			mthd=null;
			ParameterList = new List<string> (0);
			if(m is MethodDeclaration) {
				mthdAst = (MethodDeclaration)m;
				VisitMethodMember((MethodDeclaration)m, prop);
				this.FullName = prop.FullName + "." + ((MethodDeclaration)m).Name.Substring(((MethodDeclaration)m).Name.LastIndexOf(".")+1);
			} else if(m is ConstructorDeclaration) {
				mthdAst = (ConstructorDeclaration)m;
				VisitConstructorMember((ConstructorDeclaration)m, prop);
				this.FullName = prop.FullName + "." + ((ConstructorDeclaration)m).Name.Substring(((ConstructorDeclaration)m).Name.LastIndexOf(".")+1);
			}
			
			AfferentCoupling=0;
			EfferentCoupling=0;
			FilePath="";
			this.ParentClass = prop;
			this.StartLine = mthdAst.StartLocation.Line;
			this.EndLine = mthdAst.EndLocation.Line;

		}
Exemplo n.º 11
0
		public MethodProperties (IMethod m)
		{ 
			mthd = m;
			mthdAst = null;
			ParameterList = new List<string> (0);
			foreach(var param in m.Parameters) {
				ParameterList.Add(param.ReturnType.FullName);
			}
			
			AfferentCoupling=0;
			EfferentCoupling=0;
			FilePath="";
			this.FullName = mthd.FullName;
			this.StartLine = mthd.BodyRegion.Start.Line;
			this.EndLine = mthd.BodyRegion.End.Line;
		}