private static SyntaxTrivia GetLastDocumentationCommentExteriorTrivia(SyntaxNode node) { return node .DescendantTrivia(descendIntoTrivia: true) .Where(trivia => trivia.IsKind(SyntaxKind.DocumentationCommentExteriorTrivia)) .LastOrDefault(); }
private static SyntaxNode RemoveImproperDocumentationTrivia(SyntaxNode node) { IEnumerable<SyntaxTrivia> commentTrivia = from t in node.DescendantTrivia() where t.Kind() == SyntaxKind.DocumentationCommentTrivia select t; SyntaxNode newRoot = node.ReplaceTrivia(commentTrivia, (t1, t2) => default(SyntaxTrivia)); return newRoot; }
private string GetUncomment(SyntaxNode root) { var comment = from c in root.DescendantTrivia() where c.Kind() == SyntaxKind.MultiLineCommentTrivia where c.ToString().StartsWith(uncommentPrefix) select GetUncommentBody(c); return comment.FirstOrDefault(); }
private static bool HasImplementation(SyntaxNode syntaxRoot) { bool hasImplementation = true; foreach (var trivia in syntaxRoot.DescendantTrivia()) { if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia)) { if (trivia.ToFullString().Contains("TODO: Implement analysis")) { hasImplementation = false; } } } return hasImplementation; }
private static bool LocateExcludedSpans(SyntaxNode root, out ImmutableArray<TextSpan> excludedSpans) { ImmutableArray<TextSpan>.Builder builder = ImmutableArray.CreateBuilder<TextSpan>(); // Locate disabled text foreach (var trivia in root.DescendantTrivia(descendIntoTrivia: true)) { if (trivia.IsKind(SyntaxKind.DisabledTextTrivia)) { builder.Add(trivia.Span); } else if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia)) { if (trivia.ToString().StartsWith("////")) { // Exclude comments starting with //// because they could contain commented code which contains // string or character literals, and we don't want to change the contents of those strings. builder.Add(trivia.Span); } } } // Locate string literals foreach (var token in root.DescendantTokens(descendIntoTrivia: true)) { switch (token.Kind()) { case SyntaxKind.XmlTextLiteralToken: if (token.Parent.IsKind(SyntaxKind.XmlCDataSection)) { builder.Add(token.Span); } break; case SyntaxKind.CharacterLiteralToken: case SyntaxKind.StringLiteralToken: case SyntaxKind.InterpolatedStringTextToken: builder.Add(token.Span); break; default: break; } } // Sort the results builder.Sort(); // Combine adjacent and overlapping spans ReduceTextSpans(builder); excludedSpans = builder.ToImmutable(); return true; }