Author: spouliot
Date: 2008-01-24 18:43:31 -0500 (Thu, 24 Jan 2008)
New Revision: 93865

Added:
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/ImplementEqualsAndGetHashCodeInPairRule.cs
Modified:
   trunk/cecil/gendarme/rules/Gendarme.Rules.Design/ChangeLog
   trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.xml.in
   trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Makefile.am
Log:
2008-01-24  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * ImplementEqualsAndGetHashCodeInPairRule.cs: This replace Gendarme.
        Rule.BadPractice.ImplementingEqualsButNotGetHashCodeAndViceVersaRule.
        Renamed, moved & rockified.
        * Gendarme.Rules.Design.xml.in: Moved description.
        * Makefile.am: Added (moved) rule and tests.



Modified: trunk/cecil/gendarme/rules/Gendarme.Rules.Design/ChangeLog
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Design/ChangeLog  2008-01-24 
23:42:19 UTC (rev 93864)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Design/ChangeLog  2008-01-24 
23:43:31 UTC (rev 93865)
@@ -1,3 +1,11 @@
+2008-01-24  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * ImplementEqualsAndGetHashCodeInPairRule.cs: This replace Gendarme.
+       Rule.BadPractice.ImplementingEqualsButNotGetHashCodeAndViceVersaRule.
+       Renamed, moved & rockified.
+       * Gendarme.Rules.Design.xml.in: Moved description.
+       * Makefile.am: Added (moved) rule and tests.
+
 2008-01-18  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * DisposableHelper.cs: Removed.

Modified: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.xml.in
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.xml.in   
    2008-01-24 23:42:19 UTC (rev 93864)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.xml.in   
    2008-01-24 23:43:31 UTC (rev 93865)
@@ -89,6 +89,12 @@
                <problem>The enumeration flag '{0}' defines a value of 0, which 
cannot be used as a real value.</problem>
                <solution>Remove the 0 value from the flag.</solution>
        </rule>
+       <rule   Name="ImplementEqualsAndGetHashCodeInPairRule" 
+               
Type="Gendarme.Rules.Design.ImplementEqualsAndGetHashCodeInPairRule, 
Gendarme.Rules.Design, [EMAIL PROTECTED]@, Culture=neutral, PublicKeyToken=null"
+               Uri="" >
+               <problem>Only one method of Equals(Object) or GetHashCode() is 
implemented in '{0}'.</problem>
+               <solution>Implement the missing method.</solution>
+       </rule>
        <rule   Name="MainShouldNotBePublicRule"
                Type="Gendarme.Rules.Design.MainShouldNotBePublicRule, 
Gendarme.Rules.Design, [EMAIL PROTECTED]@, Culture=neutral, PublicKeyToken=null"
                Uri="" >

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/ImplementEqualsAndGetHashCodeInPairRule.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/ImplementEqualsAndGetHashCodeInPairRule.cs
 2008-01-24 23:42:19 UTC (rev 93864)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/ImplementEqualsAndGetHashCodeInPairRule.cs
 2008-01-24 23:43:31 UTC (rev 93865)
@@ -0,0 +1,71 @@
+//
+// Gendarme.Rules.Design.ImplementEqualsAndGetHashCodeInPairRule
+//
+// Authors:
+//     Nidhi Rawal <[EMAIL PROTECTED]>
+//     Sebastien Pouliot <[EMAIL PROTECTED]>
+//
+// Copyright (c) <2007> Nidhi Rawal
+// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+                               
+using System;
+
+using Mono.Cecil;
+
+using Gendarme.Framework;
+using Gendarme.Framework.Rocks;
+
+namespace Gendarme.Rules.Design {
+
+       public class ImplementEqualsAndGetHashCodeInPairRule : ITypeRule {
+
+               private const string Message = "Type implements '{0}' but does 
not implement '{1}'";
+
+               public MessageCollection CheckType (TypeDefinition type, Runner 
runner)
+               {
+                       // rule doesn't apply to interfaces and enums
+                       if (type.IsInterface || type.IsEnum)
+                               return runner.RuleSuccess;
+
+                       bool equals = type.HasMethod (MethodSignatures.Equals);
+                       bool getHashCode = type.HasMethod 
(MethodSignatures.GetHashCode);
+
+                       // if we have Equals but no GetHashCode method
+                       if (equals && !getHashCode) {
+                               Location location = new Location (type);
+                               string text = String.Format (Message, 
MethodSignatures.Equals, MethodSignatures.GetHashCode);
+                               Message message = new Message (text, location, 
MessageType.Error);
+                               return new MessageCollection (message);
+                       }
+
+                       // if we have GetHashCode but no Equals method
+                       if (!equals && getHashCode) {
+                               Location location = new Location (type);
+                               string text = String.Format (Message, 
MethodSignatures.GetHashCode, MethodSignatures.Equals);
+                               Message message = new Message (text, location, 
MessageType.Warning);
+                               return new MessageCollection (message);
+                       }
+
+                       // we either have both Equals and GetHashCode or none 
(both fine)
+                       return runner.RuleSuccess;
+               }
+       }
+}

Modified: trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Makefile.am
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Makefile.am        
2008-01-24 23:42:19 UTC (rev 93864)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Makefile.am        
2008-01-24 23:43:31 UTC (rev 93865)
@@ -18,7 +18,7 @@
        TypesWithDisposableFieldsShouldBeDisposableRule.cs 
DisposableTypesShouldHaveFinalizerRule.cs \
        DisposableFieldsShouldBeDisposedRule.cs 
FinalizersShouldBeProtectedRule.cs 
FinalizersShouldCallBaseClassFinalizerRule.cs \
        EnsureSymmetryForOverloadedOperatorsRule.cs 
OperatorEqualsShouldBeOverloadedRule.cs \
-       OverrideEqualsMethodRule.cs 
ProvideAlternativeNamesForOperatorOverloadsRule.cs
+       OverrideEqualsMethodRule.cs 
ProvideAlternativeNamesForOperatorOverloadsRule.cs 
ImplementEqualsAndGetHashCodeInPairRule.cs
 
 design_rules_build_sources = $(addprefix $(srcdir)/, $(design_rules_sources))
 design_rules_build_sources += $(design_rules_generated_sources)
@@ -50,7 +50,7 @@
        TypesWithDisposableFieldsShouldBeDisposableTest.cs 
DisposableTypesShouldHaveFinalizerTest.cs \
        DisposableFieldsShouldBeDisposedTest.cs 
FinalizersShouldBeProtectedTest.cs 
FinalizersShouldCallBaseClassFinalizerTest.cs \
        EnsureSymmetryForOverloadedOperatorsTest.cs 
OperatorEqualsShouldBeOverloadedTest.cs OverrideEqualsMethodTest.cs \
-       ProvideAlternativeNamesForOperatorOverloadsTest.cs
+       ProvideAlternativeNamesForOperatorOverloadsTest.cs 
ImplementEqualsAndGetHashCodeInPairTest.cs
 
 design_test_build_sources = $(addprefix $(srcdir)/Test/, 
$(design_test_sources))
 

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

Reply via email to