Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Pouliot <sebastien@ximian.com>2010-05-16 19:13:32 +0400
committerSebastien Pouliot <sebastien@ximian.com>2010-05-16 19:13:32 +0400
commit61779dfd3fdf36d519d0b36981efecd414d38eff (patch)
treeee34318c2d8ec152e1944756ed24b88ccb9e5c13
parent327b4bd5c5f1bfe597ba41d39ebbbc45b0808e6d (diff)
2010-05-16 Sebastien Pouliot <sebastien@ximian.com>
* AssemblyRocks.cs: * CecilRocks.cs: * CommonRocks.cs: * CustomAttributeRocks.cs: * FieldRocks.cs: * InstructionRocks.cs: * MethodRocks.cs: * ModuleRocks.cs: * TypeRocks.cs: * VariableDefinitionRocks.cs: Apply fix for CheckParametersNullityInVisibleMethodsRule svn path=/trunk/mono-tools/; revision=157398
-rw-r--r--gendarme/framework/Gendarme.Framework.Rocks/AssemblyRocks.cs5
-rw-r--r--gendarme/framework/Gendarme.Framework.Rocks/CecilRocks.cs2
-rw-r--r--gendarme/framework/Gendarme.Framework.Rocks/ChangeLog14
-rw-r--r--gendarme/framework/Gendarme.Framework.Rocks/CommonRocks.cs10
-rw-r--r--gendarme/framework/Gendarme.Framework.Rocks/CustomAttributeRocks.cs4
-rw-r--r--gendarme/framework/Gendarme.Framework.Rocks/FieldRocks.cs10
-rw-r--r--gendarme/framework/Gendarme.Framework.Rocks/InstructionRocks.cs8
-rw-r--r--gendarme/framework/Gendarme.Framework.Rocks/MethodRocks.cs23
-rw-r--r--gendarme/framework/Gendarme.Framework.Rocks/ModuleRocks.cs5
-rw-r--r--gendarme/framework/Gendarme.Framework.Rocks/TypeRocks.cs15
-rw-r--r--gendarme/framework/Gendarme.Framework.Rocks/VariableDefinitionRocks.cs2
11 files changed, 93 insertions, 5 deletions
diff --git a/gendarme/framework/Gendarme.Framework.Rocks/AssemblyRocks.cs b/gendarme/framework/Gendarme.Framework.Rocks/AssemblyRocks.cs
index 2492b0ee..28244135 100644
--- a/gendarme/framework/Gendarme.Framework.Rocks/AssemblyRocks.cs
+++ b/gendarme/framework/Gendarme.Framework.Rocks/AssemblyRocks.cs
@@ -40,6 +40,11 @@ namespace Gendarme.Framework.Rocks {
/// <returns>True if any of the assembly's modules reference the assembly name, false otherwise.</returns>
public static bool References (this AssemblyDefinition self, string assemblyName)
{
+ if (assemblyName == null)
+ throw new ArgumentNullException ("assemblyName");
+ if (self == null)
+ return false;
+
foreach (ModuleDefinition module in self.Modules) {
foreach (AssemblyNameReference r in module.AssemblyReferences) {
if (r.Name == assemblyName)
diff --git a/gendarme/framework/Gendarme.Framework.Rocks/CecilRocks.cs b/gendarme/framework/Gendarme.Framework.Rocks/CecilRocks.cs
index ba5a743c..da41a7f9 100644
--- a/gendarme/framework/Gendarme.Framework.Rocks/CecilRocks.cs
+++ b/gendarme/framework/Gendarme.Framework.Rocks/CecilRocks.cs
@@ -80,7 +80,7 @@ namespace Gendarme.Framework.Rocks {
if (self == other)
return true;
if (other == null)
- return false;
+ return (self == null);
if (!self.MetadataToken.Equals (other.MetadataToken))
return false;
// metadata token is unique per assembly
diff --git a/gendarme/framework/Gendarme.Framework.Rocks/ChangeLog b/gendarme/framework/Gendarme.Framework.Rocks/ChangeLog
index c47e37c1..c865dcb6 100644
--- a/gendarme/framework/Gendarme.Framework.Rocks/ChangeLog
+++ b/gendarme/framework/Gendarme.Framework.Rocks/ChangeLog
@@ -1,3 +1,17 @@
+2010-05-16 Sebastien Pouliot <sebastien@ximian.com>
+
+ * AssemblyRocks.cs:
+ * CecilRocks.cs:
+ * CommonRocks.cs:
+ * CustomAttributeRocks.cs:
+ * FieldRocks.cs:
+ * InstructionRocks.cs:
+ * MethodRocks.cs:
+ * ModuleRocks.cs:
+ * TypeRocks.cs:
+ * VariableDefinitionRocks.cs:
+ Apply fix for CheckParametersNullityInVisibleMethodsRule
+
2010-05-10 Sebastien Pouliot <sebastien@ximian.com>
* MethodRocks.cs (IsMain): Apply AvoidRepetitiveCallsToPropertiesRule
diff --git a/gendarme/framework/Gendarme.Framework.Rocks/CommonRocks.cs b/gendarme/framework/Gendarme.Framework.Rocks/CommonRocks.cs
index fd979ab7..29dd8587 100644
--- a/gendarme/framework/Gendarme.Framework.Rocks/CommonRocks.cs
+++ b/gendarme/framework/Gendarme.Framework.Rocks/CommonRocks.cs
@@ -43,12 +43,22 @@ namespace Gendarme.Framework.Rocks {
/// <param name="item">The item to add.</param>
public static void AddIfNew<T> (this ICollection<T> self, T item)
{
+ if (self == null)
+ throw new ArgumentNullException ("self");
+ if (item == null)
+ throw new ArgumentNullException ("item");
+
if (!self.Contains (item))
self.Add (item);
}
public static void AddRangeIfNew<T> (this ICollection<T> self, IEnumerable<T> items)
{
+ if (self == null)
+ throw new ArgumentNullException ("self");
+ if (items == null)
+ throw new ArgumentNullException ("items");
+
foreach (T item in items) {
if (!self.Contains (item))
self.Add (item);
diff --git a/gendarme/framework/Gendarme.Framework.Rocks/CustomAttributeRocks.cs b/gendarme/framework/Gendarme.Framework.Rocks/CustomAttributeRocks.cs
index 008f05c8..b54a7649 100644
--- a/gendarme/framework/Gendarme.Framework.Rocks/CustomAttributeRocks.cs
+++ b/gendarme/framework/Gendarme.Framework.Rocks/CustomAttributeRocks.cs
@@ -59,6 +59,8 @@ namespace Gendarme.Framework.Rocks {
{
if (attributeTypeName == null)
throw new ArgumentNullException ("attributeTypeName");
+ if (self == null)
+ return false;
foreach (CustomAttribute ca in self) {
if (ca.Constructor.DeclaringType.FullName == attributeTypeName)
@@ -78,6 +80,8 @@ namespace Gendarme.Framework.Rocks {
{
if (attributeTypeNames == null)
throw new ArgumentNullException ("attributeTypeNames");
+ if (self == null)
+ return false;
foreach (CustomAttribute ca in self) {
string fullname = ca.Constructor.DeclaringType.FullName;
diff --git a/gendarme/framework/Gendarme.Framework.Rocks/FieldRocks.cs b/gendarme/framework/Gendarme.Framework.Rocks/FieldRocks.cs
index 20d6b51a..e345d8ab 100644
--- a/gendarme/framework/Gendarme.Framework.Rocks/FieldRocks.cs
+++ b/gendarme/framework/Gendarme.Framework.Rocks/FieldRocks.cs
@@ -5,7 +5,7 @@
// Sebastien Pouliot <sebastien@ximian.com>
// Andreas Noever <andreas.noever@gmail.com>
//
-// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2008, 2010 Novell, Inc (http://www.novell.com)
// (C) 2008 Andreas Noever
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -42,9 +42,13 @@ namespace Gendarme.Framework.Rocks {
/// <returns>True if the field was not added directly by the developer, False otherwise</returns>
public static bool IsGeneratedCode (this FieldReference self)
{
+ if (self == null)
+ return false;
+
FieldDefinition field = self.Resolve ();
if ((field == null) || !field.HasCustomAttributes)
return false;
+
return field.CustomAttributes.ContainsAnyType (CustomAttributeRocks.GeneratedCodeAttributes);
}
@@ -55,9 +59,13 @@ namespace Gendarme.Framework.Rocks {
/// <returns>True if the field can be used from outside of the assembly, false otherwise.</returns>
public static bool IsVisible (this FieldReference self)
{
+ if (self == null)
+ return false;
+
FieldDefinition field = self.Resolve ();
if ((field == null) || field.IsPrivate || field.IsAssembly)
return false;
+
return field.DeclaringType.Resolve ().IsVisible ();
}
}
diff --git a/gendarme/framework/Gendarme.Framework.Rocks/InstructionRocks.cs b/gendarme/framework/Gendarme.Framework.Rocks/InstructionRocks.cs
index e2e73a50..fac4bdaf 100644
--- a/gendarme/framework/Gendarme.Framework.Rocks/InstructionRocks.cs
+++ b/gendarme/framework/Gendarme.Framework.Rocks/InstructionRocks.cs
@@ -236,6 +236,11 @@ namespace Gendarme.Framework.Rocks {
/// <returns>The number of value removed (pop) from the stack for this instruction.</returns>
public static int GetPopCount (this Instruction self, IMethodSignature method)
{
+ if (self == null)
+ throw new ArgumentException ("self");
+ if (method == null)
+ throw new ArgumentException ("method");
+
switch (self.OpCode.StackBehaviourPop) {
case StackBehaviour.Pop0:
return 0;
@@ -298,6 +303,9 @@ namespace Gendarme.Framework.Rocks {
/// <returns>The number of value added (push) to the stack by this instruction.</returns>
public static int GetPushCount (this Instruction self)
{
+ if (self == null)
+ throw new ArgumentException ("self");
+
switch (self.OpCode.StackBehaviourPush) {
case StackBehaviour.Push0:
return 0;
diff --git a/gendarme/framework/Gendarme.Framework.Rocks/MethodRocks.cs b/gendarme/framework/Gendarme.Framework.Rocks/MethodRocks.cs
index b7046822..171a6464 100644
--- a/gendarme/framework/Gendarme.Framework.Rocks/MethodRocks.cs
+++ b/gendarme/framework/Gendarme.Framework.Rocks/MethodRocks.cs
@@ -59,7 +59,7 @@ namespace Gendarme.Framework.Rocks {
/// <returns>True if the method is defined as the entry point of it's assembly, False otherwise</returns>
public static bool IsEntryPoint (this MethodReference self)
{
- return (self == self.DeclaringType.Module.Assembly.EntryPoint);
+ return ((self != null) && (self == self.DeclaringType.Module.Assembly.EntryPoint));
}
/// <summary>
@@ -69,6 +69,9 @@ namespace Gendarme.Framework.Rocks {
/// <returns>True if the method is a finalizer, False otherwise.</returns>
public static bool IsFinalizer (this MethodReference self)
{
+ if (self == null)
+ return false;
+
return (self.HasThis && !self.HasParameters && (self.Name == "Finalize") &&
(self.ReturnType.ReturnType.FullName == "System.Void"));
}
@@ -81,6 +84,9 @@ namespace Gendarme.Framework.Rocks {
/// False otherwise (e.g. compiler or tool generated)</returns>
public static bool IsGeneratedCode (this MethodReference self)
{
+ if (self == null)
+ return false;
+
MethodDefinition method = self.Resolve ();
if ((method != null) && method.HasCustomAttributes) {
if (method.CustomAttributes.ContainsAnyType (CustomAttributeRocks.GeneratedCodeAttributes))
@@ -101,6 +107,9 @@ namespace Gendarme.Framework.Rocks {
/// <returns>True if the method is a valid Main, False otherwise.</returns>
public static bool IsMain (this MethodReference self)
{
+ if (self == null)
+ return false;
+
MethodDefinition method = self.Resolve ();
// Main must be static
if (!method.IsStatic)
@@ -138,6 +147,9 @@ namespace Gendarme.Framework.Rocks {
/// <returns>True if the method is an override to a virtual method, False otherwise</returns>
public static bool IsOverride (this MethodReference self)
{
+ if (self == null)
+ return false;
+
MethodDefinition method = self.Resolve ();
if ((method == null) || !method.IsVirtual)
return false;
@@ -180,6 +192,9 @@ namespace Gendarme.Framework.Rocks {
/// <returns>True if the method is a getter or a setter, False otherwise</returns>
public static bool IsProperty (this MethodReference self)
{
+ if (self == null)
+ return false;
+
MethodDefinition method = self.Resolve ();
if (method == null)
return false;
@@ -193,6 +208,9 @@ namespace Gendarme.Framework.Rocks {
/// <returns>True if the method can be used from outside of the assembly, false otherwise.</returns>
public static bool IsVisible (this MethodReference self)
{
+ if (self == null)
+ return false;
+
MethodDefinition method = self.Resolve ();
if ((method == null) || method.IsPrivate || method.IsAssembly)
return false;
@@ -208,6 +226,9 @@ namespace Gendarme.Framework.Rocks {
/// <returns>True if the method has the signature of an event callback.</returns>
public static bool IsEventCallback (this MethodReference self)
{
+ if (self == null)
+ return false;
+
MethodDefinition method = self.Resolve ();
if ((method == null) || !method.HasParameters)
return false;
diff --git a/gendarme/framework/Gendarme.Framework.Rocks/ModuleRocks.cs b/gendarme/framework/Gendarme.Framework.Rocks/ModuleRocks.cs
index fa0ab600..7b50ffa5 100644
--- a/gendarme/framework/Gendarme.Framework.Rocks/ModuleRocks.cs
+++ b/gendarme/framework/Gendarme.Framework.Rocks/ModuleRocks.cs
@@ -66,6 +66,8 @@ namespace Gendarme.Framework.Rocks {
/// <returns>True if the symbol file for this module is available, False otherwise</returns>
public static bool HasDebuggingInformation (this ModuleDefinition self)
{
+ if (self == null)
+ return false;
return (self as IAnnotationProvider).Annotations.Contains ("symbols");
}
@@ -77,6 +79,9 @@ namespace Gendarme.Framework.Rocks {
/// <param name="self"></param>
public static void LoadDebuggingSymbols (this ModuleDefinition self)
{
+ if (self == null)
+ return;
+
// don't create a new reader if the symbols are already loaded
IAnnotationProvider provider = (self as IAnnotationProvider);
if (provider.Annotations.Contains ("symbols"))
diff --git a/gendarme/framework/Gendarme.Framework.Rocks/TypeRocks.cs b/gendarme/framework/Gendarme.Framework.Rocks/TypeRocks.cs
index 9e9f7948..cba42830 100644
--- a/gendarme/framework/Gendarme.Framework.Rocks/TypeRocks.cs
+++ b/gendarme/framework/Gendarme.Framework.Rocks/TypeRocks.cs
@@ -114,6 +114,8 @@ namespace Gendarme.Framework.Rocks {
{
if (typeName == null)
throw new ArgumentNullException ("typeName");
+ if (self == null)
+ return false;
foreach (TypeReference type in self) {
if (type.FullName == typeName)
@@ -133,6 +135,8 @@ namespace Gendarme.Framework.Rocks {
{
if (typeNames == null)
throw new ArgumentNullException ("typeNames");
+ if (self == null)
+ return false;
foreach (TypeReference type in self) {
string fullname = type.FullName;
@@ -155,6 +159,11 @@ namespace Gendarme.Framework.Rocks {
/// </remarks>
public static MethodDefinition GetMethod (this TypeReference self, MethodSignature signature)
{
+ if (signature == null)
+ throw new ArgumentNullException ("signature");
+ if (self == null)
+ return null;
+
bool ctors, methods;
// method name is optional so we must look in everything
if (String.IsNullOrEmpty (signature.Name)) {
@@ -299,7 +308,7 @@ namespace Gendarme.Framework.Rocks {
/// <returns>True if at least one method matches the signature. Otherwise false.</returns>
public static bool HasMethod (this TypeReference self, MethodSignature signature)
{
- return (self.GetMethod (signature) != null);
+ return ((self != null) && self.GetMethod (signature) != null);
}
/// <summary>
@@ -315,6 +324,8 @@ namespace Gendarme.Framework.Rocks {
{
if (interfaceName == null)
throw new ArgumentNullException ("interfaceName");
+ if (self == null)
+ return false;
TypeDefinition type = self.Resolve ();
if (type == null)
@@ -359,6 +370,8 @@ namespace Gendarme.Framework.Rocks {
{
if (className == null)
throw new ArgumentNullException ("className");
+ if (self == null)
+ return false;
TypeReference current = self.Resolve ();
while ((current != null) && (current.FullName != "System.Object")) {
diff --git a/gendarme/framework/Gendarme.Framework.Rocks/VariableDefinitionRocks.cs b/gendarme/framework/Gendarme.Framework.Rocks/VariableDefinitionRocks.cs
index d4841da3..bb26d461 100644
--- a/gendarme/framework/Gendarme.Framework.Rocks/VariableDefinitionRocks.cs
+++ b/gendarme/framework/Gendarme.Framework.Rocks/VariableDefinitionRocks.cs
@@ -39,7 +39,7 @@ namespace Gendarme.Framework.Rocks {
/// <returns>True if the field name was generated by the compiler, False otherwise</returns>
public static bool IsGeneratedName (this VariableReference self)
{
- return self.Name.StartsWith ("V_");
+ return ((self != null) && self.Name.StartsWith ("V_"));
}
}
}