Exemplo n.º 1
0
 private void VisitExpression(Expression expression, MethodProperties meth)
 {
     if (expression is IdentifierExpression)
     {
         VisitExpression((IdentifierExpression)expression, meth);
     }
     else if (expression is AssignmentExpression)
     {
         VisitExpression((AssignmentExpression)expression, meth);
     }
     else if (expression is PrimitiveExpression)
     {
         VisitExpression((PrimitiveExpression)expression, meth);
     }
     else if (expression is BinaryOperatorExpression)
     {
         VisitExpression((BinaryOperatorExpression)expression, meth);
     }
     else if (expression is MemberReferenceExpression)
     {
         //TODO something
     }
     else if (expression is ParenthesizedExpression)
     {
         VisitExpression((ParenthesizedExpression)expression, meth);
     }
     else if (expression is ConditionalExpression)
     {
         VisitExpression((ConditionalExpression)expression, meth);
     }
     else if (expression is InvocationExpression)
     {
         VisitExpression((InvocationExpression)expression, meth);
     }
 }
Exemplo n.º 2
0
            public void VisitStatement(ElseIfSection statement, MethodProperties meth)
            {
                meth.CyclometricComplexity++;

                VisitExpression(statement.Condition, meth);
                VisitStatement(statement.EmbeddedStatement, meth);
            }
Exemplo n.º 3
0
 public void VisitStatement(BlockStatement statement, MethodProperties meth)
 {
     meth.LOCReal++;
     foreach (var innerStatement in ((BlockStatement)statement).Children)
     {
         VisitStatement((Statement)innerStatement, meth);
     }
 }
Exemplo n.º 4
0
 public void VisitStatement(LocalVariableDeclaration statement, MethodProperties meth)
 {
     meth.NumberOfVariables += statement.Variables.Count;
     foreach (VariableDeclaration variable in statement.Variables)
     {
         VisitExpression(variable.Initializer, meth);
     }
 }
Exemplo n.º 5
0
 public void VisitExpression(BinaryOperatorExpression expression, MethodProperties meth)
 {
     if (((BinaryOperatorExpression)expression).Op == BinaryOperatorType.LogicalAnd || ((BinaryOperatorExpression)expression).Op == BinaryOperatorType.LogicalOr)
     {
         meth.CyclometricComplexity++;
         VisitExpression(((BinaryOperatorExpression)expression).Left, meth);
         VisitExpression(((BinaryOperatorExpression)expression).Right, meth);
     }
 }
Exemplo n.º 6
0
            public void VisitStatement(DoLoopStatement statement, MethodProperties meth)
            {
                meth.CyclometricComplexity++;
                VisitExpression(statement.Condition, meth);

                foreach (var innerStatement in statement.EmbeddedStatement.Children)
                {
                    VisitStatement(innerStatement, meth);
                }
            }
Exemplo n.º 7
0
            public void VisitStatement(ForeachStatement statement, MethodProperties meth)
            {
                meth.CyclometricComplexity++;
                VisitExpression(((ForeachStatement)(statement)).Expression, meth);

                VisitExpression(statement.NextExpression, meth);

                foreach (var innerStatement in ((ForeachStatement)statement).EmbeddedStatement.Children)
                {
                    VisitStatement((Statement)innerStatement, meth);
                }
            }
Exemplo n.º 8
0
        private static StringBuilder GenerateMethodMetricText(MethodProperties item)
        {
            StringBuilder results = new StringBuilder();

            results.Append(GettextCatalog.GetString("\nName : " + item.FullName));
            results.Append(GettextCatalog.GetString("\nTotal number of local variables : " + item.NumberOfVariables));
            results.Append(GettextCatalog.GetString("\nTotal number of parameters : " + item.ParameterCount));
            results.Append(GettextCatalog.GetString("\nAfferent Coupling : " + item.AfferentCoupling));
            results.Append(GettextCatalog.GetString("\nEfferent Coupling : " + item.EfferentCoupling));

            return(results);
        }
