本文整理汇总了C#中SyntaxTrivia类的典型用法代码示例。如果您正苦于以下问题:C# SyntaxTrivia类的具体用法?C# SyntaxTrivia怎么用?C# SyntaxTrivia使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SyntaxTrivia类属于命名空间,在下文中一共展示了SyntaxTrivia类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitTrivia
public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
{
if (trivia.Kind() == SyntaxKind.RegionDirectiveTrivia)
{
if (trivia == _region)
{
_nests = 0;
return SyntaxFactory.ElasticSpace;
}
else if (_nests >= 0)
{
_nests++;
}
}
else if (trivia.Kind() == SyntaxKind.EndRegionDirectiveTrivia)
{
if (_nests == 0)
{
_nests = -1;
return SyntaxFactory.ElasticSpace;
}
else if (_nests >= 0)
{
_nests--;
}
}
return base.VisitTrivia(trivia);
}
开发者ID:miya2000,项目名称:RemoveRegionCodeRefactoringSample,代码行数:29,代码来源:RemoveRegionCodeRefactoringSampleProvider.cs
示例2: IsBeginningOrEndOfDocumentComment
private bool IsBeginningOrEndOfDocumentComment(SyntaxTrivia trivia)
{
var currentParent = trivia.Token.Parent;
while (currentParent != null)
{
if (currentParent.Kind() == SyntaxKind.SingleLineDocumentationCommentTrivia ||
currentParent.Kind() == SyntaxKind.MultiLineDocumentationCommentTrivia)
{
if (trivia.Span.End == currentParent.SpanStart ||
trivia.Span.End == currentParent.Span.End)
{
return true;
}
else
{
return false;
}
}
currentParent = currentParent.Parent;
}
return false;
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:25,代码来源:CSharpTriviaFormatter.DocumentationCommentExteriorCommentRewriter.cs
示例3: AddClassification
private void AddClassification(SyntaxTrivia trivia, string type)
{
if (trivia.Width() > 0 && _textSpan.OverlapsWith(trivia.Span))
{
AddClassification(trivia.Span, type);
}
}
示例4: GetRegions
private IEnumerable<OutliningSpan> GetRegions(SyntaxTree syntaxTree, SyntaxTrivia trivia)
{
var outliner = new DisabledTextTriviaOutliner();
var spans = new List<OutliningSpan>();
outliner.CollectOutliningSpans(syntaxTree, trivia, spans, CancellationToken.None);
return spans;
}
示例5: ReplaceTabWithFourSpacesAsync
private Task<Document> ReplaceTabWithFourSpacesAsync(Document document, SyntaxNode root, SyntaxTrivia tabTrivia
, CancellationToken cancellationToken)
{
SyntaxTrivia fourSpacesTrivia = SyntaxFactory.Whitespace(new string(' ', 4 * tabTrivia.Span.Length));
SyntaxNode newRoot = root.ReplaceTrivia(tabTrivia, fourSpacesTrivia);
return Task.FromResult(document.WithSyntaxRoot(newRoot));
}
示例6: IsComment
private static bool IsComment(SyntaxTrivia trivia)
{
return trivia.IsKind(SyntaxKind.SingleLineCommentTrivia) ||
trivia.IsKind(SyntaxKind.MultiLineCommentTrivia) ||
trivia.IsKind(SyntaxKind.SingleLineDocumentationCommentTrivia) ||
trivia.IsKind(SyntaxKind.MultiLineDocumentationCommentTrivia);
}
示例7: 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;
}
示例8: HandleSingleLineComment
private static void HandleSingleLineComment(SyntaxTreeAnalysisContext context, SyntaxTrivia singleLineComment)
{
int index = 0;
// PERF: Explicitly cast to IReadOnlyList so we only box once.
IReadOnlyList<SyntaxTrivia> list = TriviaHelper.GetContainingTriviaList(singleLineComment, out index);
var firstNonWhiteSpace = TriviaHelper.IndexOfFirstNonWhitespaceTrivia(list);
// When we encounter a block of single line comments, we only want to raise this diagnostic
// on the first or last line. This ensures that whitespace in code commented out using
// the Comment Selection option in Visual Studio will not raise the diagnostic for every
// blank line in the code which is commented out.
bool isFirst = index == firstNonWhiteSpace;
if (!isFirst)
{
// This is -2 because we need to go back past the end of line trivia as well.
var lastNonWhiteSpace = TriviaHelper.IndexOfTrailingWhitespace(list) - 2;
if (index != lastNonWhiteSpace)
{
return;
}
}
if (IsNullOrWhiteSpace(singleLineComment.ToString(), 2))
{
var diagnostic = Diagnostic.Create(Descriptor, singleLineComment.GetLocation());
context.ReportDiagnostic(diagnostic);
}
}
示例9: Evaluate
public EvaluationResult Evaluate(SyntaxTrivia node)
{
var result = EvaluateImpl(node);
if (result != null)
{
var sourceTree = node.GetLocation().SourceTree;
var filePath = sourceTree.FilePath;
var typeDefinition = GetNodeType(node.Token.Parent);
var unitNamespace = GetNamespace(node.Token.Parent);
if (result.ErrorCount == 0)
{
result.ErrorCount = 1;
}
result.LinesOfCodeAffected = 0;
result.Namespace = unitNamespace;
result.TypeKind = typeDefinition.Item1;
result.TypeName = typeDefinition.Item2;
result.Title = Title;
result.Suggestion = Suggestion;
result.Quality = Quality;
result.QualityAttribute = QualityAttribute;
result.ImpactLevel = ImpactLevel;
result.FilePath = filePath;
}
return result;
}
示例10: VisitTrivia
public override void VisitTrivia(SyntaxTrivia trivia)
{
if (trivia.Kind != SyntaxKind.DocumentationCommentExteriorTrivia)
{
arg.Append(trivia.ToString());
}
}
示例11: VisitTrivia
public override void VisitTrivia(SyntaxTrivia trivia)
{
if (TriviaPredicate != null && TriviaAction != null && TriviaPredicate(trivia))
{
TriviaAction(trivia);
}
}
示例12: VisitTrivia
public virtual void VisitTrivia(SyntaxTrivia trivia)
{
if (this.Depth >= SyntaxWalkerDepth.StructuredTrivia && trivia.HasStructure)
{
this.Visit((CSharpSyntaxNode)trivia.GetStructure());
}
}
示例13: VisitTrivia
public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
{
var comment = trivia.ToString();
if (trivia.Kind() == SyntaxKind.MultiLineCommentTrivia)
{
if (!comment.StartsWith("/*uncomment"))
{
bool shouldCreateTextBlock = trivia.GetParents().Count(p => IsNestingParent(p, trivia)) <= 1;
if (shouldCreateTextBlock)
Blocks.Add(ExtractMarkDownFromComment(trivia));
}
}
else if (trivia.Kind() == SyntaxKind.SingleLineCommentTrivia)
{
if (comment.StartsWith("//#"))
{
var parts = comment.Split(new[] { ' ' }, 2);
if (parts[0] == "//#video") EmbedVideo(parts[1]);
if (parts[0] == "//#include") EmbedCode(parts[1]);
if (parts[0] == "//#para") EmbedPara(parts[1]);
if (parts[0] == "//#gallery") EmbedGallery(parts[1]);
}
}
return base.VisitTrivia(trivia);
}
示例14: VisitTrivia
public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
{
if (trivia.Kind() == SyntaxKind.WhitespaceTrivia ||
trivia.Kind() == SyntaxKind.EndOfLineTrivia)
return SyntaxTrivia(SyntaxKind.WhitespaceTrivia, string.Empty);
return base.VisitTrivia(trivia);
}
示例15: 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;
}