当前位置: 首页>>代码示例>>C#>>正文


C# SyntaxNode.GetAnnotatedNodesAndTokens方法代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.SyntaxNode.GetAnnotatedNodesAndTokens方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.GetAnnotatedNodesAndTokens方法的具体用法?C# SyntaxNode.GetAnnotatedNodesAndTokens怎么用?C# SyntaxNode.GetAnnotatedNodesAndTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.CodeAnalysis.SyntaxNode的用法示例。


在下文中一共展示了SyntaxNode.GetAnnotatedNodesAndTokens方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestAnnotations

        private void TestAnnotations(
            string expectedText,
            IList<TextSpan> expectedSpans,
            SyntaxNode fixedRoot,
            string annotationKind,
            bool compareTokens,
            ParseOptions parseOptions = null)
        {
            expectedSpans = expectedSpans ?? new List<TextSpan>();
            var annotatedTokens = fixedRoot.GetAnnotatedNodesAndTokens(annotationKind).Select(n => (SyntaxToken)n).ToList();

            Assert.Equal(expectedSpans.Count, annotatedTokens.Count);

            if (expectedSpans.Count > 0)
            {
                var expectedTokens = TokenUtilities.GetTokens(TokenUtilities.GetSyntaxRoot(expectedText, GetLanguage(), parseOptions));
                var actualTokens = TokenUtilities.GetTokens(fixedRoot);

                for (var i = 0; i < Math.Min(expectedTokens.Count, actualTokens.Count); i++)
                {
                    var expectedToken = expectedTokens[i];
                    var actualToken = actualTokens[i];

                    var actualIsConflict = annotatedTokens.Contains(actualToken);
                    var expectedIsConflict = expectedSpans.Contains(expectedToken.Span);
                    Assert.Equal(expectedIsConflict, actualIsConflict);
                }
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:29,代码来源:AbstractCodeActionOrUserDiagnosticTest.cs

示例2: AnnotationResolver

            private SyntaxToken AnnotationResolver(
                SyntaxNode node,
                TriviaLocation location,
                SyntaxAnnotation annotation,
                SyntaxNode callsite,
                MethodDeclarationSyntax method)
            {
                var token = node.GetAnnotatedNodesAndTokens(annotation).FirstOrDefault().AsToken();
                if (token.RawKind != 0)
                {
                    return token;
                }

                switch (location)
                {
                    case TriviaLocation.BeforeBeginningOfSpan:
                        return callsite.GetFirstToken(includeZeroWidth: true).GetPreviousToken(includeZeroWidth: true);
                    case TriviaLocation.AfterEndOfSpan:
                        return callsite.GetLastToken(includeZeroWidth: true).GetNextToken(includeZeroWidth: true);
                    case TriviaLocation.AfterBeginningOfSpan:
                        return method.Body.OpenBraceToken.GetNextToken(includeZeroWidth: true);
                    case TriviaLocation.BeforeEndOfSpan:
                        return method.Body.CloseBraceToken.GetPreviousToken(includeZeroWidth: true);
                }

                return Contract.FailWithReturn<SyntaxToken>("can't happen");
            }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:27,代码来源:CSharpMethodExtractor.TriviaResult.cs

示例3: ResolveAnnotation

 private static SyntaxToken ResolveAnnotation(
     SyntaxNode root,
     TriviaLocation location,
     SyntaxAnnotation annotation)
 {
     return root.GetAnnotatedNodesAndTokens(annotation).FirstOrDefault().AsToken();
 }
开发者ID:GloryChou,项目名称:roslyn,代码行数:7,代码来源:AbstractSyntaxTriviaService.Result.cs

示例4: RemoveAnnotationIfExists

        private static SyntaxNode RemoveAnnotationIfExists(SyntaxNode root, SyntaxAnnotation annotation)
        {
            var element = root.GetAnnotatedNodesAndTokens(annotation).FirstOrDefault();
            if (element == default(SyntaxNodeOrToken))
            {
                return root;
            }

            if (element.IsNode)
            {
                var node = element.AsNode();
                return root.ReplaceNode(
                    node,
                    node.WithoutAnnotations(annotation));
            }

            var token = element.AsToken();
            return root.ReplaceToken(
                token,
                token.WithoutAnnotations(annotation));
        }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:21,代码来源:DocumentBasedFixAllProvider.cs

示例5: GetAnnotatedSpans

        private static IEnumerable<TextSpan> GetAnnotatedSpans(SyntaxNode node, SyntaxAnnotation annotation)
        {
            foreach (var nodeOrToken in node.GetAnnotatedNodesAndTokens(annotation))
            {
                var firstToken = nodeOrToken.IsNode ? nodeOrToken.AsNode().GetFirstToken(includeZeroWidth: true) : nodeOrToken.AsToken();
                var lastToken = nodeOrToken.IsNode ? nodeOrToken.AsNode().GetLastToken(includeZeroWidth: true) : nodeOrToken.AsToken();

                var previousToken = firstToken.GetPreviousToken();
                var nextToken = lastToken.GetNextToken();

                if (previousToken.RawKind != 0)
                {
                    firstToken = previousToken;
                }

                if (nextToken.RawKind != 0)
                {
                    lastToken = nextToken;
                }

                yield return TextSpan.FromBounds(firstToken.SpanStart, lastToken.Span.End);
            }
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:23,代码来源:Formatter.cs

示例6: GetAnnotatedSpans

 private static IEnumerable<TextSpan> GetAnnotatedSpans(SyntaxNode node, SyntaxAnnotation annotation)
 {
     foreach (var nodeOrToken in node.GetAnnotatedNodesAndTokens(annotation))
     {
         var firstToken = nodeOrToken.IsNode ? nodeOrToken.AsNode().GetFirstToken(includeZeroWidth: true) : nodeOrToken.AsToken();
         var lastToken = nodeOrToken.IsNode ? nodeOrToken.AsNode().GetLastToken(includeZeroWidth: true) : nodeOrToken.AsToken();
         yield return GetSpan(firstToken, lastToken);
     }
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:9,代码来源:Formatter.cs


注:本文中的Microsoft.CodeAnalysis.SyntaxNode.GetAnnotatedNodesAndTokens方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。