Author: spouliot
Date: 2007-12-26 15:58:16 -0500 (Wed, 26 Dec 2007)
New Revision: 91905

Added:
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/AbstractTypesShouldNotHavePublicConstructorsRule.cs
   trunk/cecil/gendarme/rules/Gendarme.Rules.Design/AvoidEmptyInterfaceRule.cs
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/AvoidPropertiesWithoutGetAccessorRule.cs
   trunk/cecil/gendarme/rules/Gendarme.Rules.Design/DefineAZeroValueRule.cs
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/EnumsShouldDefineAZeroValueRule.cs
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/FlagsShouldNotDefineAZeroValueRule.cs
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/TypesShouldBeInsideNamespacesRule.cs
Modified:
   trunk/cecil/gendarme/rules/Gendarme.Rules.Design/ChangeLog
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/DontDeclareProtectedFieldsInSealedClassRule.cs
   trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.mdp
   trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.xml.in
   trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Makefile.am
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/UsingCloneWithoutImplementingICloneableRule.cs
Log:
2007-12-26  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * AbstractTypesShouldNotHavePublicConstructorsRule.cs: New. Rule
        to check for public constructors inside abstract classes.
        * AvoidEmptyInterfaceRule.cs: New. Rule to check for empty interfaces
        * AvoidPropertiesWithoutGetAccessorRule.cs: New. Rule to check for
        properties with only a setter.
        * DefineAZeroValueRule.cs: New. Abstract base class for 
        [EnumsShould|FlagsShouldNot]DefineAZeroValueRule.
        * DontDeclareProtectedFieldsInSealedClassRule.cs: Updated to use
        simpler Location ctor.
        * EnumsShouldDefineAZeroValueRule.cs: New. Rule to check that all
        enums, except flags, provide a 0 value.
        * FlagsShouldNotDefineAZeroValueRule.cs: New. Rule to check that all
        flags don't provide a 0 value.
        * TypesShouldBeInsideNamespacesRule.cs: New. Rule to check that 
        types are defined inside namspaces.
        * UsingCloneWithoutImplementingICloneableRule.cs: Updated to use
        simpler Location ctor and rocks.
        * Gendarme.Rules.Design.mdp: Add new files to MonoDevelop project file.
        * Gendarme.Rules.Design.xml.in: Update rules descriptions.
        * Makefile.am: Add new rules to the build.



Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/AbstractTypesShouldNotHavePublicConstructorsRule.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/AbstractTypesShouldNotHavePublicConstructorsRule.cs
        2007-12-26 20:57:36 UTC (rev 91904)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/AbstractTypesShouldNotHavePublicConstructorsRule.cs
        2007-12-26 20:58:16 UTC (rev 91905)
