Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Merge pull request #204 from olathunberg/feature/Nameof-handle-Delega…
Browse files Browse the repository at this point in the history
…teInvokeMethod

Fixed false positive XmlDoc, #201
  • Loading branch information
Rpinski committed Apr 12, 2016
2 parents 0e9fd12 + 4aa927a commit 8562cba
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
18 changes: 14 additions & 4 deletions RefactoringEssentials/CSharp/Diagnostics/Custom/XmlDocAnalyzer.cs
Expand Up @@ -71,7 +71,7 @@ public override void VisitDocumentationCommentTrivia(DocumentationCommentTriviaS
void AddXmlIssue(int offset, int length, string str)
{
context.ReportDiagnostic(Diagnostic.Create(
descriptor,
descriptor,
Location .Create(context.Tree, new TextSpan(offset, length)),
str
));
Expand All @@ -90,9 +90,9 @@ void CheckForInvalid(SyntaxNode node)
return;

context.ReportDiagnostic(Diagnostic.Create(
descriptor,
descriptor,
Location .Create(context.Tree, storedXmlComment[0].FullSpan),
storedXmlComment.Skip(1).Select(cmt => Location .Create(context.Tree, cmt.FullSpan)),
storedXmlComment.Skip(1).Select(cmt => Location .Create(context.Tree, cmt.FullSpan)),
GettextCatalog.GetString("Xml comment is not placed before a valid language element")
));
storedXmlComment.Clear();
Expand Down Expand Up @@ -156,7 +156,7 @@ void CheckXmlDocForErrors(SyntaxNode node, ISymbol member)

if (storedXmlComment.Count == 0)
return;

xml.Clear();
xml.Append(firstline);
var OffsetTable = new List<int>();
Expand Down Expand Up @@ -227,6 +227,16 @@ void CheckXmlDocForErrors(SyntaxNode node, ISymbol member)
AddXmlIssue(CalculateRealStartOffset(OffsetTable, name.ValueSegment.Start + 1), name.ValueSegment.Length - 2, string.Format(GettextCatalog.GetString("Parameter '{0}' not found"), name.Value));
break;
}
var named = member as INamedTypeSymbol;
if (named != null)
{
if (named.DelegateInvokeMethod == null)
break;
if (named.DelegateInvokeMethod.Parameters.Any(p => p.Name == name.Value))
break;
AddXmlIssue(CalculateRealStartOffset(OffsetTable, name.ValueSegment.Start + 1), name.ValueSegment.Length - 2, string.Format(GettextCatalog.GetString("Parameter '{0}' not found"), name.Value));
break;
}
AddXmlIssue(CalculateRealStartOffset(OffsetTable, name.ValueSegment.Start + 1), name.ValueSegment.Length - 2, string.Format(GettextCatalog.GetString("Parameter '{0}' not found"), name.Value));
break;
}
Expand Down
24 changes: 20 additions & 4 deletions Tests/CSharp/Diagnostics/XmlDocTests.cs
Expand Up @@ -109,7 +109,7 @@ class Foo {
}

/// <summary>
/// Bug 17729 - Incorrect XML-docs warning about 'value' paramref
/// Bug 17729 - Incorrect XML-docs warning about 'value' paramref
/// </summary>
[Test]
public void TestBug17729()
Expand Down Expand Up @@ -138,7 +138,7 @@ namespace Foo
public interface IGroupingProvider
{
IGroupingProvider Next { get; set; }
/// <summary>
/// Occurs when <see cref=""Next""/> changes.
/// </summary>
Expand Down Expand Up @@ -184,8 +184,24 @@ public void FooBar(int x, int y, int z)
}
");
}
}


[Test]
public void TestDelegateDeclaration()
{
Analyze<XmlDocAnalyzer>(@"
class Foo {
/// <summary>
/// </summary>
/// <param name=""$message$"">The data.</param>
public delegate void FooEventHandler(byte[] data);
/// <summary>
/// </summary>
/// <param name=""data"">The data.</param>
public delegate void BarEventHandler(byte[] data);
}
");
}
}
}

0 comments on commit 8562cba

Please sign in to comment.