106 lines
4.0 KiB
C#
106 lines
4.0 KiB
C#
using System.Collections.Immutable;
|
|
using System.Threading;
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
using Microsoft.CodeAnalysis.PooledObjects;
|
|
using Microsoft.CodeAnalysis.Text;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp;
|
|
|
|
internal static class SourceDocumentationCommentUtils
|
|
{
|
|
internal static string GetAndCacheDocumentationComment(Symbol symbol, bool expandIncludes, ref string lazyXmlText)
|
|
{
|
|
if (lazyXmlText == null)
|
|
{
|
|
string documentationCommentXml = DocumentationCommentCompiler.GetDocumentationCommentXml(symbol, expandIncludes, default(CancellationToken));
|
|
Interlocked.CompareExchange(ref lazyXmlText, documentationCommentXml, null);
|
|
}
|
|
return lazyXmlText;
|
|
}
|
|
|
|
internal static ImmutableArray<DocumentationCommentTriviaSyntax> GetDocumentationCommentTriviaFromSyntaxNode(CSharpSyntaxNode syntaxNode, DiagnosticBag diagnostics)
|
|
{
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0011: Invalid comparison between Unknown and I4
|
|
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00d4: Expected O, but got Unknown
|
|
if ((int)syntaxNode.SyntaxTree.Options.DocumentationMode < 1)
|
|
{
|
|
return ImmutableArray<DocumentationCommentTriviaSyntax>.Empty;
|
|
}
|
|
if (syntaxNode.Kind() == SyntaxKind.VariableDeclarator)
|
|
{
|
|
CSharpSyntaxNode cSharpSyntaxNode;
|
|
for (cSharpSyntaxNode = syntaxNode; cSharpSyntaxNode != null; cSharpSyntaxNode = cSharpSyntaxNode.Parent)
|
|
{
|
|
SyntaxKind syntaxKind = cSharpSyntaxNode.Kind();
|
|
if (syntaxKind == SyntaxKind.FieldDeclaration || syntaxKind == SyntaxKind.EventFieldDeclaration)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
if (cSharpSyntaxNode != null)
|
|
{
|
|
syntaxNode = cSharpSyntaxNode;
|
|
}
|
|
}
|
|
ArrayBuilder<DocumentationCommentTriviaSyntax> val = null;
|
|
bool flag = false;
|
|
SyntaxTriviaList leadingTrivia = syntaxNode.GetLeadingTrivia();
|
|
Reversed val2 = ((SyntaxTriviaList)(ref leadingTrivia)).Reverse();
|
|
Enumerator enumerator = ((Reversed)(ref val2)).GetEnumerator();
|
|
while (((Enumerator)(ref enumerator)).MoveNext())
|
|
{
|
|
SyntaxTrivia current = ((Enumerator)(ref enumerator)).Current;
|
|
switch (current.Kind())
|
|
{
|
|
case SyntaxKind.SingleLineDocumentationCommentTrivia:
|
|
case SyntaxKind.MultiLineDocumentationCommentTrivia:
|
|
if (flag)
|
|
{
|
|
SyntaxTree syntaxTree = ((SyntaxTrivia)(ref current)).SyntaxTree;
|
|
if (syntaxTree.ReportDocumentationCommentDiagnostics())
|
|
{
|
|
int position = ((SyntaxTrivia)(ref current)).Position;
|
|
diagnostics.Add(ErrorCode.WRN_UnprocessedXMLComment, (Location)new SourceLocation(syntaxTree, new TextSpan(position, 1)));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (val == null)
|
|
{
|
|
val = ArrayBuilder<DocumentationCommentTriviaSyntax>.GetInstance();
|
|
}
|
|
val.Add((DocumentationCommentTriviaSyntax)(object)((SyntaxTrivia)(ref current)).GetStructure());
|
|
}
|
|
break;
|
|
default:
|
|
if (val != null)
|
|
{
|
|
flag = true;
|
|
}
|
|
break;
|
|
case SyntaxKind.EndOfLineTrivia:
|
|
case SyntaxKind.WhitespaceTrivia:
|
|
break;
|
|
}
|
|
}
|
|
if (val == null)
|
|
{
|
|
return ImmutableArray<DocumentationCommentTriviaSyntax>.Empty;
|
|
}
|
|
val.ReverseContents();
|
|
return val.ToImmutableAndFree();
|
|
}
|
|
}
|