@@ -0,0 +1,59 @@
+// 
+// Gendarme.Rules.Design.AbstractTypesShouldNotHavePublicConstructorsRule
+//
+// Authors:
+//     Sebastien Pouliot  <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 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;
+
+namespace Gendarme.Rules.Design {
+
+       public class AbstractTypesShouldNotHavePublicConstructorsRule: 
ITypeRule {
+
+               public MessageCollection CheckType (TypeDefinition type, Runner 
runner)
+               {
+                       // rule apply only on abstract types
+                       if (!type.IsAbstract)
+                               return runner.RuleSuccess;
+
+                       // rule applies!
+
+                       MessageCollection mc = null;
+                       foreach (MethodDefinition ctor in type.Constructors) {
+                               if (ctor.IsPublic) {
+                                       Message msg = new Message ("Public 
constructor found.", new Location (ctor), MessageType.Warning);
+                                       if (mc == null)
+                                               mc = new MessageCollection 
(msg);
+                                       else
+                                               mc.Add (msg);
+                               }
+                       }
+
+                       return mc;
+               }
+       }
+}

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/AvoidEmptyInterfaceRule.cs
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Design/AvoidEmptyInterfaceRule.cs 
2007-12-26 20:57:36 UTC (rev 91904)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Design/AvoidEmptyInterfaceRule.cs 
2007-12-26 20:58:16 UTC (rev 91905)
@@ -0,0 +1,57 @@
+// 
+// Gendarme.Rules.Design.AvoidEmptyInterfaceRule
+//
+// Authors:
+//     Sebastien Pouliot  <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 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;
+
+namespace Gendarme.Rules.Design {
+
+       public class AvoidEmptyInterfaceRule : ITypeRule {
+
+               public MessageCollection CheckType (TypeDefinition type, Runner 
runner)
+               {
+                       // rule only applies to interfaces
+                       if (!type.IsInterface)
+                               return runner.RuleSuccess;
+
+                       // rule applies!
+
+                       // first check if the interface defines it's own members
+                       if (type.Methods.Count > 0)
+                               return runner.RuleSuccess;
+
+                       // otherwise it may implement more than one interface 
itself
+                       if (type.Interfaces.Count > 0)
+                               return runner.RuleSuccess;
+
+                       Message msg = new Message ("Interface is empty.", new 
Location (type), MessageType.Warning);
+                       return new MessageCollection (msg);
+               }
+       }
+}

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/AvoidPropertiesWithoutGetAccessorRule.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/AvoidPropertiesWithoutGetAccessorRule.cs
   2007-12-26 20:57:36 UTC (rev 91904)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/AvoidPropertiesWithoutGetAccessorRule.cs
   2007-12-26 20:58:16 UTC (rev 91905)
@@ -0,0 +1,63 @@
+// 
+// Gendarme.Rules.Design.AvoidPropertiesWithoutGetAccessorRule
+//
+// Authors:
+//     Sebastien Pouliot  <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 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 AvoidPropertiesWithoutGetAccessorRule : IMethodRule {
+
+               public MessageCollection CheckMethod (MethodDefinition method, 
Runner runner)
+               {
+                       // rule applies to setters
+                       if (!method.IsSetter ())
+                               return runner.RuleSuccess;
+
+                       // rule applies
+
+                       // check if there is a getter for the same property
+                       string name = method.Name.Replace ("set_", "get_");
+                       TypeDefinition type = method.DeclaringType as 
TypeDefinition;
+                       // inside the declaring type
+                       foreach (MethodDefinition md in type.Methods) {
+                               // look for the getter name
+                               if (md.Name == name) {
+                                       // and confirm it's getter
+                                       if (md.IsGetter ())
+                                               return runner.RuleSuccess;
+                               }
+                       }
+
+                       Message msg = new Message ("The property only provide a 
set (and no get)", new Location (method), MessageType.Warning);
+                       return new MessageCollection (msg);
+               }
+       }
+}

Modified: trunk/cecil/gendarme/rules/Gendarme.Rules.Design/ChangeLog
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Design/ChangeLog  2007-12-26 
20:57:36 UTC (rev 91904)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Design/ChangeLog  2007-12-26 
20:58:16 UTC (rev 91905)
@@ -1,3 +1,26 @@
+2007-12-26  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * AbstractTypesShouldNotHavePublicConstructorsRule.cs: New. Rule
+       to check for public constructors inside abstract classes.
+       * AvoidEmptyInterfaceRule.cs: New. Rule to check for empty interfaces
+       * AvoidPropertiesWithoutGetAccessorRule.cs: New. Rule to check for
+       properties with only a setter.
+       * DefineAZeroValueRule.cs: New. Abstract base class for 
+       [EnumsShould|FlagsShouldNot]DefineAZeroValueRule.
+       * DontDeclareProtectedFieldsInSealedClassRule.cs: Updated to use
+       simpler Location ctor.
+       * EnumsShouldDefineAZeroValueRule.cs: New. Rule to check that all
+       enums, except flags, provide a 0 value.
+       * FlagsShouldNotDefineAZeroValueRule.cs: New. Rule to check that all
+       flags don't provide a 0 value.
+       * TypesShouldBeInsideNamespacesRule.cs: New. Rule to check that 
+       types are defined inside namspaces.
+       * UsingCloneWithoutImplementingICloneableRule.cs: Updated to use
+       simpler Location ctor and rocks.
+       * Gendarme.Rules.Design.mdp: Add new files to MonoDevelop project file.
+       * Gendarme.Rules.Design.xml.in: Update rules descriptions.
+       * Makefile.am: Add new rules to the build.
+
 2007-11-22  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * DontDeclareProtectedFieldsInSealedClassRule.cs: Avoid creating

