Author: spouliot
Date: 2006-09-18 09:06:18 -0400 (Mon, 18 Sep 2006)
New Revision: 65576
Modified:
trunk/cecil/gendarme/rules/Gendarme.Rules.Portability/ChangeLog
trunk/cecil/gendarme/rules/Gendarme.Rules.Portability/NewLineLiteralRule.cs
Log:
2006-09-18 Sebastien Pouliot <[EMAIL PROTECTED]>
* NewLineLiteralRule.cs: Update rule to provide location (which
results in better reports).
Modified: trunk/cecil/gendarme/rules/Gendarme.Rules.Portability/ChangeLog
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Portability/ChangeLog
2006-09-18 13:05:51 UTC (rev 65575)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Portability/ChangeLog
2006-09-18 13:06:18 UTC (rev 65576)
@@ -1,3 +1,8 @@
+2006-09-18 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * NewLineLiteralRule.cs: Update rule to provide location (which
+ results in better reports).
+
2006-07-31 Sebastien Pouliot <[EMAIL PROTECTED]>
* Gendarme.Rules.Portability.mdp: New. Project file for MonoDevelop.
Modified:
trunk/cecil/gendarme/rules/Gendarme.Rules.Portability/NewLineLiteralRule.cs
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Portability/NewLineLiteralRule.cs
2006-09-18 13:05:51 UTC (rev 65575)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Portability/NewLineLiteralRule.cs
2006-09-18 13:06:18 UTC (rev 65576)
@@ -39,31 +39,14 @@
private static char[] InvalidChar = { '\r', '\n' };
- private ArrayList results;
-
- private ArrayList Results {
- get { return results; }
- }
-
- private void AddMessage (string s)
- {
- if (results == null)
- results = new ArrayList ();
-
- // make the invalid char visible on output
- s = s.Replace ("\n", "\\n");
- s = s.Replace ("\r", "\\r");
- // add the "problematic" string for easier validation
- results.Add (String.Format ("Found string: \"{0}\"",
s));
- }
-
public IList CheckMethod (AssemblyDefinition assembly,
ModuleDefinition module, TypeDefinition type, MethodDefinition method, Runner
runner)
{
// methods can be empty (e.g. p/invoke declarations)
if ((method.Body == null) || (method.Body.Instructions
== null))
return null;
- results = null;
+ string fullname = method.DeclaringType.FullName;
+ ArrayList results = new ArrayList ();
foreach (Instruction ins in method.Body.Instructions) {
switch (ins.OpCode.Name) {
case "ldstr":
@@ -72,15 +55,24 @@
if (s == null)
continue;
- if (s.IndexOfAny (InvalidChar) >= 0)
- AddMessage (s);
+ if (s.IndexOfAny (InvalidChar) >= 0) {
+ Location loc = new Location
(fullname, method.Name, ins.Offset);
+ // make the invalid char
visible on output
+ s = s.Replace ("\n", "\\n");
+ s = s.Replace ("\r", "\\r");
+ Message msg = new Message
(String.Format ("Found string: \"{0}\"", s),
+ loc,
MessageType.Warning);
+ results.Add (msg);
+ }
break;
default:
break;
}
}
- // no literal for new line has been found
- return Results;
+
+ if (results.Count == 0)
+ return null;
+ return results;
}
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches