GetXMLDoc on fields

Hi All,

As far as i can tell the GetXMLDoc() method on IFieldDeclarations doesnt work in the new R#6.1 api. As anyone else experienced this? My code is (paraphrased):

internal class MyDaemonProcess : IDaemonStageProcess {

...

       private void CheckMembersHaveComments(IClassMemberDeclaration declaration,
                                                List<HighlightingInfo> highlightings)
        {
            XmlNode docNode = declaration.GetXMLDoc(false);

            if (docNode != null) return;

            highlightings.Add(
                 new HighlightingInfo(
                     declaration.GetNameDocumentRange(), new TestHighlighting(...)));

        }




        public void Execute(Action<DaemonStageResult> commiter)
        {

            if (!_daemonProcess.FullRehighlightingRequired)
            {
                return;
            }

            var highlightings = new List<HighlightingInfo>();

            IFile file = _daemonProcess.SourceFile.GetPsiFile(CSharpLanguage.Instance);
            if (file == null)
            {
                return;
            }

            file.ProcessChildren<IClassMemberDeclaration>(declaration => this.CheckMembersHaveComments(declaration, highlightings));

            commiter(new DaemonStageResult(highlightings));
        }

}



Fields are always highlighted regardless of whether they have documentation comments or not. Am i using GetXMLDoc incorrectly?

Cheers,
Chris
0
3 comments

I'm not sure that 'doesn't work' is the right term to use here. The fact that you're getting highlightings for all members means that GetXMLDoc() returns a non-null value. I would consider checking the FirstChild property of the result and seeing if that is null or not.

0

Hmm, I'm not quite sure what you mean. The first child of an IFieldDeclaration is always an Identifier afaik which never seems to own the comments?

GetXMLDoc comes back non-null but only when "declaration" is not an IFieldDeclaration (ie, it's an IMethodDeclaration, IPropertyDeclaration etc).



Using the Psi Viewer, I had a look at the contents of the document and I can see that the XML comment is always a part of an IMultipleFieldDeclaration which contains the IFieldDeclaration. I tried getting the parent IMultipleFieldDeclaration and running GetXMLDoc on that, but I'm still getting null (I checked that i actually got the IMultipleFieldDeclaration correctly so that's not the problem).

For now, i've ended up doing this:

XmlNode docNode = null;

IDocCommentBlockNode commentBlock;

IMultipleDeclarationMember multipleDeclarationMember = declaration as IMultipleDeclarationMember;

if (multipleDeclarationMember != null)

{

      // get the parent

      IMultipleDeclaration multipleDeclaration = multipleDeclarationMember.MultipleDeclaration;

      // Now ask for the actual comment block

      commentBlock = SharedImplUtil.GetDocCommentBlockNode(multipleDeclaration);

      if (commentBlock != null) docNode = commentBlock.GetXML(null);

}

else

{

      commentBlock = SharedImplUtil.GetDocCommentBlockNode(declaration);

      docNode = declaration.GetXMLDoc(false);

}


Which works ok but obviously will only get the comment on multiple declarations when it's defined in this file, not if it's defined on a parent class.
0

Ah - just re-read your comment again and I can see the confusion. I'm highlighting anything that doesnt have comments (ie where GetXMLDoc() returns null). I think you mised the "!="

I definitely get null from GetXMLDoc() on all fields but not from the IMultiFieldDefinition.

0

Please sign in to leave a comment.