109 lines
4.0 KiB
C#
109 lines
4.0 KiB
C#
using System.Threading;
|
|||
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||
|
|
using Microsoft.CodeAnalysis.Text;
|
||
|
|
|
||
|
|
namespace Microsoft.CodeAnalysis.CSharp;
|
||
|
|
|
||
|
|
internal class UnprocessedDocumentationCommentFinder : CSharpSyntaxWalker
|
||
|
|
{
|
||
|
|
private readonly DiagnosticBag _diagnostics;
|
||
|
|
|
||
|
|
private readonly CancellationToken _cancellationToken;
|
||
|
|
|
||
|
|
private readonly TextSpan? _filterSpanWithinTree;
|
||
|
|
|
||
|
|
private bool _isValidLocation;
|
||
|
|
|
||
|
|
private UnprocessedDocumentationCommentFinder(DiagnosticBag diagnostics, TextSpan? filterSpanWithinTree, CancellationToken cancellationToken)
|
||
|
|
: base((SyntaxWalkerDepth)2)
|
||
|
|
{
|
||
|
|
_diagnostics = diagnostics;
|
||
|
|
_filterSpanWithinTree = filterSpanWithinTree;
|
||
|
|
_cancellationToken = cancellationToken;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static void ReportUnprocessed(SyntaxTree tree, TextSpan? filterSpanWithinTree, DiagnosticBag diagnostics, CancellationToken cancellationToken)
|
||
|
|
{
|
||
|
|
if (tree.ReportDocumentationCommentDiagnostics())
|
||
|
|
{
|
||
|
|
new UnprocessedDocumentationCommentFinder(diagnostics, filterSpanWithinTree, cancellationToken).Visit(tree.GetRoot(cancellationToken));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private bool IsSyntacticallyFilteredOut(TextSpan fullSpan)
|
||
|
|
{
|
||
|
|
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
if (_filterSpanWithinTree.HasValue)
|
||
|
|
{
|
||
|
|
TextSpan value = _filterSpanWithinTree.Value;
|
||
|
|
return !((TextSpan)(ref value)).Contains(fullSpan);
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void DefaultVisit(SyntaxNode node)
|
||
|
|
{
|
||
|
|
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
CancellationToken cancellationToken = _cancellationToken;
|
||
|
|
cancellationToken.ThrowIfCancellationRequested();
|
||
|
|
if (IsSyntacticallyFilteredOut(node.FullSpan))
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (!node.HasStructuredTrivia)
|
||
|
|
{
|
||
|
|
TextSpan span = node.Span;
|
||
|
|
if (((TextSpan)(ref span)).Length > 0)
|
||
|
|
{
|
||
|
|
_isValidLocation = false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
if (node is BaseTypeDeclarationSyntax || node is DelegateDeclarationSyntax || node is EnumMemberDeclarationSyntax || node is BaseMethodDeclarationSyntax || node is BasePropertyDeclarationSyntax || node is BaseFieldDeclarationSyntax)
|
||
|
|
{
|
||
|
|
_isValidLocation = true;
|
||
|
|
}
|
||
|
|
base.DefaultVisit(node);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void VisitLeadingTrivia(SyntaxToken token)
|
||
|
|
{
|
||
|
|
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
CancellationToken cancellationToken = _cancellationToken;
|
||
|
|
cancellationToken.ThrowIfCancellationRequested();
|
||
|
|
if (!IsSyntacticallyFilteredOut(((SyntaxToken)(ref token)).FullSpan))
|
||
|
|
{
|
||
|
|
base.VisitLeadingTrivia(token);
|
||
|
|
_isValidLocation = false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void VisitTrivia(SyntaxTrivia trivia)
|
||
|
|
{
|
||
|
|
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_005e: Expected O, but got Unknown
|
||
|
|
CancellationToken cancellationToken = _cancellationToken;
|
||
|
|
cancellationToken.ThrowIfCancellationRequested();
|
||
|
|
if (!IsSyntacticallyFilteredOut(((SyntaxTrivia)(ref trivia)).FullSpan))
|
||
|
|
{
|
||
|
|
if (!_isValidLocation && SyntaxFacts.IsDocumentationCommentTrivia(trivia.Kind()))
|
||
|
|
{
|
||
|
|
int position = ((SyntaxTrivia)(ref trivia)).Position;
|
||
|
|
_diagnostics.Add(ErrorCode.WRN_UnprocessedXMLComment, (Location)new SourceLocation(((SyntaxTrivia)(ref trivia)).SyntaxTree, new TextSpan(position, 1)));
|
||
|
|
}
|
||
|
|
base.VisitTrivia(trivia);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|