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


C# SyntaxToken.GetCommonRoot方法代码示例

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


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

示例1: GetInitialIndentBlockOperations

            private List<IndentBlockOperation> GetInitialIndentBlockOperations(SyntaxToken startToken, SyntaxToken endToken)
            {
                var span = TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End);
                var node = startToken.GetCommonRoot(endToken).GetParentWithBiggerSpan();
                var previous = default(SyntaxNode);

                // starting from the common node, move up to the parent
                var operations = new List<IndentBlockOperation>();
                var list = new List<IndentBlockOperation>();
                while (node != null)
                {
                    // get all operations for the nodes that contains the formatting span, but not ones contained by the span
                    node.DescendantNodesAndSelf(n => n != previous && n.Span.IntersectsWith(span) && !span.Contains(n.Span))
                        .Do(n =>
                            {
                                this.formattingRules.AddIndentBlockOperations(list, n);
                                foreach (var element in list)
                                {
                                    if (element != null)
                                    {
                                        operations.Add(element);
                                    }
                                }

                                list.Clear();
                            });

                    // found some. use these as initial indentation
                    if (operations.Any(o => o.TextSpan.Contains(span)))
                    {
                        break;
                    }

                    previous = node;
                    node = node.Parent;
                }

                // make sure operations we have has effects over the formatting span
                operations.RemoveAll(o => o == null || !o.TextSpan.IntersectsWith(span));

                // we couldn't find anything
                // return initial location so that we can get base indentation correctly
                if (operations.Count == 0)
                {
                    operations.Add(new IndentBlockOperation(
                        startToken: this.rootNode.GetFirstToken(includeZeroWidth: true),
                        endToken: this.rootNode.GetLastToken(includeZeroWidth: true),
                        textSpan: this.rootNode.FullSpan,
                        indentationDelta: 0,
                        option: IndentBlockOption.AbsolutePosition));

                    return operations;
                }

                operations.Sort(CommonFormattingHelpers.IndentBlockOperationComparer);
                return operations;
            }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:57,代码来源:FormattingContext.InitialContextFinder.cs

示例2: FormatRange

        public IList<TextChange> FormatRange(
            Workspace workspace, SyntaxToken startToken, SyntaxToken endToken, CancellationToken cancellationToken)
        {
            Contract.ThrowIfTrue(startToken.Kind() == SyntaxKind.None || startToken.Kind() == SyntaxKind.EndOfFileToken);
            Contract.ThrowIfTrue(endToken.Kind() == SyntaxKind.None || endToken.Kind() == SyntaxKind.EndOfFileToken);

            var smartTokenformattingRules = _formattingRules;
            var common = startToken.GetCommonRoot(endToken);
            if (common.ContainsDiagnostics)
            {
                // if there is errors, do not touch lines
                smartTokenformattingRules = (new NoLineChangeFormattingRule()).Concat(_formattingRules);
            }

            return Formatter.GetFormattedTextChanges(_root, new TextSpan[] { TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End) }, workspace, _optionSet, smartTokenformattingRules, cancellationToken);
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:16,代码来源:SmartTokenFormatter.cs

示例3: FormatRange

        public IList<TextChange> FormatRange(
            Workspace workspace, SyntaxToken startToken, SyntaxToken endToken, CancellationToken cancellationToken)
        {
            Contract.ThrowIfTrue(startToken.Kind() == SyntaxKind.None || startToken.Kind() == SyntaxKind.EndOfFileToken);
            Contract.ThrowIfTrue(endToken.Kind() == SyntaxKind.None || endToken.Kind() == SyntaxKind.EndOfFileToken);

            var smartTokenformattingRules = _formattingRules;
            var common = startToken.GetCommonRoot(endToken);

            // if there are errors, do not touch lines
            // Exception: In the case of try-catch-finally block, a try block without a catch/finally block is considered incomplete
            //            but we would like to apply line operation in a completed try block even if there is no catch/finally block
            if (common.ContainsDiagnostics && !CloseBraceOfTryBlock(endToken))
            {
                smartTokenformattingRules = (new NoLineChangeFormattingRule()).Concat(_formattingRules);
            }

            return Formatter.GetFormattedTextChanges(_root, new TextSpan[] { TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End) }, workspace, _optionSet, smartTokenformattingRules, cancellationToken);
        }
开发者ID:vmussak,项目名称:roslyn,代码行数:19,代码来源:SmartTokenFormatter.cs

示例4: GetNodeWithTokens

 internal SyntaxNode GetNodeWithTokens(SyntaxToken startToken, SyntaxToken endToken, SyntaxNode root)
 {
     if (IsEndOfFileToken(endToken))
     {
         return root;
     }
     else
     {
         return startToken.GetCommonRoot(endToken);
     }
 }
开发者ID:hbarve1,项目名称:roslyn,代码行数:11,代码来源:AbstractSuppressionCodeFixProvider.cs

示例5: SetInnermostNodeForSpan

        private void SetInnermostNodeForSpan(SyntaxNode root, ref TextSpan span, out SyntaxToken token1, out SyntaxToken token2, out SyntaxNode commonNode)
        {
            commonNode = default(SyntaxNode);

            GetTokens(root, span, out token1, out token2);

            span = GetSpanFromTokens(span, token1, token2);

            if (token1.RawKind == 0 || token2.RawKind == 0)
            {
                return;
            }

            commonNode = token1.GetCommonRoot(token2);
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:15,代码来源:BaseIndentationFormattingRule.cs


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