Exemplo n.º 9
0
 public void VisitStatement(SwitchStatement statement, MethodProperties meth)
 {
     meth.CyclometricComplexity++;
     VisitExpression(((SwitchStatement)statement).SwitchExpression, meth);
     foreach (SwitchSection innerSection in ((SwitchStatement)statement).SwitchSections)
     {
         meth.CyclometricComplexity++;
         foreach (var caseLabel in innerSection.SwitchLabels)
         {
             VisitExpression(caseLabel.ToExpression, meth);
         }
     }
 }
Exemplo n.º 10
0
 public void VisitExpression(IdentifierExpression expression, MethodProperties meth)
 {
     if (cls.Fields.ContainsKey(expression.Identifier))
     {
         cls.Fields[expression.Identifier].InternalAccessCount++;
     }
     else
     {
         foreach (var field in cls.Fields)
         {
             //TODO External access
         }
     }
 }
Exemplo n.º 11
0
            internal static void EvaluateMethodLOC(MethodProperties prop, List <LineSegment> text, Mono.TextEditor.Document doc)
            {
                ulong totalLines = 0, totalRealLines = 0, totalCommentedLines = 0;
                int   realLines             = 0;
                bool  isSingleLineComment   = false;
                bool  isMultipleLineComment = false;

                int startIndex = prop.StartLine;
                int endIndex   = prop.EndLine;

                for (int i = startIndex; i < endIndex; i++)
                {
                    string lineText = "";
                    try{
                        lineText = doc.GetTextAt(text[i]).Trim();
                    } catch (Exception e) {
                        continue;
                    }
                    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++;
                    }
                }

                totalLines     += (ulong)(endIndex - startIndex + 1);
                totalRealLines += (ulong)realLines;
                ((MethodProperties)prop).LOCComments = totalCommentedLines;
                ((MethodProperties)prop).LOCReal     = totalRealLines + 1;
            }
Exemplo n.º 12
0
            public void VisitStatement(ForNextStatement statement, MethodProperties meth)
            {
                meth.CyclometricComplexity++;
                VisitExpression(statement.LoopVariableExpression, meth);

                foreach (Expression innerExpression in statement.NextExpressions)
                {
                    VisitExpression(innerExpression, meth);
                }

                foreach (var innerStatement in statement.EmbeddedStatement.Children)
                {
                    VisitStatement(innerStatement, meth);
                }
            }
Exemplo n.º 13
0
 private void VisitStatement(ICSharpCode.NRefactory.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
 }
			internal static void EvaluateComplexityMetrics (ICSharpCode.NRefactory.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;
			}
Exemplo n.º 15
0
            public static string EvaluateMethodCoupling(InvocationExpression expression, MethodProperties meth)
            {
                Console.WriteLine(expression.ToString());

                meth.EfferentCoupling++;

                StringBuilder    calleeName = new StringBuilder();
                List <string>    paramList  = new List <string>();
                MethodProperties methCallee = null;

                lock (coupleLock)
                {
                    if (expression.TargetObject is MemberReferenceExpression)
                    {
                        calleeName.Append(ExtractCalleeFullName((MemberReferenceExpression)(expression.TargetObject), meth));
                        paramList = ExtractParamList(expression, meth);

                        try {
                            methCallee = ComplexityMetrics.ProjProp.GetMethodReference(calleeName.ToString(), paramList);
                            methCallee.AfferentCoupling++;
                        } catch (Exception e) {
                            Console.WriteLine(e.ToString());
                        }
                    }
                    else if (expression.TargetObject is IdentifierExpression)
                    {
                        calleeName.Append(((IdentifierExpression)expression.TargetObject).Identifier);
                        paramList = ExtractParamList(expression, meth);

                        try {
                            Console.WriteLine(calleeName.ToString());
                            methCallee = ComplexityMetrics.ProjProp.GetMethodReference(calleeName.ToString(), paramList);
                            methCallee.AfferentCoupling++;
                        } catch (Exception e) {
                            Console.WriteLine(e.ToString());
                        }
                    }
                }
                return(methCallee.Method.ReturnType.FullName);
            }
