Author: spouliot
Date: 2008-02-16 16:00:29 -0500 (Sat, 16 Feb 2008)
New Revision: 95920

Modified:
   trunk/mono-tools/gendarme/framework/Gendarme.Framework/ChangeLog
   trunk/mono-tools/gendarme/framework/Gendarme.Framework/Defect.cs
   trunk/mono-tools/gendarme/framework/Gendarme.Framework/TestRunner.cs
Log:
2008-02-16  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * Defect.cs: Make ExtractFirst methods static. Rename 
        Get[Type|Method]FromLocation to Find*
        * TestRunner.cs: Avoid code duplication in Check* methods.



Modified: trunk/mono-tools/gendarme/framework/Gendarme.Framework/ChangeLog
===================================================================
--- trunk/mono-tools/gendarme/framework/Gendarme.Framework/ChangeLog    
2008-02-16 20:38:41 UTC (rev 95919)
+++ trunk/mono-tools/gendarme/framework/Gendarme.Framework/ChangeLog    
2008-02-16 21:00:29 UTC (rev 95920)
@@ -1,3 +1,9 @@
+2008-02-16  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * Defect.cs: Make ExtractFirst methods static. Rename 
+       Get[Type|Method]FromLocation to Find*
+       * TestRunner.cs: Avoid code duplication in Check* methods.
+
 2008-02-15  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * AssemblyResolver.cs: Handle GenericParameter.

Modified: trunk/mono-tools/gendarme/framework/Gendarme.Framework/Defect.cs
===================================================================
--- trunk/mono-tools/gendarme/framework/Gendarme.Framework/Defect.cs    
2008-02-16 20:38:41 UTC (rev 95919)
+++ trunk/mono-tools/gendarme/framework/Gendarme.Framework/Defect.cs    
2008-02-16 21:00:29 UTC (rev 95920)
@@ -90,7 +90,7 @@
                        get { return severity; }
                }
 
-               private Instruction ExtractFirst (TypeDefinition type)
+               private static Instruction ExtractFirst (TypeDefinition type)
                {
                        if (type == null)
                                return null;
@@ -102,7 +102,7 @@
                        return null;
                }
 
-               private Instruction ExtractFirst (MethodDefinition method)
+               private static Instruction ExtractFirst (MethodDefinition 
method)
                {
                        if ((method == null) || !method.HasBody)
                                return null;
@@ -110,7 +110,7 @@
                        return (ins.SequencePoint != null) ? ins : null;
                }
 
-               private TypeDefinition GetTypeFromLocation ()
+               private TypeDefinition FindTypeFromLocation ()
                {
                        MethodDefinition method = (location as 
MethodDefinition);
                        if (method != null)
@@ -127,7 +127,7 @@
                        return (location as TypeDefinition);
                }
 
-               private MethodDefinition GetMethodFromLocation ()
+               private MethodDefinition FindMethodFromLocation ()
                {
                        ParameterDefinition parameter = (location as 
ParameterDefinition);
                        if (parameter != null)
@@ -163,7 +163,7 @@
 
                                // MethodDefinition, ParameterDefinition
                                //      return the method source file with 
(appromixate) line number
-                               MethodDefinition method = GetMethodFromLocation 
();
+                               MethodDefinition method = 
FindMethodFromLocation ();
                                if (method != null) {
                                        candidate = ExtractFirst (method);
                                        if (candidate != null) {
@@ -180,7 +180,7 @@
                                // TypeDefinition, FieldDefinition
                                //      return the type source file (based on 
the first ctor)
                                if (type == null)
-                                       type = GetTypeFromLocation ();
+                                       type = FindTypeFromLocation ();
                                candidate = ExtractFirst (type);
                                if (candidate != null) {
                                        // we report only the source file of 
the first ctor (that reported something)

Modified: trunk/mono-tools/gendarme/framework/Gendarme.Framework/TestRunner.cs
===================================================================
--- trunk/mono-tools/gendarme/framework/Gendarme.Framework/TestRunner.cs        
2008-02-16 20:38:41 UTC (rev 95919)
+++ trunk/mono-tools/gendarme/framework/Gendarme.Framework/TestRunner.cs        
2008-02-16 21:00:29 UTC (rev 95920)
@@ -24,6 +24,8 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 
+using System;
+
 using Mono.Cecil;
 
 namespace Gendarme.Framework {
@@ -50,24 +52,29 @@
                        CurrentRule.Initialize (this);
                }
 
+               private void PreCheck (IMetadataTokenProvider obj)
+               {
+                       if (obj == null)
+                               throw new ArgumentNullException ("obj", "Cannot 
check a null object");
+                       Reset ();
+                       CurrentTarget = obj;
+               }
+
                public RuleResult CheckAssembly (AssemblyDefinition assembly)
                {
-                       Reset ();
-                       CurrentTarget = assembly;
+                       PreCheck (assembly);
                        return (CurrentRule as IAssemblyRule).CheckAssembly 
(assembly);
                }
 
                public RuleResult CheckType (TypeDefinition type)
                {
-                       Reset ();
-                       CurrentTarget = type;
+                       PreCheck (type);
                        return (CurrentRule as ITypeRule).CheckType (type);
                }
 
                public RuleResult CheckMethod (MethodDefinition method)
                {
-                       Reset ();
-                       CurrentTarget = method;
+                       PreCheck (method);
                        return (CurrentRule as IMethodRule).CheckMethod 
(method);
                }
        }

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

Reply via email to