Added: trunk/cecil/gendarme/rules/Gendarme.Rules.Design/DefineAZeroValueRule.cs
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Design/DefineAZeroValueRule.cs    
2007-12-26 20:57:36 UTC (rev 91904)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Design/DefineAZeroValueRule.cs    
2007-12-26 20:58:16 UTC (rev 91905)
@@ -0,0 +1,55 @@
+// 
+// Gendarme.Rules.Design.DefineAZeroValueRule
+//
+// Authors:
+//     Sebastien Pouliot  <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 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;
+
+namespace Gendarme.Rules.Design {
+
+       abstract public class DefineAZeroValueRule {
+
+               protected static bool HasZeroValue (TypeDefinition type)
+               {
+                       foreach (FieldDefinition field in type.Fields) {
+                               switch (field.Name) {
+                               case "value__":
+                                       // special case
+                                       break;
+                               default:
+                                       if (field.Constant is int) {
+                                               if (((int) (field.Constant)) == 
0)
+                                                       return true;
+                                       }
+                                       break;
+                               }
+                       }
+                       return false;
+               }
+       }
+}

Modified: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/DontDeclareProtectedFieldsInSealedClassRule.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/DontDeclareProtectedFieldsInSealedClassRule.cs
     2007-12-26 20:57:36 UTC (rev 91904)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/DontDeclareProtectedFieldsInSealedClassRule.cs
     2007-12-26 20:58:16 UTC (rev 91905)