Exemplo n.º 16
0
 public void VisitStatement(IfElseStatement statement, MethodProperties meth)
 {
     meth.CyclometricComplexity++;
     //Process the conditions
     VisitExpression(((IfElseStatement)statement).Condition, meth);
     //Handle the true statement
     foreach (Statement innerStatement in  ((IfElseStatement)statement).TrueStatement)
     {
         VisitStatement(innerStatement, meth);
     }
     //Handle the false statement
     foreach (Statement innerStatement in ((IfElseStatement)statement).FalseStatement)
     {
         meth.CyclometricComplexity++;
         VisitStatement(innerStatement, meth);
     }
     //Handle the ElseIf statements
     foreach (ElseIfSection elseIfSection in ((IfElseStatement)statement).ElseIfSections)
     {
         VisitStatement(elseIfSection, meth);
     }
 }
Exemplo n.º 17
0
			public static string EvaluateMethodCoupling(InvocationExpression expression, MethodProperties meth)
			{
				Console.WriteLine(expression.ToString());
				
				meth.EfferentCoupling++;
				
				StringBuilder calleeName = new StringBuilder();
				List<string> paramList = new List<string>();
				MethodProperties methCallee = null;
				lock(coupleLock)
				{
					if(expression.Target is MemberReferenceExpression) {
					
			   			calleeName.Append(ExtractCalleeFullName((MemberReferenceExpression)(expression.Target), meth));
						paramList = ExtractParamList(expression, meth);
					
						try {
//							methCallee = ComplexityMetrics.ProjProp.GetMethodReference(calleeName.ToString(), paramList);
							methCallee.AfferentCoupling++;
						} catch (Exception e) {
							Console.WriteLine(e.ToString());
						}
					
					} else if (expression.Target is IdentifierExpression) {
					
						calleeName.Append(((IdentifierExpression)expression.Target).Identifier);
						paramList = ExtractParamList(expression, meth);
					
						try {
							Console.WriteLine(calleeName.ToString());
//							methCallee = ComplexityMetrics.ProjProp.GetMethodReference(calleeName.ToString(), paramList);
							methCallee.AfferentCoupling++;
						} catch (Exception e) {
							Console.WriteLine(e.ToString());
						}
					} 
				}
				return methCallee.Method.ReturnType.ToString ();
			}
			private void VisitExpression(Expression expression, MethodProperties meth)
			{
				if(expression is IdentifierExpression){
					
					VisitExpression((IdentifierExpression)expression, meth);
				} else if (expression is AssignmentExpression) {
					
					VisitExpression((AssignmentExpression)expression, meth);
				} else if (expression is PrimitiveExpression) {
					
					VisitExpression((PrimitiveExpression)expression, meth);
				} else if (expression is BinaryOperatorExpression) {
			
					VisitExpression((BinaryOperatorExpression) expression, meth);
				} else if (expression is MemberReferenceExpression) {
					//TODO something
				} else if (expression is ParenthesizedExpression) {
					
					VisitExpression((ParenthesizedExpression)expression, meth);
				} else if (expression is ConditionalExpression) {
					
					VisitExpression((ConditionalExpression)expression, meth);
				} else if (expression is InvocationExpression) {
					
					VisitExpression((InvocationExpression)expression, meth);
				}
			}
