本文整理汇总了C#中SyntaxTrivia.ToFullString方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxTrivia.ToFullString方法的具体用法?C# SyntaxTrivia.ToFullString怎么用?C# SyntaxTrivia.ToFullString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxTrivia
的用法示例。
在下文中一共展示了SyntaxTrivia.ToFullString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NeedsSpaceAdding
private bool NeedsSpaceAdding(SyntaxTrivia trivia)
{
if (trivia.Kind != SyntaxKind.SingleLineCommentTrivia)
{
return false;
}
var text = trivia.ToFullString();
if (!text.StartsWith("//"))
{
return false;
}
if (text.StartsWith("///") || text.StartsWith("////"))
{
return false;
}
if (text.Length >= 3 && text[2] != ' ')
{
return true;
}
if (text.Length >= 4 && text[2] == ' ' && text[3] == ' ')
{
return true;
}
return false;
}
示例2: AppendTodoComments
protected override void AppendTodoComments(ImmutableArray<TodoCommentDescriptor> commentDescriptors, SyntacticDocument document, SyntaxTrivia trivia, List<TodoComment> todoList)
{
if (PreprocessorHasComment(trivia))
{
var message = trivia.ToFullString();
var index = message.IndexOf(SingleLineCommentPrefix);
var start = trivia.FullSpan.Start + index;
AppendTodoCommentInfoFromSingleLine(commentDescriptors, document, message.Substring(index), start, todoList);
return;
}
if (IsSingleLineComment(trivia))
{
ProcessMultilineComment(commentDescriptors, document, trivia, postfixLength: 0, todoList: todoList);
return;
}
if (IsMultilineComment(trivia))
{
ProcessMultilineComment(commentDescriptors, document, trivia, s_multilineCommentPostfixLength, todoList);
return;
}
throw ExceptionUtilities.Unreachable;
}
示例3: VisitTrivia
public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
{
if (trivia.Kind() == SyntaxKind.DocumentationCommentExteriorTrivia)
{
if (IsBeginningOrEndOfDocumentComment(trivia))
{
return base.VisitTrivia(trivia);
}
else
{
var triviaText = trivia.ToFullString();
var newTriviaText = triviaText.AdjustIndentForXmlDocExteriorTrivia(
_forceIndentation,
_indentation,
_indentationDelta,
_optionSet.GetOption(FormattingOptions.UseTabs, LanguageNames.CSharp),
_optionSet.GetOption(FormattingOptions.TabSize, LanguageNames.CSharp));
if (triviaText == newTriviaText)
{
return base.VisitTrivia(trivia);
}
var parsedNewTrivia = SyntaxFactory.DocumentationCommentExterior(newTriviaText);
return parsedNewTrivia;
}
}
return base.VisitTrivia(trivia);
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:32,代码来源:CSharpTriviaFormatter.DocumentationCommentExteriorCommentRewriter.cs
示例4: HandleWhitespaceTrivia
private void HandleWhitespaceTrivia(SyntaxTreeAnalysisContext context, SyntaxTrivia trivia)
{
if (trivia.ToFullString().IndexOf('\t') < 0)
{
return;
}
// Tabs must not be used.
context.ReportDiagnostic(Diagnostic.Create(Descriptor, trivia.GetLocation()));
}
示例5: EvaluateImpl
protected override EvaluationResult EvaluateImpl(SyntaxTrivia node)
{
var trimmed = StrippedRegex.Replace(node.ToFullString(), string.Empty).Trim();
var commentWords = RemoveLineDashes(RemoveXml(trimmed))
.Split(' ')
.Select(RemoveXml)
.Select(s => s.TrimEnd('.', ',', '_'))
.Where(IsNotNumber)
.AsArray();
var errorCount = commentWords.Aggregate(0, (i, s) => i + (_spellChecker.Spell(s) ? 0 : 1));
if (errorCount >= 0.50 * commentWords.Length)
{
return new EvaluationResult
{
Snippet = node.ToFullString()
};
}
return null;
}
示例6: GetTransformedDocumentAsync
private static Task<Document> GetTransformedDocumentAsync(Document document, SyntaxNode root, SyntaxTrivia trivia)
{
string text = trivia.ToFullString();
if (!text.StartsWith("//"))
{
return Task.FromResult(document);
}
string correctedText = "// " + text.Substring(2).TrimStart(' ');
SyntaxTrivia corrected = SyntaxFactory.Comment(correctedText).WithoutFormatting();
Document updatedDocument = document.WithSyntaxRoot(root.ReplaceTrivia(trivia, corrected));
return Task.FromResult(updatedDocument);
}
示例7: IsMultiLine
public static bool IsMultiLine(SyntaxTrivia trivia)
{
switch (trivia.Kind())
{
case SyntaxKind.EndOfLineTrivia:
return true;
case SyntaxKind.WhitespaceTrivia:
case SyntaxKind.SingleLineCommentTrivia:
return false;
// todo could possibly optimize for structured trivia
default:
return trivia.ToFullString().IndexOf('\n') >= 0;
}
}
示例8: VisitTrivia
public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
{
if (NeedsSpaceAdding(trivia))
{
var text = trivia.ToFullString();
text = text.Substring(0, 2) + " " + text.Substring(2).TrimStart();
var triviaList = Syntax.ParseLeadingTrivia(text);
if (triviaList.Count == 1)
{
return triviaList[0];
}
}
return trivia;
}
示例9: HandleWhitespaceTrivia
private static void HandleWhitespaceTrivia(SyntaxTreeAnalysisContext context, SyntaxTrivia trivia)
{
string fullString = trivia.ToFullString();
if (fullString.StartsWith("////"))
{
// This is a line of commented code.
return;
}
if (fullString.IndexOf('\t') < 0)
{
// No hard tabs were found.
return;
}
// Tabs must not be used.
context.ReportDiagnostic(Diagnostic.Create(Descriptor, trivia.GetLocation()));
}
示例10: RemoveComments
private Task<Document> RemoveComments(Document document, SyntaxNode root, SyntaxTrivia comment, CancellationToken cancellationToken)
{
var startCommentText = comment.ToFullString().Substring(2).Trim(); // skip "//"
var endCommentText = Regex.Replace(startCommentText, @"\bstart\b", "end", RegexOptions.IgnoreCase);
var endCommentRegex = new Regex(string.Join(@"\s+", Regex.Split(endCommentText, @"\s+").Select(n => Regex.Escape(n))), RegexOptions.IgnoreCase);
var lines = new List<SyntaxTrivia>();
var node = comment.Token.Parent.AncestorsAndSelf()
.Where(n => n is BlockSyntax || n is BaseTypeDeclarationSyntax)
.First();
var tokens = node.ChildNodesAndTokens();
foreach (var line in tokens.Where(t => t.HasLeadingTrivia).SelectMany(t => t.GetLeadingTrivia().SplitLines()).SkipWhile(n => !n.Contains(comment)))
{
//skip outside of declaration.
if (line[0].SpanStart < node.SpanStart || line[0].SpanStart > node.Span.End) continue;
// find line contains SingleLineComment only.
foreach (var firstTrivia in line.SkipWhile(n => n.Kind() == SyntaxKind.WhitespaceTrivia).Take(1))
{
if (firstTrivia.Kind() == SyntaxKind.SingleLineCommentTrivia)
{
lines.AddRange(line);
var commentText = firstTrivia.ToFullString();
if (endCommentRegex.IsMatch(commentText))
{
goto EOL;
}
}
}
}
EOL:
var newRoot = root.ReplaceTrivia(lines, (_, __) => default(SyntaxTrivia));
var newDocument = document.WithSyntaxRoot(newRoot);
return Task.FromResult(newDocument);
}
示例11: IsEndOfXmlHeader
private static bool IsEndOfXmlHeader(SyntaxTrivia trivia, out SyntaxTrivia end)
{
var next = GetNextComment(trivia);
var currentFullText = trivia.ToFullString();
var nextFullText = next == null ? string.Empty : next.Value.ToFullString();
end = nextFullText.StartsWith(RulerMarker, StringComparison.OrdinalIgnoreCase)
? next.Value
: trivia;
return currentFullText.StartsWith(EndMarker, StringComparison.OrdinalIgnoreCase);
}
开发者ID:OliverKurowski,项目名称:StylecopCodeFormatter,代码行数:12,代码来源:HasNoCustomCopyrightHeaderFormattingRule.cs
示例12: IsBeginningOfXmlHeader
private static bool IsBeginningOfXmlHeader(SyntaxTrivia trivia, out SyntaxTrivia start)
{
var next = GetNextComment(trivia);
var currentFullText = trivia.ToFullString();
var nextFullText = next == null ? string.Empty : next.Value.ToFullString();
start = trivia;
return currentFullText.StartsWith(StartMarker, StringComparison.OrdinalIgnoreCase) ||
currentFullText.StartsWith(RulerMarker, StringComparison.OrdinalIgnoreCase) &&
nextFullText.StartsWith(StartMarker, StringComparison.OrdinalIgnoreCase);
}
开发者ID:OliverKurowski,项目名称:StylecopCodeFormatter,代码行数:12,代码来源:HasNoCustomCopyrightHeaderFormattingRule.cs
示例13: VisitTrivia
public override void VisitTrivia(SyntaxTrivia trivia)
{
if (trivia.Kind() != SyntaxKind.MultiLineDocumentationCommentTrivia)
{
base.VisitTrivia(trivia);
return;
}
var tokens = trivia.ToFullString()
.RemoveLeadingAndTrailingMultiLineComments()
.SplitOnNewLines(StringSplitOptions.None);
var builder = new StringBuilder();
foreach (var token in tokens)
{
var currentToken = token.RemoveLeadingSpacesAndAsterisk();
var decodedToken = System.Net.WebUtility.HtmlDecode(currentToken);
builder.AppendLine(decodedToken);
}
var text = builder.ToString();
var line = _firstVisit
? trivia.SyntaxTree.GetLineSpan(trivia.Span).StartLinePosition.Line
: _lineNumberOverride.GetValueOrDefault(0);
this.Blocks.Add(new TextBlock(text, line));
}
示例14: HandleSingleLineCommentTrivia
private static void HandleSingleLineCommentTrivia(SyntaxTreeAnalysisContext context, SyntaxTrivia trivia, bool isFirstSingleLineTrivia)
{
string text = trivia.ToFullString();
if (text.Equals(@"//"))
{
return;
}
// special case: commented code or documentation if the parsers documentation mode is DocumentationMode.None
if (text.StartsWith(@"///", StringComparison.Ordinal))
{
return;
}
// Special case: multiple dashes at start of comment
if (text.StartsWith(@"//--", StringComparison.Ordinal))
{
return;
}
// Special case: //\ negates spacing requirements
if (text.StartsWith(@"//\", StringComparison.Ordinal))
{
return;
}
// No need to handle documentation comments ("///") because they're not
// reported as SingleLineCommentTrivia.
int spaceCount = 0;
for (int i = 2; (i < text.Length) && (text[i] == ' '); i++)
{
spaceCount++;
}
if (spaceCount == 1)
{
return;
}
// Special case: follow-on comment lines may be indented with more than
// one space.
if (spaceCount > 1 && !isFirstSingleLineTrivia)
{
return;
}
// Single line comment must begin with a space.
context.ReportDiagnostic(Diagnostic.Create(Descriptor, trivia.GetLocation()));
}
开发者ID:neugenes,项目名称:StyleCopAnalyzers,代码行数:49,代码来源:SA1005SingleLineCommentsMustBeginWithSingleSpace.cs
示例15: IsComment
private static bool IsComment(SyntaxTrivia syntaxTrivia)
{
var isSingleLineComment = syntaxTrivia.IsKind(SyntaxKind.SingleLineCommentTrivia)
&& !syntaxTrivia.ToFullString().StartsWith(@"////", StringComparison.Ordinal);
return isSingleLineComment
|| syntaxTrivia.IsKind(SyntaxKind.MultiLineCommentTrivia);
}
开发者ID:endjin,项目名称:StyleCopAnalyzers,代码行数:7,代码来源:SA1108BlockStatementsMustNotContainEmbeddedComments.cs