@@ -43,7 +43,7 @@
                        MessageCollection mc = null;
                        foreach (FieldDefinition field in type.Fields) {
                                if (field.IsFamily) {
-                                       Location location = new Location 
(type.FullName, type.Name, 0);
+                                       Location location = new Location (type);
                                        Message message = new Message ("This 
sealed class contains protected field(s)", location, MessageType.Error);
                                        if (mc == null)
                                                mc = new MessageCollection 
(message);

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/EnumsShouldDefineAZeroValueRule.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/EnumsShouldDefineAZeroValueRule.cs
 2007-12-26 20:57:36 UTC (rev 91904)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/EnumsShouldDefineAZeroValueRule.cs
 2007-12-26 20:58:16 UTC (rev 91905)
@@ -0,0 +1,57 @@
+// 
+// Gendarme.Rules.Design.EnumsShouldDefineAZeroValueRule
+//
+// Authors:
+//     Sebastien Pouliot  <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 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 EnumsShouldDefineAZeroValueRule : DefineAZeroValueRule, 
ITypeRule {
+
+               public MessageCollection CheckType (TypeDefinition type, Runner 
runner)
+               {
+                       // rule apply only on enums
+                       if (!type.IsEnum)
+                               return runner.RuleSuccess;
+
+                       // rule doesn't apply on [Flags]
+                       if (type.IsFlags ())
+                               return runner.RuleSuccess;
+
+                       // rule applies!
+
+                       if (HasZeroValue (type))
+                               return runner.RuleSuccess;
+
+                       Message msg = new Message ("Enum doesn't define a 0 
value.", new Location (type), MessageType.Error);
+                       return new MessageCollection (msg);
+               }
+       }
+}

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/FlagsShouldNotDefineAZeroValueRule.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/FlagsShouldNotDefineAZeroValueRule.cs
      2007-12-26 20:57:36 UTC (rev 91904)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/FlagsShouldNotDefineAZeroValueRule.cs
      2007-12-26 20:58:16 UTC (rev 91905)
@@ -0,0 +1,53 @@
+// 
+// Gendarme.Rules.Design.FlagsShouldNotDefineAZeroValueRule
+//
+// Authors:
+//     Sebastien Pouliot  <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 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 FlagsShouldNotDefineAZeroValueRule : DefineAZeroValueRule, 
ITypeRule {
+
+               public MessageCollection CheckType (TypeDefinition type, Runner 
runner)
+               {
+                       // rule apply only on [Flags] (this takes care of 
checking for enums)
+                       if (!type.IsFlags ())
+                               return runner.RuleSuccess;
+
+                       // rule applies!
+
+                       if (!HasZeroValue (type))
+                               return runner.RuleSuccess;
+
+                       Message msg = new Message ("Flags define a 0 value.", 
new Location (type), MessageType.Error);
+                       return new MessageCollection (msg);
+               }
+       }
+}

Modified: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.mdp
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.mdp  
2007-12-26 20:57:36 UTC (rev 91904)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.mdp  
2007-12-26 20:58:16 UTC (rev 91905)
@@ -1,22 +1,29 @@
 <Project name="Gendarme.Rules.Design" fileversion="2.0" language="C#" 
clr-version="Net_2_0" ctype="DotNetProject">
   <Configurations active="Debug">
     <Configuration name="Debug" ctype="DotNetProjectConfiguration">
-      <Output directory="../../bin" assembly="Gendarme.Rules.Design" />
+      <Output directory="../../bin" assemblyKeyFile="." 
assembly="Gendarme.Rules.Design" />
       <Build debugmode="True" target="Library" />
       <Execution runwithwarnings="True" consolepause="False" runtime="MsNet" 
clr-version="Net_2_0" />
-      <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" 
unsafecodeallowed="False" generateoverflowchecks="True" 
generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
+      <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" 
unsafecodeallowed="False" generateoverflowchecks="True" 
generatexmldocumentation="False" additionalargs="-langversion:linq" 
ctype="CSharpCompilerParameters" />
     </Configuration>
     <Configuration name="Release" ctype="DotNetProjectConfiguration">
-      <Output directory="./bin/Release" assembly="Gendarme.Rules.Design" />
+      <Output directory="bin/Release" assembly="Gendarme.Rules.Design" />
       <Build debugmode="False" target="Library" />
       <Execution runwithwarnings="True" consolepause="False" runtime="MsNet" 
clr-version="Net_2_0" />
-      <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" 
unsafecodeallowed="False" generateoverflowchecks="True" 
generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
+      <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" 
unsafecodeallowed="False" generateoverflowchecks="True" 
generatexmldocumentation="False" additionalargs="-langversion:linq" 
ctype="CSharpCompilerParameters" />
     </Configuration>
   </Configurations>
   <Contents>
-    <File name="./DontDeclareProtectedFieldsInSealedClassRule.cs" 
subtype="Code" buildaction="Compile" />
-    <File name="./Gendarme.Rules.Design.xml.in" subtype="Code" 
buildaction="Nothing" />
-    <File name="./UsingCloneWithoutImplementingICloneableRule.cs" 
subtype="Code" buildaction="Compile" />
+    <File name="DontDeclareProtectedFieldsInSealedClassRule.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="Gendarme.Rules.Design.xml.in" subtype="Code" 
buildaction="Nothing" />
+    <File name="UsingCloneWithoutImplementingICloneableRule.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="AbstractTypesShouldNotHavePublicConstructorsRule.cs" 
subtype="Code" buildaction="Compile" />
+    <File name="AvoidEmptyInterfaceRule.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="AvoidPropertiesWithoutGetAccessorRule.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="DefineAZeroValueRule.cs" subtype="Code" buildaction="Compile" 
/>
+    <File name="EnumsShouldDefineAZeroValueRule.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="FlagsShouldNotDefineAZeroValueRule.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="TypesShouldBeInsideNamespacesRule.cs" subtype="Code" 
buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Project" localcopy="True" refto="framework" />

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   
    2007-12-26 20:57:36 UTC (rev 91904)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.xml.in   
    2007-12-26 20:58:16 UTC (rev 91905)
@@ -1,14 +1,50 @@
 <rules>
-       <rule   Name="UsingCloneWithoutImplementingICloneableRule" 
-               
Type="Gendarme.Rules.Design.UsingCloneWithoutImplementingICloneableRule, 
Gendarme.Rules.Design, [EMAIL PROTECTED]@, Culture=neutral, PublicKeyToken=null"
-               
Uri="http://groups.google.com/group/gendarme/web/rules-documentation#UsingCloneWithoutImplementingICloneableRule";
 >
-               <problem>The class '{0}' uses Clone () method but does not 
implement ICloneable interface.</problem>
-               <solution>Implement the ICloneable interface.</solution>
+       <rule   Name="AbstractTypesShouldNotHavePublicConstructorsRule"
+               
Type="Gendarme.Rules.Design.AbstractTypesShouldNotHavePublicConstructorsRule, 
Gendarme.Rules.Design, [EMAIL PROTECTED]@, Culture=neutral, PublicKeyToken=null"
+               Uri="" >
+               <problem>The class '{0}' provides public 
constructor(s).</problem>
+               <solution>Change constructor visibility to protected.</solution>
        </rule>
+       <rule   Name="AvoidEmptyInterfaceRule"
+               Type="Gendarme.Rules.Design.AvoidEmptyInterfaceRule, 
Gendarme.Rules.Design, [EMAIL PROTECTED]@, Culture=neutral, PublicKeyToken=null"
+               Uri="" >
+               <problem>The interface '{0}' does not define any members. This 
is generally a sign that the interface is used as a marker.</problem>
+               <solution>Review interface. If used as a marker then see if it 
could be replaced by using attributes.</solution>
+       </rule>
+       <rule   Name="AvoidPropertiesWithoutGetAccessorRule"
+               
Type="Gendarme.Rules.Design.AvoidPropertiesWithoutGetAccessorRule, 
Gendarme.Rules.Design, [EMAIL PROTECTED]@, Culture=neutral, PublicKeyToken=null"
+               Uri="" >
+               <problem>The property '{0}' does not provide a getter.</problem>
+               <solution>Add a getter to the property or change the property 
into a method.</solution>
+       </rule>
        <rule   Name="DontDeclareProtectedFieldsInSealedClassRule" 
                
Type="Gendarme.Rules.Design.DontDeclareProtectedFieldsInSealedClassRule, 
Gendarme.Rules.Dodgy, [EMAIL PROTECTED]@, Culture=neutral, PublicKeyToken=null"
                
Uri="http://groups.google.com/group/gendarme/web/rules-documentation#DontDeclareProtectedFieldsInSealedClassRule";
 >
                <problem>The sealed class '{0}' contains protected 
field(s).</problem>
                <solution>Change the access specifier to public or private to 
represent the true use for the field.</solution>
        </rule>
+       <rule   Name="EnumsShouldDefineAZeroValueRule"
+               Type="Gendarme.Rules.Design.EnumsShouldDefineAZeroValueRule, 
Gendarme.Rules.Design, [EMAIL PROTECTED]@, Culture=neutral, PublicKeyToken=null"
+               Uri="" >
+               <problem>The enum '{0}' should define a member with a value of 
0.</problem>
+               <solution>Add a new member in the enum with a value of 
0.</solution>
+       </rule>
+       <rule   Name="FlagsShouldNotDefineAZeroValueRule"
+               Type="Gendarme.Rules.Design.FlagsShouldNotDefineAZeroValueRule, 
Gendarme.Rules.Design, [EMAIL PROTECTED]@, Culture=neutral, PublicKeyToken=null"
+               Uri="" >
+               <problem>The enum '{0}' is marked by a [Flag] attribute and 
should not include a value of 0.</problem>
+               <solution>Review the member that has a value of 0, it is either 
unneeded or cannot work as expected with binary logic operators.</solution>
+       </rule>
+       <rule   Name="TypesShouldBeInsideNamespacesRule"
+               Type="Gendarme.Rules.Design.TypesShouldBeInsideNamespacesRule, 
Gendarme.Rules.Design, [EMAIL PROTECTED]@, Culture=neutral, PublicKeyToken=null"
+               Uri="" >
+               <problem>The type '{0}' is visible and should be defined inside 
a namespace.</problem>
+               <solution>Move the type inside a namespace or reduce type 
visibility (e.g. internal or private).</solution>
+       </rule>
+       <rule   Name="UsingCloneWithoutImplementingICloneableRule" 
+               
Type="Gendarme.Rules.Design.UsingCloneWithoutImplementingICloneableRule, 
Gendarme.Rules.Design, [EMAIL PROTECTED]@, Culture=neutral, PublicKeyToken=null"
+               
Uri="http://groups.google.com/group/gendarme/web/rules-documentation#UsingCloneWithoutImplementingICloneableRule";
 >
+               <problem>The class '{0}' uses Clone () method but does not 
implement ICloneable interface.</problem>
+               <solution>Implement the ICloneable interface.</solution>
+       </rule>
 </rules>

Modified: trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Makefile.am
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Makefile.am        
2007-12-26 20:57:36 UTC (rev 91904)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Makefile.am        
2007-12-26 20:58:16 UTC (rev 91905)
@@ -9,13 +9,16 @@
 
 design_rules_sources_in = ../../AssemblyInfo.cs.in
 design_rules_generated_sources = $(design_rules_sources_in:.in=)
-design_rules_sources = DontDeclareProtectedFieldsInSealedClassRule.cs 
UsingCloneWithoutImplementingICloneableRule.cs
+design_rules_sources = DontDeclareProtectedFieldsInSealedClassRule.cs 
UsingCloneWithoutImplementingICloneableRule.cs \
+       DefineAZeroValueRule.cs EnumsShouldDefineAZeroValueRule.cs 
FlagsShouldNotDefineAZeroValueRule.cs \
+       AbstractTypesShouldNotHavePublicConstructorsRule.cs 
AvoidEmptyInterfaceRule.cs TypesShouldBeInsideNamespacesRule.cs \
+       AvoidPropertiesWithoutGetAccessorRule.cs
 
 design_rules_build_sources = $(addprefix $(srcdir)/, $(design_rules_sources))
 design_rules_build_sources += $(design_rules_generated_sources)
 
 ../../bin/Gendarme.Rules.Design.dll: $(design_rules_build_sources)
-       $(MCS) -debug -target:library -pkg:mono-cecil 
-r:../../bin/Gendarme.Framework.dll -out:$@ $(design_rules_build_sources)
+       $(MCS) -debug -target:library -langversion:linq -pkg:mono-cecil 
-r:../../bin/Gendarme.Framework.dll -out:$@ $(design_rules_build_sources)
        cp Gendarme.Rules.*.xml ../../bin/
 
 # Install Unstable Mono Libraries (see configure.ac)
@@ -32,7 +35,11 @@
                rm -f $(DESTDIR)$(pkglibdir)/`basename $$ASM`; \
        done;
 
-design_test_sources = DontDeclareProtectedFieldsInSealedClassTest.cs 
UsingCloneWithoutImplementingICloneableTest.cs
+design_test_sources = DontDeclareProtectedFieldsInSealedClassTest.cs 
UsingCloneWithoutImplementingICloneableTest.cs \
+       EnumsShouldDefineAZeroValueTest.cs 
FlagsShouldNotDefineAZeroValueTest.cs \
+       AbstractTypesShouldNotHavePublicConstructorsTest.cs 
AvoidEmptyInterfaceTest.cs TypesShouldBeInsideNamespacesTest.cs \
+       AvoidPropertiesWithoutGetAccessorTest.cs
+
 design_test_build_sources = $(addprefix $(srcdir)/Test/, 
$(design_test_sources))
 
 Test.Rules.Design.dll: $(design_rules_build_sources) $(design_rules_SCRIPTS)

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/TypesShouldBeInsideNamespacesRule.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/TypesShouldBeInsideNamespacesRule.cs
       2007-12-26 20:57:36 UTC (rev 91904)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/TypesShouldBeInsideNamespacesRule.cs
       2007-12-26 20:58:16 UTC (rev 91905)
@@ -0,0 +1,56 @@
+// 
+// Gendarme.Rules.Design.TypesShouldBeInsideNamespacesRule
+//
+// Authors:
+//     Sebastien Pouliot  <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 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;
+
+namespace Gendarme.Rules.Design {
+
+       public class TypesShouldBeInsideNamespacesRule: ITypeRule {
+
+               public MessageCollection CheckType (TypeDefinition type, Runner 
runner)
+               {
+                       // rule applies to public types
+                       if (!type.IsPublic && !(type.IsNestedPublic || 
type.IsNestedFamily))
+                               return runner.RuleSuccess;
+
+                       // rule applies!
+
+                       // if the type is nested then check our declaring type 
namespace
+                       string ns = type.IsNested ? (type.DeclaringType as 
TypeDefinition).Namespace : type.Namespace;
+
+                       // check if the type resides inside a namespace
+                       if (ns.Length > 0)
+                               return runner.RuleSuccess;
+
+                       Message msg = new Message ("Type is not declared inside 
a namespace.", new Location (type), MessageType.Warning);
+                       return new MessageCollection (msg);
+               }
+       }
+}

Modified: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/UsingCloneWithoutImplementingICloneableRule.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/UsingCloneWithoutImplementingICloneableRule.cs
     2007-12-26 20:57:36 UTC (rev 91904)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/UsingCloneWithoutImplementingICloneableRule.cs
     2007-12-26 20:58:16 UTC (rev 91905)
@@ -29,23 +29,16 @@
 using System;
 
 using Mono.Cecil;
+
 using Gendarme.Framework;
+using Gendarme.Framework.Rocks;
 
 namespace Gendarme.Rules.Design {
 
        public class UsingCloneWithoutImplementingICloneableRule: ITypeRule {
 
-               private bool ImplementsICloneable (TypeDefinition type)
-               {
-                       foreach (TypeReference iface in type.Interfaces) {
-                               if (iface.FullName == "System.ICloneable")
-                                       return true;
-                       }
-                       return false;
-               }
-
                // copy-pasted from 
gendarme\rules\Gendarme.Rules.BadPractice\CloneMethodShouldNotReturnNullRule.cs
-               private bool IsCloneMethod (MethodDefinition method)
+               private static bool IsCloneMethod (MethodDefinition method)
                {
                        return (method.Name == "Clone" && 
(method.Parameters.Count == 0));
                }
@@ -53,7 +46,7 @@
                public MessageCollection CheckType (TypeDefinition type, Runner 
runner)
                {
                        // rule applies to type that doesn't implement 
System.IClonable
-                       if (ImplementsICloneable (type))
+                       if (type.Implements ("System.ICloneable"))
                                return runner.RuleSuccess;
 
                        MessageCollection mc = null;
@@ -65,7 +58,7 @@
                                // that return System.Object, e.g. public 
object Clone()
                                // or the current type, e.g. public <type> 
Clone()
                                if ((method.ReturnType.ReturnType.FullName == 
"System.Object") || (method.ReturnType.ReturnType == type)) {
-                                       Location location = new Location 
(type.FullName, type.Name, 0);
+                                       Location location = new Location (type);
                                        Message message = new Message ("A 
Clone() method is provided but System.ICloneable is not implemented", location, 
MessageType.Error);
                                        if (mc == null)
                                                mc = new MessageCollection 
(message);

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

Reply via email to