Exemplo n.º 19
0
 public void VisitExpression(PrimitiveExpression expression, MethodProperties meth)
 {
     return;
 }
			public void VisitStatement (SwitchStatement statement, MethodProperties meth)
			{
				meth.CyclometricComplexity++;
				VisitExpression(((SwitchStatement)statement).SwitchExpression, meth);
				foreach(SwitchSection innerSection in ((SwitchStatement)statement).SwitchSections){
					meth.CyclometricComplexity++;
					foreach(var caseLabel in innerSection.SwitchLabels)
						VisitExpression(caseLabel.ToExpression, meth);
				}
			}
			public void VisitStatement (ExpressionStatement statement, MethodProperties meth)
			{
				//TODO Ability to evaluate access count of external fields
				// Currently we assume that MemberReferenceExpression is not called and that we directly go on to IdentifierExpression
				VisitExpression(statement.Expression, meth);
			}
			public void VisitStatement (ElseIfSection statement, MethodProperties meth)
			{
				meth.CyclometricComplexity++;
				
				VisitExpression(statement.Condition, meth);
				VisitStatement(statement.EmbeddedStatement, meth);
			}
			public void VisitStatement (ForNextStatement statement, MethodProperties meth)
			{
				meth.CyclometricComplexity++;
				VisitExpression(statement.LoopVariableExpression, meth);
				
				foreach(Expression innerExpression in statement.NextExpressions)
					VisitExpression(innerExpression, meth);
				
				foreach(var innerStatement in statement.EmbeddedStatement.Children)
					VisitStatement(innerStatement, meth);
			}
Exemplo n.º 24
0
			private static List<string> ExtractParamList(InvocationExpression expression, MethodProperties meth)
			{
				List<string> retVal = new List<string>();
				foreach(Expression param in expression.Arguments)
				{
					if(param is PrimitiveExpression) {
						retVal.Add(((PrimitiveExpression)param).Value.GetType().Name);
						continue;
					} else if(param is BinaryOperatorExpression) {
						if(((BinaryOperatorExpression)param).Operator == BinaryOperatorType.ConditionalAnd || ((BinaryOperatorExpression)param).Operator == BinaryOperatorType.ConditionalOr)
							retVal.Add("System.Boolean");
						continue;
					} else if (param is InvocationExpression) {
						// TODO Deal with method calls within method calls
						// Lots of cases
						retVal.Add(EvaluateMethodCoupling((InvocationExpression)param, meth));
					}
					
				}
				return retVal;
			}
			public void VisitStatement (BlockStatement statement, MethodProperties meth)
			{
				meth.LOCReal++;
				foreach(var innerStatement in ((BlockStatement)statement).Children)
					VisitStatement((Statement)innerStatement, meth);				
			}
Exemplo n.º 26
0
 public void VisitExpression(MemberReferenceExpression expression, MethodProperties meth)
 {
     return;
 }
Exemplo n.º 27
0
 /// <summary>
 /// Afferent coupling at field level
 /// </summary>
 /// <param name="expression">
 /// A <see cref="IdentifierExpression"/>
 /// </param>
 /// <param name="meth">
 /// A <see cref="MethodProperties"/>
 /// </param>
 public static void EvaluateFieldCoupling(IdentifierExpression expression, MethodProperties meth)
 {
     //TODO
 }
Exemplo n.º 28
0
 public void VisitExpression(ParenthesizedExpression expression, MethodProperties meth)
 {
     VisitExpression(((ParenthesizedExpression)expression).Expression, meth);
 }
Exemplo n.º 29
0
 public void VisitExpression(ConditionalExpression expression, MethodProperties meth)
 {
     VisitExpression(((ConditionalExpression)expression).Condition, meth);
     VisitExpression(((ConditionalExpression)expression).TrueExpression, meth);
 }
Exemplo n.º 30
0
 public void VisitExpression(AssignmentExpression expression, MethodProperties meth)
 {
     VisitExpression(expression.Left, meth);
     VisitExpression(expression.Right, meth);
 }
			public void VisitExpression (PrimitiveExpression expression, MethodProperties meth)
			{
				return;
			}
