Author: spouliot
Date: 2008-02-16 10:51:54 -0500 (Sat, 16 Feb 2008)
New Revision: 95896

Modified:
   trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/AvoidLongMethodsRule.cs
   trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/ChangeLog
Log:
2008-02-16  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * AvoidLongMethodsRule.cs: Display actual and maximum IL instruction 
        counts if -v -v is supplied.



Modified: 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/AvoidLongMethodsRule.cs
===================================================================
--- 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/AvoidLongMethodsRule.cs   
    2008-02-16 15:14:19 UTC (rev 95895)
+++ 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/AvoidLongMethodsRule.cs   
    2008-02-16 15:51:54 UTC (rev 95896)
@@ -40,7 +40,7 @@
        [Solution ("You should apply an Extract Method refactoring, but there 
are other solutions.")]
        public class AvoidLongMethodsRule : Rule,IMethodRule {
                private int maxInstructions = 170;
-               const int AsignationRatio = 7;
+               const int AssignationRatio = 7;
                const int DefaultAmountOfElements = 13;
                static Hashtable typeMethodDictionary;
 
@@ -117,20 +117,21 @@
 
                        // rule applies!
                        // success if the instruction count is below the 
defined threshold
+                       int max = MaxInstructions;
                        if (method.IsConstructor && method.IsStatic) {
-                               if (method.Body.Instructions.Count <= 
MaxInstructions + (CountStaticFields (method.DeclaringType as TypeDefinition) * 
AsignationRatio))
-                                       return RuleResult.Success;
+                               max += CountStaticFields (method.DeclaringType 
as TypeDefinition) * AssignationRatio;
                        }
                        else if (method.IsConstructor && method.IsStatic) {
-                               if (method.Body.Instructions.Count <= 
MaxInstructions + (CountInstanceFields (method.DeclaringType as TypeDefinition) 
* AsignationRatio))
-                                       return RuleResult.Success;
+                               max += CountInstanceFields 
(method.DeclaringType as TypeDefinition) * AssignationRatio;
                        }
-                       else {
-                               if (method.Body.Instructions.Count <= 
MaxInstructions)
-                                       return RuleResult.Success;
-                       }
 
-                       Runner.Report (method, Severity.High, 
Confidence.Normal, "This method is long.");       
+                       if (method.Body.Instructions.Count <= max)
+                               return RuleResult.Success;
+
+                       string s = (Runner.VerbosityLevel < 2) ? String.Empty : 
+                               String.Format ("Method IL Size: {0}. Maximum 
Size: {1}", method.Body.Instructions.Count, max);
+
+                       Runner.Report (method, Severity.High, 
Confidence.Normal, s);    
                        return RuleResult.Failure;
                }
        }

Modified: trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/ChangeLog
===================================================================
--- trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/ChangeLog     
2008-02-16 15:14:19 UTC (rev 95895)
+++ trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/ChangeLog     
2008-02-16 15:51:54 UTC (rev 95896)
@@ -1,3 +1,8 @@
+2008-02-16  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * AvoidLongMethodsRule.cs: Display actual and maximum IL instruction 
+       counts if -v -v is supplied.
+
 2008-02-15  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * AvoidSpeculativeGeneralityRule.cs: Fix rule check since we now use

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to