Author: spouliot
Date: 2007-10-07 19:04:34 -0400 (Sun, 07 Oct 2007)
New Revision: 87063
Added:
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/
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/Test/
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/ChangeLog
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/DontDeclareProtectedFieldsInSealedClassTest.cs
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/Test.Rules.Design.mdp
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/UsingCloneWithoutImplementingICloneableTest.cs
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/UsingCloneWithoutImplementingICloneableRule.cs
Log:
Integrate some GSoC 2007 work and update project files
Added: trunk/cecil/gendarme/rules/Gendarme.Rules.Design/ChangeLog
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Design/ChangeLog 2007-10-07
22:59:20 UTC (rev 87062)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Design/ChangeLog 2007-10-07
23:04:34 UTC (rev 87063)
@@ -0,0 +1,9 @@
+2007-10-07 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * DontDeclareProtectedFieldsInSealedClassRule.cs: New rule (Nidhi
+ Rawal, GSoC 2007)
+ * UsingCloneWithoutImplementingICloneableRule.cs: New rule (Nidhi
+ Rawal, GSoC 2007)
+ * Gendarme.Rules.Design.mdp: New. Project file for MonoDevelop.
+ * Gendarme.Rules.Design.xml.in: New. Rule descriptions.
+ * Makefile.am: New. Build file for rules and unit tests.
Added:
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/DontDeclareProtectedFieldsInSealedClassRule.cs
===================================================================
---
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/DontDeclareProtectedFieldsInSealedClassRule.cs
2007-10-07 22:59:20 UTC (rev 87062)
+++
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/DontDeclareProtectedFieldsInSealedClassRule.cs
2007-10-07 23:04:34 UTC (rev 87063)
@@ -0,0 +1,55 @@
+//
+// Gendarme.Rules.Dodgy.DontDeclareProtectedFieldsInSealedClassRule
+//
+// Authors:
+// Nidhi Rawal <[EMAIL PROTECTED]>
+//
+// Copyright (c) <2007> Nidhi Rawal
+//
+// 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 System.Collections;
+
+using Mono.Cecil;
+using Mono.Cecil.Cil;
+using Gendarme.Framework;
+
+namespace Gendarme.Rules.Design
+{
+ public class DontDeclareProtectedFieldsInSealedClassRule: ITypeRule
+ {
+ public MessageCollection CheckType (TypeDefinition type, Runner
runner)
+ {
+ MessageCollection messageCollection = new
MessageCollection ();
+ if (type.IsSealed) {
+ foreach (FieldDefinition field in type.Fields) {
+ if (field.Attributes.ToString () ==
"Family") {
+ Location location = new
Location (type.FullName, type.Name, 0);
+ Message message = new Message
("This sealed class contains protected field(s)", location, MessageType.Error);
+ messageCollection.Add (message);
+ }
+ }
+ }
+ if (messageCollection.Count == 0)
+ return null;
+ return messageCollection;
+ }
+ }
+}
\ No newline at end of file
Added:
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.mdp
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.mdp
2007-10-07 22:59:20 UTC (rev 87062)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.mdp
2007-10-07 23:04:34 UTC (rev 87063)
@@ -0,0 +1,27 @@
+<Project name="Gendarme.Rules.Design" fileversion="2.0" language="C#"
clr-version="Net_1_1" ctype="DotNetProject">
+ <Configurations active="Debug">
+ <Configuration name="Debug" ctype="DotNetProjectConfiguration">
+ <Output directory="./bin/Debug" assembly="Gendarme.Rules.Design" />
+ <Build debugmode="True" target="Library" />
+ <Execution runwithwarnings="True" consolepause="False" runtime="MsNet"
clr-version="Net_1_1" />
+ <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True"
unsafecodeallowed="False" generateoverflowchecks="True"
generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
+ </Configuration>
+ <Configuration name="Release" ctype="DotNetProjectConfiguration">
+ <Output directory="./bin/Release" assembly="Gendarme.Rules.Design" />
+ <Build debugmode="False" target="Library" />
+ <Execution runwithwarnings="True" consolepause="False" runtime="MsNet"
clr-version="Net_1_1" />
+ <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True"
unsafecodeallowed="False" generateoverflowchecks="True"
generatexmldocumentation="False" 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" />
+ </Contents>
+ <References>
+ <ProjectReference type="Gac" localcopy="True" refto="System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+ <ProjectReference type="Project" localcopy="True" refto="framework" />
+ <ProjectReference type="Assembly" localcopy="True"
refto="../../../lib/Mono.Cecil.dll" />
+ </References>
+ <Deployment.LinuxDeployData generatePcFile="False" />
+</Project>
\ No newline at end of file
Added:
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-10-07 22:59:20 UTC (rev 87062)
+++
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.xml.in
2007-10-07 23:04:34 UTC (rev 87063)
@@ -0,0 +1,14 @@
+<rules>
+ <rule Name="UsingCloneWithoutImplementingICloneableRule"
+
Type="Gendarme.Rules.Design.UsingCloneWithoutImplementingICloneableRule,
Gendarme.Rules.Design, [EMAIL PROTECTED]@, Culture=neutral, PublicKeyToken=null"
+ Uri="" >
+ <problem>The class '{0}' uses Clone () method but does not
implement ICloneable interface.</problem>
+ <solution>Implement the ICloneable interface.</solution>
+ </rule>
+ <rule Name="DontDeclareProtectedFieldsInSealedClassRule"
+
Type="Gendarme.Rules.Design.DontDeclareProtectedFieldsInSealedClassRule,
Gendarme.Rules.Dodgy, [EMAIL PROTECTED]@, Culture=neutral, PublicKeyToken=null"
+ Uri="" >
+ <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>
+</rules>
Added: trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Makefile.am
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Makefile.am
2007-10-07 22:59:20 UTC (rev 87062)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Makefile.am
2007-10-07 23:04:34 UTC (rev 87063)
@@ -0,0 +1,47 @@
+SUBDIRS=Test
+
+design_rulesdir=$(pkglibdir)
+design_rules_SCRIPTS = Gendarme.Rules.Design.dll
+EXTRA_DIST = $(design_rules_sources) $(design_rules_sources_in)
Gendarme.Rules.Design.xml \
+ Gendarme.Rules.Design.mdp Gendarme.Rules.Design.csproj
+CLEANFILES = Gendarme.Rules.Design.dll Test.Rules.Design.dll
+DISTCLEANFILES = Makefile.in Gendarme.Rules.Design.xml TestResult.xml
+
+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_build_sources = $(addprefix $(srcdir)/, $(design_rules_sources))
+design_rules_build_sources += $(design_rules_generated_sources)
+
+Gendarme.Rules.Design.dll: $(design_rules_build_sources)
+ $(MCS) -target:library -pkg:mono-cecil
-r:../../framework/Gendarme.Framework.dll -out:$@ $(design_rules_build_sources)
+
+# Install Unstable Mono Libraries (see configure.ac)
+
+install-data-hook:
+ $(INSTALL) -c -m 0644 Gendarme.Rules.Design.xml $(DESTDIR)$(pkglibdir);
+ for ASM in $(INSTALLED_ASSEMBLIES); do \
+ $(INSTALL) -c -m 0755 $$ASM $(DESTDIR)$(pkglibdir); \
+ done;
+
+uninstall-hook:
+ rm -f $(DESTDIR)$(pkglibdir)/`basename Gendarme.Rules.Design.xml`;
+ for ASM in $(INSTALLED_ASSEMBLIES); do \
+ rm -f $(DESTDIR)$(pkglibdir)/`basename $$ASM`; \
+ done;
+
+design_test_sources = DontDeclareProtectedFieldsInSealedClassTest.cs
UsingCloneWithoutImplementingICloneableTest.cs
+design_test_build_sources = $(addprefix $(srcdir)/Test/,
$(design_test_sources))
+
+Test.Rules.Design.dll: $(design_rules_build_sources)
+ $(MCS) -target:library -pkg:mono-cecil -pkg:mono-nunit
-r:../../framework/Gendarme.Framework.dll \
+ -r:Gendarme.Rules.Design.dll -out:$@
$(design_test_build_sources)
+
+test: Gendarme.Rules.Design.dll Test.Rules.Design.dll
+
+run-test: Gendarme.Rules.Design.dll Test.Rules.Design.dll
+ MONO_PATH=../../framework/:$(CECIL_PATH):$(MONO_PATH) nunit-console
Test.Rules.Design.dll
+
+self-test: test
+ gendarme Gendarme.Rules.Design.dll
Added: trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/ChangeLog
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/ChangeLog
2007-10-07 22:59:20 UTC (rev 87062)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/ChangeLog
2007-10-07 23:04:34 UTC (rev 87063)
@@ -0,0 +1,7 @@
+2007-10-07 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * DontDeclareProtectedFieldsInSealedClassTest.cs: Unit tests (Nidhi
+ Rawal, GSoC 2007)
+ * UsingCloneWithoutImplementingICloneableTest.cs: Unit tests (Nidhi
+ Rawal, GSoC 2007)
+ * Test.Rules.Design.mdp: New. Project file for MonoDevelop.
Added:
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/DontDeclareProtectedFieldsInSealedClassTest.cs
===================================================================
---
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/DontDeclareProtectedFieldsInSealedClassTest.cs
2007-10-07 22:59:20 UTC (rev 87062)
+++
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/DontDeclareProtectedFieldsInSealedClassTest.cs
2007-10-07 23:04:34 UTC (rev 87063)
@@ -0,0 +1,103 @@
+//
+// Unit tests for DontDeclareProtectedFieldsInSealedClassRule
+//
+// Authors:
+// Nidhi Rawal <[EMAIL PROTECTED]>
+//
+// Copyright (c) <2007> Nidhi Rawal
+//
+// 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 System.Reflection;
+
+using Gendarme.Framework;
+using Gendarme.Rules.Design;
+using Mono.Cecil;
+using NUnit.Framework;
+
+namespace Test.Rules.Design
+{
+ [TestFixture]
+ public class DontDeclareProtectedFieldsInSealedClassTest {
+
+ public sealed class UnInheritableClassWithProtectedField
+ {
+ protected int i;
+ protected double d;
+ }
+
+ public sealed class UnInheritableClassWithoutProtectedFields
+ {
+ public string s;
+ private float f;
+ }
+
+ public class InheritableClassWithProtectedFields
+ {
+ protected double d;
+ protected int j;
+ }
+
+ private ITypeRule typeRule;
+ private AssemblyDefinition assembly;
+ private TypeDefinition type;
+ MessageCollection messageCollection;
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ string unit = Assembly.GetExecutingAssembly ().Location;
+ assembly = AssemblyFactory.GetAssembly (unit);
+ typeRule = new
DontDeclareProtectedFieldsInSealedClassRule();
+ messageCollection = null;
+ }
+
+ private TypeDefinition GetTest (string name)
+ {
+ string fullname =
"Test.Rules.Design.DontDeclareProtectedFieldsInSealedClassTest/" + name;
+ return assembly.MainModule.Types[fullname];
+ }
+
+ [Test]
+ public void unInheritableClassWithProtectedFieldTest ()
+ {
+ type = GetTest ("UnInheritableClassWithProtectedField");
+ messageCollection = typeRule.CheckType (type, new
MinimalRunner ());
+ Assert.IsNotNull (messageCollection);
+ Assert.AreEqual (2, messageCollection.Count);
+ }
+
+ [Test]
+ public void unInheritableClassWithoutProtectedFieldsTest ()
+ {
+ type = GetTest
("UnInheritableClassWithoutProtectedFields");
+ messageCollection = typeRule.CheckType (type, new
MinimalRunner ());
+ Assert.IsNull (messageCollection);
+ }
+
+ [Test]
+ public void inheritableClassWithProtectedFieldsTest ()
+ {
+ type = GetTest ("InheritableClassWithProtectedFields");
+ messageCollection = typeRule.CheckType (type, new
MinimalRunner ());
+ Assert.IsNull (messageCollection);
+ }
+ }
+}
\ No newline at end of file
Added:
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/Test.Rules.Design.mdp
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/Test.Rules.Design.mdp
2007-10-07 22:59:20 UTC (rev 87062)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/Test.Rules.Design.mdp
2007-10-07 23:04:34 UTC (rev 87063)
@@ -0,0 +1,27 @@
+<Project name="Test.Rules.Design" fileversion="2.0" language="C#"
clr-version="Net_1_1" ctype="DotNetProject">
+ <Configurations active="Debug">
+ <Configuration name="Debug" ctype="DotNetProjectConfiguration">
+ <Output directory="./bin/Debug" assembly="Test.Rules.Design" />
+ <Build debugmode="True" target="Library" />
+ <Execution runwithwarnings="True" consolepause="False" runtime="MsNet"
clr-version="Net_1_1" />
+ <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True"
unsafecodeallowed="False" generateoverflowchecks="True"
generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
+ </Configuration>
+ <Configuration name="Release" ctype="DotNetProjectConfiguration">
+ <Output directory="./bin/Release" assembly="Test.Rules.Design" />
+ <Build debugmode="False" target="Library" />
+ <Execution runwithwarnings="True" consolepause="False" runtime="MsNet"
clr-version="Net_1_1" />
+ <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True"
unsafecodeallowed="False" generateoverflowchecks="True"
generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
+ </Configuration>
+ </Configurations>
+ <Contents>
+ <File name="./DontDeclareProtectedFieldsInSealedClassTest.cs"
subtype="Code" buildaction="Compile" />
+ <File name="./UsingCloneWithoutImplementingICloneableTest.cs"
subtype="Code" buildaction="Compile" />
+ </Contents>
+ <References>
+ <ProjectReference type="Gac" localcopy="True" refto="System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+ <ProjectReference type="Assembly" localcopy="True"
refto="../../../../lib/Mono.Cecil.dll" />
+ <ProjectReference type="Gac" localcopy="True" refto="nunit.framework,
Version=2.2.0.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
+ <ProjectReference type="Project" localcopy="True" refto="framework" />
+ <ProjectReference type="Project" localcopy="True"
refto="Gendarme.Rules.Design" />
+ </References>
+</Project>
\ No newline at end of file
Added:
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/UsingCloneWithoutImplementingICloneableTest.cs
===================================================================
---
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/UsingCloneWithoutImplementingICloneableTest.cs
2007-10-07 22:59:20 UTC (rev 87062)
+++
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/Test/UsingCloneWithoutImplementingICloneableTest.cs
2007-10-07 23:04:34 UTC (rev 87063)
@@ -0,0 +1,140 @@
+//
+// Unit tests for UsingCloneWithoutImplementingICloneableRule
+//
+// Authors:
+// Nidhi Rawal <[EMAIL PROTECTED]>
+//
+// Copyright (c) <2007> Nidhi Rawal
+//
+// 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 System.Reflection;
+
+using Gendarme.Framework;
+using Gendarme.Rules.Design;
+using Mono.Cecil;
+using NUnit.Framework;
+
+namespace Test.Rules.Design
+{
+ [TestFixture]
+ public class UsingCloneWithoutImplementingICloneableTest {
+ public class UsingCloneAndImplementingICloneable: ICloneable
+ {
+ public object Clone ()
+ {
+ return this.MemberwiseClone ();
+ }
+ }
+
+ public class UsingCloneWithoutImplementingICloneable
+ {
+ public object Clone ()
+ {
+ return this.MemberwiseClone ();
+ }
+ }
+
+ public class NeitherUsingCloneNorImplementingICloneable
+ {
+ public object clone ()
+ {
+ return this;
+ }
+ }
+
+ public class AnotherExampleOfNotUsingBoth
+ {
+ public int Clone ()
+ {
+ return 1;
+ }
+ }
+
+ public class OneMoreExample
+ {
+ public object Clone (int i)
+ {
+ return this.MemberwiseClone ();
+ }
+ }
+
+ private ITypeRule typeRule;
+ private AssemblyDefinition assembly;
+ private TypeDefinition type;
+ MessageCollection messageCollection;
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ string unit = Assembly.GetExecutingAssembly ().Location;
+ assembly = AssemblyFactory.GetAssembly (unit);
+ typeRule = new
UsingCloneWithoutImplementingICloneableRule ();
+ messageCollection = null;
+ }
+
+ private TypeDefinition GetTest (string name)
+ {
+ string fullname =
"Test.Rules.Design.UsingCloneWithoutImplementingICloneableTest/" + name;
+ return assembly.MainModule.Types[fullname];
+ }
+
+ [Test]
+ public void usingCloneAndImplementingICloneableTest ()
+ {
+ type = GetTest ("UsingCloneAndImplementingICloneable");
+ messageCollection = typeRule.CheckType (type, new
MinimalRunner ());
+ Assert.IsNull (messageCollection);
+ }
+
+ [Test]
+ public void usingCloneWithoutImplementingICloneableTest ()
+ {
+ type = GetTest
("UsingCloneWithoutImplementingICloneable");
+ messageCollection = typeRule.CheckType (type, new
MinimalRunner ());
+ Assert.IsNotNull (messageCollection);
+ Assert.AreEqual (1, messageCollection.Count);
+ }
+
+ [Test]
+ public void neitherUsingCloneNorImplementingICloneableTest ()
+ {
+ type = GetTest
("NeitherUsingCloneNorImplementingICloneable");
+ messageCollection = typeRule.CheckType (type, new
MinimalRunner ());
+ Assert.IsNull (messageCollection);
+ }
+
+ [Test]
+ public void anotherExampleOfNotUsingBothTest ()
+ {
+ type = GetTest ("AnotherExampleOfNotUsingBoth");
+ messageCollection = typeRule.CheckType (type, new
MinimalRunner ());
+ Assert.IsNull (messageCollection);
+ }
+
+ [Test]
+ public void OneMoreExampleTest ()
+ {
+ type = GetTest ("OneMoreExample");
+ messageCollection = typeRule.CheckType (type, new
MinimalRunner ());
+ Assert.IsNull (messageCollection);
+ }
+ }
+}
\ No newline at end of file
Added:
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/UsingCloneWithoutImplementingICloneableRule.cs
===================================================================
---
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/UsingCloneWithoutImplementingICloneableRule.cs
2007-10-07 22:59:20 UTC (rev 87062)
+++
trunk/cecil/gendarme/rules/Gendarme.Rules.Design/UsingCloneWithoutImplementingICloneableRule.cs
2007-10-07 23:04:34 UTC (rev 87063)
@@ -0,0 +1,62 @@
+//
+// Gendarme.Rules.Design.UsingCloneWithoutImplementingICloneableRule
+//
+// Authors:
+// Nidhi Rawal <[EMAIL PROTECTED]>
+//
+// Copyright (c) <2007> Nidhi Rawal
+//
+// 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 System.Collections;
+
+using Mono.Cecil;
+using Mono.Cecil.Cil;
+using Gendarme.Framework;
+
+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;
+ }
+
+ public MessageCollection CheckType (TypeDefinition type, Runner
runner)
+ {
+ MessageCollection messageCollection = new
MessageCollection ();
+ if (!ImplementsICloneable (type))
+ foreach (MethodDefinition method in
type.Methods)
+ if (method.Name == "Clone" &&
method.ReturnType.ReturnType.ToString ().Equals ("System.Object") &&
method.Parameters.Count == 0) {
+ Location location = new
Location (type.FullName, type.Name, 0);
+ Message message = new Message
("The Clone () method is used, but ICloneable is not implemented", location,
MessageType.Error);
+ messageCollection.Add (message);
+ }
+
+ if (messageCollection.Count == 0)
+ return null;
+ return messageCollection;
+ }
+ }
+}
\ No newline at end of file
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches