Author: spouliot
Date: 2008-02-13 16:48:53 -0500 (Wed, 13 Feb 2008)
New Revision: 95601
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/MinimalRunner.cs
trunk/mono-tools/gendarme/framework/Gendarme.Framework/Runner.cs
Log:
2008-02-13 Sebastien Pouliot <[EMAIL PROTECTED]>
* Defect.cs: Merge Defect and Defect<T> into a non-generic
class.
* MinimalRunner.cs: Move Reset method to Runner.
* Runner.cs: Adapt for Defect changes and add Reset method.
Modified: trunk/mono-tools/gendarme/framework/Gendarme.Framework/ChangeLog
===================================================================
--- trunk/mono-tools/gendarme/framework/Gendarme.Framework/ChangeLog
2008-02-13 21:39:25 UTC (rev 95600)
+++ trunk/mono-tools/gendarme/framework/Gendarme.Framework/ChangeLog
2008-02-13 21:48:53 UTC (rev 95601)
@@ -1,3 +1,9 @@
+2008-02-13 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * Defect.cs: Merge Defect and Defect<T> into a non-generic class.
+ * MinimalRunner.cs: Move Reset method to Runner.
+ * Runner.cs: Adapt for Defect changes and add Reset method.
+
2008-02-12 Sebastien Pouliot <[EMAIL PROTECTED]>
* Defect.cs: Fix exception argument.
Modified: trunk/mono-tools/gendarme/framework/Gendarme.Framework/Defect.cs
===================================================================
--- trunk/mono-tools/gendarme/framework/Gendarme.Framework/Defect.cs
2008-02-13 21:39:25 UTC (rev 95600)
+++ trunk/mono-tools/gendarme/framework/Gendarme.Framework/Defect.cs
2008-02-13 21:48:53 UTC (rev 95601)
@@ -25,61 +25,71 @@
// THE SOFTWARE.
using System;
-using System.Text;
+using System.Globalization;
using Mono.Cecil;
using Mono.Cecil.Cil;
namespace Gendarme.Framework {
- // implementation of Defect classes must be immutable
- abstract public class Defect {
+ // to be moved elsewhere
+ public static class IMetadataTokenProviderRock {
- IRule rule;
- string text;
-
- protected Defect (IRule rule, string text)
+ public static AssemblyDefinition GetAssembly (this
IMetadataTokenProvider self)
{
- this.rule = rule;
- this.text = text;
- }
+ AssemblyDefinition ad = (self as AssemblyDefinition);
+ if (ad != null)
+ return ad;
- public IRule Rule {
- get { return rule; }
- }
+ TypeDefinition td = (self as TypeDefinition);
+ if (td != null)
+ return td.Module.Assembly;
- public string Text {
- get { return text; }
- }
+ MethodDefinition md = (self as MethodDefinition);
+ if (md != null)
+ return md.DeclaringType.Module.Assembly;
- abstract public AssemblyDefinition Assembly { get; }
+ FieldDefinition fd = (self as FieldDefinition);
+ if (fd != null)
+ return fd.DeclaringType.Module.Assembly;
- abstract public Confidence Confidence { get; }
+ ParameterDefinition pd = (self as ParameterDefinition);
+ if (pd != null)
+ return pd.Method.DeclaringType.Module.Assembly;
- abstract public string Location { get; }
-
- abstract public Severity Severity { get; }
-
- abstract public object Target { get; }
+ return null;
+ }
}
- public class Defect<T> : Defect {
+ public class Defect {
- private T location;
+ private IRule rule;
+ private IMetadataTokenProvider target;
+ private IMetadataTokenProvider location;
private Severity severity;
private Confidence confidence;
private Instruction ins;
+ private string text;
- public Defect (IRule rule, T location, Severity severity,
Confidence confidence, string text)
- : base (rule, text)
+ public Defect (IRule rule, IMetadataTokenProvider target,
IMetadataTokenProvider location, Severity severity, Confidence confidence,
string text)
{
+ if (rule == null)
+ throw new ArgumentNullException ("rule");
+ if (target == null)
+ throw new ArgumentNullException ("target");
+ if (location == null)
+ throw new ArgumentNullException ("location");
+
+ this.rule = rule;
+ this.target = target;
this.location = location;
this.confidence = confidence;
this.severity = severity;
+ this.text = text;
}
- public Defect (IRule rule, T location, Instruction ins,
Severity severity, Confidence confidence, string text)
- : this (rule, location, severity, confidence, text)
+ public Defect (IRule rule, IMetadataTokenProvider target,
IMetadataTokenProvider location, Instruction ins, Severity severity, Confidence
confidence, string text)
+ : this (rule, target, location, severity, confidence,
text)
{
// this ctor is usable only for MethodDefinition
if (!(location is MethodDefinition))
@@ -87,71 +97,52 @@
this.ins = ins;
}
- public override AssemblyDefinition Assembly {
- get {
- AssemblyDefinition ad = (location as
AssemblyDefinition);
- if (ad != null)
- return ad;
+ public AssemblyDefinition Assembly {
+ get { return target.GetAssembly (); }
+ }
- /*ModuleDefinition md = (location as
ModuleDefinition);
- if (md != null)
- return md.Assembly;*/
+ public Confidence Confidence {
+ get { return confidence; }
+ }
- TypeDefinition td = (location as
TypeDefinition);
- if (td != null)
- return td.Module.Assembly;
+ public IMetadataTokenProvider Location {
+ get { return location; }
+ }
- MethodDefinition md = (location as
MethodDefinition);
- if (md != null)
- return md.DeclaringType.Module.Assembly;
-
- FieldDefinition fd = (location as
FieldDefinition);
- if (fd != null)
- return fd.DeclaringType.Module.Assembly;
-
- ParameterDefinition pd = (location as
ParameterDefinition);
- if (pd != null)
- return
pd.Method.DeclaringType.Module.Assembly;
-
- return null;
- }
+ public IRule Rule {
+ get { return rule; }
}
- public override Confidence Confidence {
- get { return confidence; }
+ public Severity Severity {
+ get { return severity; }
}
- public override string Location {
+ public string Source {
get {
if (ins == null)
- return Assembly.Name.FullName;
+ return String.Empty;
- MethodDefinition method = (location as
MethodDefinition);
- StringBuilder sb = new StringBuilder ();
-
- // try to find to most
+ // try to find the closed sequence point for
this instruction
Instruction search = ins;
while (search != null) {
if (search.SequencePoint != null) {
- sb.AppendFormat
("{0}({1},{2})", search.SequencePoint.Document.Url,
-
search.SequencePoint.StartLine, search.SequencePoint.StartColumn);
- return sb.ToString ();
+ return String.Format
(CultureInfo.InvariantCulture, "{0}({1},{2})",
+
search.SequencePoint.Document.Url, search.SequencePoint.StartLine,
+
search.SequencePoint.StartColumn);
}
search = search.Previous;
}
- sb.Append (method.ToString ());
- sb.AppendFormat (":(0x{0:x4})", ins.Offset);
- return sb.ToString ();
+ return String.Format
(CultureInfo.InvariantCulture, "IL offset: (0x{0:x4})", ins.Offset);
}
}
- public override Severity Severity {
- get { return severity; }
+ public IMetadataTokenProvider Target {
+ get { return target; }
}
- public override object Target {
- get { return location; }
+ public string Text {
+ get { return text; }
}
}
}
Modified:
trunk/mono-tools/gendarme/framework/Gendarme.Framework/MinimalRunner.cs
===================================================================
--- trunk/mono-tools/gendarme/framework/Gendarme.Framework/MinimalRunner.cs
2008-02-13 21:39:25 UTC (rev 95600)
+++ trunk/mono-tools/gendarme/framework/Gendarme.Framework/MinimalRunner.cs
2008-02-13 21:48:53 UTC (rev 95601)
@@ -27,11 +27,5 @@
namespace Gendarme.Framework {
public class MinimalRunner : Runner {
-
- public void Reset ()
- {
- defectCountBeforeCheck = 0;
- Defects.Clear ();
- }
}
}
Modified: trunk/mono-tools/gendarme/framework/Gendarme.Framework/Runner.cs
===================================================================
--- trunk/mono-tools/gendarme/framework/Gendarme.Framework/Runner.cs
2008-02-13 21:39:25 UTC (rev 95600)
+++ trunk/mono-tools/gendarme/framework/Gendarme.Framework/Runner.cs
2008-02-13 21:48:53 UTC (rev 95601)
@@ -48,8 +48,9 @@
private IEnumerable<ITypeRule> type_rules;
private IEnumerable<IMethodRule> method_rules;
private IRule currentRule;
+ private IMetadataTokenProvider currentTarget;
- protected int defectCountBeforeCheck;
+ private int defectCountBeforeCheck;
public event EventHandler<RunnerEventArgs> AnalyzeAssembly;
// ??? ProcessAssembly ???
public event EventHandler<RunnerEventArgs> AnalyzeModule;
@@ -149,34 +150,39 @@
public void Report (AssemblyDefinition assembly, Severity
severity, Confidence confidence, string message)
{
- defect_list.Add (new Defect<AssemblyDefinition>
(currentRule, assembly, severity, confidence, message));
+ defect_list.Add (new Defect (currentRule,
currentTarget, assembly, severity, confidence, message));
}
public void Report (TypeDefinition type, Severity severity,
Confidence confidence, string message)
{
- defect_list.Add (new Defect<TypeDefinition>
(currentRule, type, severity, confidence, message));
+ defect_list.Add (new Defect (currentRule,
currentTarget, type, severity, confidence, message));
}
public void Report (FieldDefinition field, Severity severity,
Confidence confidence, string message)
{
- defect_list.Add (new Defect<FieldDefinition>
(currentRule, field, severity, confidence, message));
+ defect_list.Add (new Defect (currentRule,
currentTarget, field, severity, confidence, message));
}
public void Report (MethodDefinition method, Severity severity,
Confidence confidence, string message)
{
- defect_list.Add (new Defect<MethodDefinition>
(currentRule, method, severity, confidence, message));
+ defect_list.Add (new Defect (currentRule,
currentTarget, method, severity, confidence, message));
}
public void Report (MethodDefinition method, Instruction ins,
Severity severity, Confidence confidence, string message)
{
- defect_list.Add (new Defect<MethodDefinition>
(currentRule, method, ins, severity, confidence, message));
+ defect_list.Add (new Defect (currentRule,
currentTarget, method, ins, severity, confidence, message));
}
public void Report (ParameterDefinition parameter, Severity
severity, Confidence confidence, string message)
{
- defect_list.Add (new Defect<ParameterDefinition>
(currentRule, parameter, severity, confidence, message));
+ defect_list.Add (new Defect (currentRule,
currentTarget, parameter, severity, confidence, message));
}
+ public void Reset ()
+ {
+ defectCountBeforeCheck = 0;
+ Defects.Clear ();
+ }
private void OnEvent (EventHandler<RunnerEventArgs> handler,
RunnerEventArgs e)
{
@@ -267,18 +273,22 @@
RunnerEventArgs runner_args = new RunnerEventArgs
(this);
foreach (AssemblyDefinition assembly in assemblies) {
+ currentTarget = (IMetadataTokenProvider)
assembly;
runner_args.CurrentAssembly = assembly;
OnAssembly (runner_args);
foreach (ModuleDefinition module in
assembly.Modules) {
+ currentTarget =
(IMetadataTokenProvider) module;
runner_args.CurrentModule = module;
OnModule (runner_args);
foreach (TypeDefinition type in
module.Types) {
+ currentTarget =
(IMetadataTokenProvider) type;
runner_args.CurrentType = type;
OnType (runner_args);
foreach (MethodDefinition
method in GetMethods (type)) {
+ currentTarget =
(IMetadataTokenProvider) method;
runner_args.CurrentMethod = method;
OnMethod (runner_args);
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches