public static bool IsCommentOrDirectiveTrivia(this SyntaxTrivia t) { if (t.IsSingleLineComment()) { return(true); } if (t.IsMultiLineComment()) { return(true); } if (t.IsDirective) { return(true); } return(false); }
private static string GetCommentBannerText(SyntaxTrivia comment) { Contract.ThrowIfFalse(comment.IsSingleLineComment() || comment.IsMultiLineComment()); if (comment.IsSingleLineComment()) { return CreateCommentBannerTextWithPrefix(comment.ToString(), "//"); } else if (comment.IsMultiLineComment()) { int lineBreakStart = comment.ToString().IndexOfAny(new char[] { '\r', '\n' }); var text = comment.ToString(); if (lineBreakStart >= 0) { text = text.Substring(0, lineBreakStart); } else { text = text.EndsWith(MultiLineCommentSuffix) ? text.Substring(0, text.Length - MultiLineCommentSuffix.Length) : text; } return CreateCommentBannerTextWithPrefix(text, "/*"); } else { return string.Empty; } }
protected override LineColumnRule GetLineColumnRuleBetween(SyntaxTrivia trivia1, LineColumnDelta existingWhitespaceBetween, bool implicitLineBreak, SyntaxTrivia trivia2) { if (IsStartOrEndOfFile(trivia1, trivia2)) { return(LineColumnRule.PreserveLinesWithAbsoluteIndentation(lines: 0, indentation: 0)); } // [trivia] [whitespace] [token] case if (trivia2.IsKind(SyntaxKind.None)) { var insertNewLine = this.FormattingRules.GetAdjustNewLinesOperation(this.Token1, this.Token2) != null; if (IsMultilineComment(trivia1)) { return(LineColumnRule.PreserveLinesWithGivenIndentation(lines: insertNewLine ? 1 : 0)); } if (insertNewLine) { return(LineColumnRule.PreserveLinesWithDefaultIndentation(lines: 0)); } if (existingWhitespaceBetween.Lines > 0 && existingWhitespaceBetween.Spaces != this.Spaces) { return(LineColumnRule.PreserveWithGivenSpaces(spaces: this.Spaces)); } return(LineColumnRule.Preserve); } // preprocessor case if (SyntaxFacts.IsPreprocessorDirective(trivia2.Kind())) { // Check for immovable preprocessor directives, which are bad directive trivia // without a preceding line break if (trivia2.IsKind(SyntaxKind.BadDirectiveTrivia) && existingWhitespaceBetween.Lines == 0 && !implicitLineBreak) { _succeeded = false; return(LineColumnRule.Preserve); } // if current line is the first line of the file, don't put extra line 1 var lines = (trivia1.IsKind(SyntaxKind.None) && this.Token1.IsKind(SyntaxKind.None)) ? 0 : 1; if (trivia2.IsKind(SyntaxKind.RegionDirectiveTrivia) || trivia2.IsKind(SyntaxKind.EndRegionDirectiveTrivia)) { return(LineColumnRule.PreserveLinesWithDefaultIndentation(lines)); } return(LineColumnRule.PreserveLinesWithAbsoluteIndentation(lines, indentation: 0)); } // comments case if (trivia2.IsRegularOrDocComment()) { // Start of new comments group. // // 1. Comment groups must contain the same kind of comments // 2. Every block comment is a group of its own if (!trivia1.IsKind(trivia2.Kind()) || trivia2.IsMultiLineComment() || trivia2.IsMultiLineDocComment() || existingWhitespaceBetween.Lines > 1) { if (this.FormattingRules.GetAdjustNewLinesOperation(this.Token1, this.Token2) != null) { return(LineColumnRule.PreserveLinesWithDefaultIndentation(lines: 0)); } return(LineColumnRule.PreserveLinesWithGivenIndentation(lines: 0)); } // comments after existing comment if (existingWhitespaceBetween.Lines == 0) { return(LineColumnRule.PreserveLinesWithGivenIndentation(lines: 0)); } return(LineColumnRule.PreserveLinesWithFollowingPrecedingIndentation); } if (trivia2.IsKind(SyntaxKind.SkippedTokensTrivia)) { // if there is any skipped tokens, it is not possible to format this trivia range. _succeeded = false; } return(LineColumnRule.Preserve); }
private static bool IsMultilineComment(SyntaxTrivia trivia1) => trivia1.IsMultiLineComment() || trivia1.IsMultiLineDocComment();
public static bool IsRegularOrDocComment(this SyntaxTrivia trivia) { return(trivia.IsSingleLineComment() || trivia.IsMultiLineComment() || trivia.IsDocComment()); }
protected override bool IsMultilineComment(SyntaxTrivia trivia) { return trivia.IsMultiLineComment() || trivia.IsMultiLineDocComment(); }
protected override bool IsMultilineComment(SyntaxTrivia trivia) { return(trivia.IsMultiLineComment() || trivia.IsMultiLineDocComment()); }
private static bool IsMultilineComment(SyntaxTrivia trivia1) { return(trivia1.IsMultiLineComment() || trivia1.IsMultiLineDocComment()); }
public static bool IsRegularComment(this SyntaxTrivia trivia) { return(trivia.IsSingleLineComment() || trivia.IsMultiLineComment() || trivia.IsShebangDirective()); }
private static bool IsMultilineComment(SyntaxTrivia trivia1) { return trivia1.IsMultiLineComment() || trivia1.IsMultiLineDocComment(); }
protected override bool IsMultilineComment(SyntaxTrivia trivia) => trivia.IsMultiLineComment() || trivia.IsMultiLineDocComment();