Exemplo n.º 32
0
			/// <summary>
			/// Afferent coupling at field level
			/// </summary>
			/// <param name="expression">
			/// A <see cref="IdentifierExpression"/>
			/// </param>
			/// <param name="meth">
			/// A <see cref="MethodProperties"/>
			/// </param>
			public static void EvaluateFieldCoupling(IdentifierExpression expression, MethodProperties meth)
			{
				//TODO
			}
			public void VisitExpression (InvocationExpression expression, MethodProperties meth)
			{
				//Coupling.EvaluateMethodCoupling(expression, meth);
			}
Exemplo n.º 34
0
 private static string ExtractCalleeFullName(MemberReferenceExpression expression, MethodProperties meth)
 {
     if (expression.TargetObject is MemberReferenceExpression)
     {
         return(ExtractCalleeFullName((MemberReferenceExpression)(expression.TargetObject), meth) + "." + expression.MemberName);
     }
     if (expression.TargetObject is IdentifierExpression)
     {
         return(((IdentifierExpression)(expression.TargetObject)).Identifier + "." + expression.MemberName);
     }
     return("");
 }
			public void VisitStatement (IfElseStatement statement, MethodProperties meth)
			{
				meth.CyclometricComplexity++;
				//Process the conditions
				VisitExpression(((IfElseStatement)statement).Condition, meth);
				//Handle the true statement
				foreach(Statement innerStatement in  ((IfElseStatement)statement).TrueStatement)
					VisitStatement(innerStatement, meth);
				//Handle the false statement
				foreach(Statement innerStatement in ((IfElseStatement)statement).FalseStatement) {
					meth.CyclometricComplexity++;		
					VisitStatement(innerStatement, meth);
				}
				//Handle the ElseIf statements
				foreach(ElseIfSection elseIfSection in ((IfElseStatement)statement).ElseIfSections)
					VisitStatement(elseIfSection, meth);
			}
			public void VisitExpression (MemberReferenceExpression expression, MethodProperties meth)
			{
				return;
			}
			public void VisitStatement (ForeachStatement statement, MethodProperties meth)
			{
				meth.CyclometricComplexity++;
				VisitExpression(((ForeachStatement)(statement)).Expression, meth);
				
				VisitExpression(statement.NextExpression, meth);						
				
				foreach(var innerStatement in ((ForeachStatement)statement).EmbeddedStatement.Children)
					VisitStatement((Statement)innerStatement, meth);
			}
			public void VisitExpression (ParenthesizedExpression expression, MethodProperties meth)
			{
				VisitExpression(((ParenthesizedExpression)expression).Expression, meth);
			}
			public void VisitStatement (DoLoopStatement statement, MethodProperties meth)
			{
				meth.CyclometricComplexity++;
				VisitExpression(statement.Condition, meth);
				
				foreach(var innerStatement in statement.EmbeddedStatement.Children)
					VisitStatement(innerStatement, meth);
			}
			public void VisitExpression (ConditionalExpression expression, MethodProperties meth)
			{
				VisitExpression(((ConditionalExpression)expression).Condition, meth);
				VisitExpression(((ConditionalExpression)expression).TrueExpression, meth);
			}
			public void VisitStatement (LocalVariableDeclaration statement, MethodProperties meth) 
			{
				meth.NumberOfVariables+=statement.Variables.Count;
				foreach(VariableDeclaration variable in statement.Variables)
					VisitExpression(variable.Initializer, meth);
			}
			public void VisitExpression (IdentifierExpression expression, MethodProperties meth)
			{
				if(cls.Fields.ContainsKey(expression.Identifier)){
					cls.Fields[expression.Identifier].InternalAccessCount++;
				} else {
					foreach(var field in cls.Fields){
					//TODO External access
					}
				
				}
			}
			private void VisitStatement(ICSharpCode.NRefactory.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
			}	
			public void VisitExpression (AssignmentExpression expression, MethodProperties meth)
			{
				VisitExpression(expression.Left, meth);
				VisitExpression(expression.Right, meth);
			}
Exemplo n.º 45
0
 public void VisitStatement(ExpressionStatement statement, MethodProperties meth)
 {
     //TODO Ability to evaluate access count of external fields
     // Currently we assume that MemberReferenceExpression is not called and that we directly go on to IdentifierExpression
     VisitExpression(statement.Expression, meth);
 }
