Check XML documentation parameters on all parameters-like member kinds
authorMarek Safar <marek.safar@gmail.com>
Wed, 30 Mar 2011 09:05:37 +0000 (10:05 +0100)
committerMarek Safar <marek.safar@gmail.com>
Wed, 30 Mar 2011 09:40:17 +0000 (10:40 +0100)
mcs/errors/cs1572-2.cs [new file with mode: 0644]
mcs/errors/cs1572-3.cs [new file with mode: 0644]
mcs/mcs/decl.cs
mcs/mcs/doc.cs
mcs/mcs/method.cs

diff --git a/mcs/errors/cs1572-2.cs b/mcs/errors/cs1572-2.cs
new file mode 100644 (file)
index 0000000..2e069d3
--- /dev/null
@@ -0,0 +1,14 @@
+// CS1572: XML comment on `Testing.Test.this[int]' has a param tag for `mismatch', but there is no parameter by that name
+// Line: 10
+// Compiler options: -doc:dummy.xml -warn:2 -warnaserror
+
+namespace Testing
+{
+       class Test
+       {
+               /// <param name='mismatch'>mismatch</param>
+               public int this[int i] {
+                       set {}
+               }
+       }
+}
diff --git a/mcs/errors/cs1572-3.cs b/mcs/errors/cs1572-3.cs
new file mode 100644 (file)
index 0000000..ad4b230
--- /dev/null
@@ -0,0 +1,12 @@
+// CS1572: XML comment on `Testing.Test.D' has a param tag for `mismatch', but there is no parameter by that name
+// Line: 10
+// Compiler options: -doc:dummy.xml -warn:2 -warnaserror
+
+namespace Testing
+{
+       class Test
+       {
+               /// <param name='mismatch'>mismatch</param>
+               public delegate void D (int i);
+       }
+}
index 9992f68f7288207bef59d3bff375d199b15e8c32..2edc8578677a62e3cf76b55778daca7ea202cc3a 100644 (file)
@@ -807,14 +807,6 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               //
-               // Raised (and passed an XmlElement that contains the comment)
-               // when GenerateDocComment is writing documentation expectedly.
-               //
-               internal virtual void OnGenerateDocComment (XmlElement intermediateNode)
-               {
-               }
-
                //
                // Returns a string that represents the signature for this 
                // member which should be used in XML documentation.
index 415bda382df5e3950c564d17db11b3d89cd0b903..fd4e394b75b1286fda8ea715ff91bc7e5053a20c 100644 (file)
@@ -35,7 +35,7 @@ namespace Mono.CSharp
                //
                // The output for XML documentation.
                //
-               public XmlWriter XmlCommentOutput;
+               XmlWriter XmlCommentOutput;
 
                static readonly string line_head = Environment.NewLine + "            ";
 
@@ -122,7 +122,10 @@ namespace Mono.CSharp
 
                        XmlElement el = n as XmlElement;
                        if (el != null) {
-                               mc.OnGenerateDocComment (el);
+                               var pm = mc as IParametersMember;
+                               if (pm != null) {
+                                       CheckParametersComments (mc, pm, el);
+                               }
 
                                // FIXME: it could be done with XmlReader
                                XmlNodeList nl = n.SelectNodes (".//include");
@@ -455,15 +458,6 @@ namespace Mono.CSharp
                        xref.SetAttribute ("cref", cref);
                }
 
-               void Report419 (MemberCore mc, string member_name, MemberSpec [] mis)
-               {
-                       Report.Warning (419, 3, mc.Location, 
-                               "Ambiguous reference in cref attribute `{0}'. Assuming `{1}' but other overloads including `{2}' have also matched",
-                               member_name,
-                               TypeManager.GetFullNameSignature (mis [0]),
-                               TypeManager.GetFullNameSignature (mis [1]));
-               }
-
                //
                // Get a prefix from member type for XML documentation (used
                // to formalize cref target name).
@@ -491,27 +485,42 @@ namespace Mono.CSharp
                // FIXME: with a few effort, it could be done with XmlReader,
                // that means removal of DOM use.
                //
-               internal static void OnMethodGenerateDocComment (
-                       MethodCore mc, XmlElement el, Report Report)
+               void CheckParametersComments (MemberCore member, IParametersMember paramMember, XmlElement el)
                {
-                       var paramTags = new Dictionary<string, string> ();
+                       HashSet<string> found_tags = null;
                        foreach (XmlElement pelem in el.SelectNodes ("param")) {
                                string xname = pelem.GetAttribute ("name");
                                if (xname.Length == 0)
                                        continue; // really? but MS looks doing so
-                               if (xname != "" && mc.ParameterInfo.GetParameterIndexByName (xname) < 0)
-                                       Report.Warning (1572, 2, mc.Location, "XML comment on `{0}' has a param tag for `{1}', but there is no parameter by that name",
-                                               mc.GetSignatureForError (), xname);
-                               else if (paramTags.ContainsKey (xname))
-                                       Report.Warning (1571, 2, mc.Location, "XML comment on `{0}' has a duplicate param tag for `{1}'",
-                                               mc.GetSignatureForError (), xname);
-                               paramTags [xname] = xname;
+
+                               if (found_tags == null) {
+                                       found_tags = new HashSet<string> ();
+                               }
+
+                               if (xname != "" && paramMember.Parameters.GetParameterIndexByName (xname) < 0) {
+                                       Report.Warning (1572, 2, member.Location,
+                                               "XML comment on `{0}' has a param tag for `{1}', but there is no parameter by that name",
+                                               member.GetSignatureForError (), xname);
+                                       continue;
+                               }
+
+                               if (found_tags.Contains (xname)) {
+                                       Report.Warning (1571, 2, member.Location,
+                                               "XML comment on `{0}' has a duplicate param tag for `{1}'",
+                                               member.GetSignatureForError (), xname);
+                                       continue;
+                               }
+
+                               found_tags.Add (xname);
                        }
-                       IParameterData [] plist = mc.ParameterInfo.FixedParameters;
-                       foreach (Parameter p in plist) {
-                               if (paramTags.Count > 0 && !paramTags.ContainsKey (p.Name))
-                                       Report.Warning (1573, 4, mc.Location, "Parameter `{0}' has no matching param tag in the XML comment for `{1}'",
-                                               p.Name, mc.GetSignatureForError ());
+
+                       if (found_tags != null) {
+                               foreach (Parameter p in paramMember.Parameters.FixedParameters) {
+                                       if (!found_tags.Contains (p.Name) && !(p is ArglistParameter))
+                                               Report.Warning (1573, 4, member.Location,
+                                                       "Parameter `{0}' has no matching param tag in the XML comment for `{1}'",
+                                                       p.Name, member.GetSignatureForError ());
+                               }
                        }
                }
 
index 83a11cc370d6998027d61df7ea8ddac4fe88de30..ee6b69b8d26126872b1d06841ff1280823860752 100644 (file)
@@ -126,18 +126,6 @@ namespace Mono.CSharp {
                        return base.CheckBase ();
                }
 
-               //
-               // Raised (and passed an XmlElement that contains the comment)
-               // when GenerateDocComment is writing documentation expectedly.
-               //
-               // FIXME: with a few effort, it could be done with XmlReader,
-               // that means removal of DOM use.
-               //
-               internal override void OnGenerateDocComment (XmlElement el)
-               {
-                       DocumentationBuilder.OnMethodGenerateDocComment (this, el, Report);
-               }
-
                //
                //   Represents header string for documentation comment.
                //