Exemplo n.º 46
0
 public void VisitExpression(InvocationExpression expression, MethodProperties meth)
 {
     //Coupling.EvaluateMethodCoupling(expression, meth);
 }
			internal static void EvaluateMethodLOC(MethodProperties prop, List<LineSegment> text, Mono.TextEditor.Document doc)
			{
				ulong totalLines = 0, totalRealLines = 0, totalCommentedLines = 0;
				int realLines = 0;
				bool isSingleLineComment = false;
				bool isMultipleLineComment = false;
				
				int startIndex=prop.StartLine;
				int endIndex=prop.EndLine;
				
				for(int i=startIndex;i< endIndex;i++)
				{
					string lineText = "";
					try{
					lineText = doc.GetTextAt(text[i]).Trim();
					} catch (Exception e) {
						continue;
					}
					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++;	
				}
			
				totalLines     += (ulong)(endIndex-startIndex+1);
				totalRealLines += (ulong)realLines;
				((MethodProperties)prop).LOCComments = totalCommentedLines;
				((MethodProperties)prop).LOCReal = totalRealLines + 1;
			}		
Exemplo n.º 48
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;
            }
Exemplo n.º 49
0
			private static string ExtractCalleeFullName(MemberReferenceExpression expression, MethodProperties meth)
			{
				if(expression.Target is MemberReferenceExpression)
				{
					return ExtractCalleeFullName((MemberReferenceExpression)(expression.Target), meth)+"."+expression.MemberName; 
				}
				if(expression.Target is IdentifierExpression)
				{
					return ((IdentifierExpression)(expression.Target)).Identifier+"."+expression.MemberName;
				}
				return "";
			}
		private static StringBuilder GenerateMethodMetricText(MethodProperties item)
		{
			StringBuilder results = new StringBuilder();
			results.Append(GettextCatalog.GetString("\nName : " + item.FullName));
			results.Append(GettextCatalog.GetString("\nTotal number of local variables : " + item.NumberOfVariables));
			results.Append(GettextCatalog.GetString("\nTotal number of parameters : " + item.ParameterCount));
			results.Append(GettextCatalog.GetString("\nAfferent Coupling : " + item.AfferentCoupling));
			results.Append(GettextCatalog.GetString("\nEfferent Coupling : " + item.EfferentCoupling));
			
			return results;
		}
			public void VisitExpression (BinaryOperatorExpression expression, MethodProperties meth)
			{
				if(((BinaryOperatorExpression)expression).Op==BinaryOperatorType.LogicalAnd||((BinaryOperatorExpression)expression).Op==BinaryOperatorType.LogicalOr) {
					meth.CyclometricComplexity++;
					VisitExpression(((BinaryOperatorExpression)expression).Left , meth);
					VisitExpression(((BinaryOperatorExpression)expression).Right, meth);
				}
			}
Exemplo n.º 52
0
            private static List <string> ExtractParamList(InvocationExpression expression, MethodProperties meth)
            {
                List <string> retVal = new List <string>();

                foreach (Expression param in expression.Arguments)
                {
                    if (param is PrimitiveExpression)
                    {
                        retVal.Add(((PrimitiveExpression)param).Value.GetType().Name);
                        continue;
                    }
                    else if (param is BinaryOperatorExpression)
                    {
                        if (((BinaryOperatorExpression)param).Op == BinaryOperatorType.LogicalAnd || ((BinaryOperatorExpression)param).Op == BinaryOperatorType.LogicalOr)
                        {
                            retVal.Add("System.Boolean");
                        }
                        continue;
                    }
                    else if (param is InvocationExpression)
                    {
                        // TODO Deal with method calls within method calls
                        // Lots of cases
                        retVal.Add(EvaluateMethodCoupling((InvocationExpression)param, meth));
                    }
                }
                return(retVal);
            }