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


C# SyntaxNode.ChildNodesAndTokens方法代码示例

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


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

示例1: GetLastToken

        internal SyntaxToken GetLastToken(SyntaxNode current, Func<SyntaxToken, bool> predicate, Func<SyntaxTrivia, bool> stepInto)
        {
            foreach (var child in current.ChildNodesAndTokens().Reverse())
            {
                var token = child.IsToken
                    ? GetLastToken(child.AsToken(), predicate, stepInto)
                    : GetLastToken(child.AsNode(), predicate, stepInto);

                if (token.RawKind != None)
                {
                    return token;
                }
            }

            return default(SyntaxToken);
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:16,代码来源:AbstractSyntaxNavigator.cs

示例2: Visit

 /// <summary>
 /// Called when the walker visits a node.  This method may be overridden if subclasses want
 /// to handle the node.  Overrides should call back into this base method if they want the
 /// children of this node to be visited.
 /// </summary>
 /// <param name="node">The current node that the walker is visiting.</param>
 public virtual void Visit(SyntaxNode node)
 {
     foreach (var child in node.ChildNodesAndTokens())
     {
         if (child.IsNode)
         {
             if (this.Depth >= SyntaxWalkerDepth.Node)
             {
                 Visit(child.AsNode());
             }
         }
         else if (child.IsToken)
         {
             if (this.Depth >= SyntaxWalkerDepth.Token)
             {
                 VisitToken(child.AsToken());
             }
         }
     }
 }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:26,代码来源:SyntaxWalker.cs

示例3: GetFirstToken

        internal SyntaxToken GetFirstToken(SyntaxNode current, Func<SyntaxToken, bool> predicate, Func<SyntaxTrivia, bool> stepInto)
        {
            var stack = s_childEnumeratorStackPool.Allocate();
            try
            {
                stack.Push(current.ChildNodesAndTokens().GetEnumerator());

                while (stack.Count > 0)
                {
                    var en = stack.Pop();
                    if (en.MoveNext())
                    {
                        var child = en.Current;

                        if (child.IsToken)
                        {
                            var token = GetFirstToken(child.AsToken(), predicate, stepInto);
                            if (token.RawKind != None)
                            {
                                return token;
                            }
                        }

                        // push this enumerator back, not done yet
                        stack.Push(en);

                        if (child.IsNode)
                        {
                            stack.Push(child.AsNode().ChildNodesAndTokens().GetEnumerator());
                        }
                    }
                }

                return default(SyntaxToken);
            }
            finally
            {
                stack.Clear();
                s_childEnumeratorStackPool.Free(stack);
            }
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:41,代码来源:AbstractSyntaxNavigator.cs

示例4: Resolve

            private static SymbolKeyResolution? Resolve(
                SemanticModel semanticModel, SyntaxNode syntaxNode, string name, ISymbol target,
                CancellationToken cancellationToken)
            {
                var symbol = semanticModel.GetDeclaredSymbol(syntaxNode, cancellationToken);
                if (symbol != null)
                {
                    if (symbol.Kind == SymbolKind.Alias)
                    {
                        var aliasSymbol = (IAliasSymbol)symbol;
                        if (aliasSymbol.Name == name &&
                            SymbolEquivalenceComparer.Instance.Equals(aliasSymbol.Target, target))
                        {
                            return new SymbolKeyResolution(aliasSymbol);
                        }
                    }
                    else if (symbol.Kind != SymbolKind.Namespace)
                    {
                        // Don't recurse into anything except namespaces.  We can't find aliases
                        // any deeper than that.
                        return null;
                    }
                }

                foreach (var child in syntaxNode.ChildNodesAndTokens())
                {
                    if (child.IsNode)
                    {
                        var result = Resolve(semanticModel, child.AsNode(), name, target, cancellationToken);
                        if (result.HasValue)
                        {
                            return result;
                        }
                    }
                }

                return null;
            }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:38,代码来源:SymbolKey.AliasSymbolKey.cs

示例5: AddNode

        private void AddNode(TreeViewItem parentItem, SyntaxNode node)
        {
            var kind = node.GetKind();
            var tag = new SyntaxTag()
            {
                SyntaxNode = node,
                Category = SyntaxCategory.SyntaxNode,
                Span = node.Span,
                FullSpan = node.FullSpan,
                Kind = kind,
                ParentItem = parentItem
            };

            var item = new TreeViewItem()
            {
                Tag = tag,
                IsExpanded = false,
                Foreground = Brushes.Blue,
                Background = node.ContainsDiagnostics ? Brushes.Pink : Brushes.White,
                Header = tag.Kind + " " + node.Span.ToString()
            };

            if (SyntaxTree != null && node.ContainsDiagnostics)
            {
                item.ToolTip = string.Empty;
                foreach (var diagnostic in SyntaxTree.GetDiagnostics(node))
                {
                    item.ToolTip += diagnostic.ToString() + "\n";
                }

                item.ToolTip = item.ToolTip.ToString().Trim();
            }

            item.Selected += new RoutedEventHandler((sender, e) =>
            {
                _isNavigatingFromTreeToSource = true;

                typeTextLabel.Visibility = Visibility.Visible;
                kindTextLabel.Visibility = Visibility.Visible;
                typeValueLabel.Content = node.GetType().Name;
                kindValueLabel.Content = kind;
                _propertyGrid.SelectedObject = node;

                item.IsExpanded = true;

                if (!_isNavigatingFromSourceToTree && SyntaxNodeNavigationToSourceRequested != null)
                {
                    SyntaxNodeNavigationToSourceRequested(node);
                }

                _isNavigatingFromTreeToSource = false;
                e.Handled = true;
            });

            item.Expanded += new RoutedEventHandler((sender, e) =>
            {
                if (item.Items.Count == 1 && item.Items[0] == null)
                {
                    // Remove placeholder child and populate real children.
                    item.Items.RemoveAt(0);
                    foreach (var child in node.ChildNodesAndTokens())
                    {
                        AddNodeOrToken(item, child);
                    }
                }
            });

            if (parentItem == null)
            {
                treeView.Items.Clear();
                treeView.Items.Add(item);
            }
            else
            {
                parentItem.Items.Add(item);
            }

            if (node.ChildNodesAndTokens().Count > 0)
            {
                if (IsLazy)
                {
                    // Add placeholder child to indicate that real children need to be populated on expansion.
                    item.Items.Add(null);
                }
                else
                {
                    // Recursively populate all descendants.
                    foreach (var child in node.ChildNodesAndTokens())
                    {
                        AddNodeOrToken(item, child);
                    }
                }
            }
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:94,代码来源:SyntaxVisualizerControl.xaml.cs

示例6: VisitBody

			void VisitBody (SyntaxNode node)
			{
				var oldIter = curIter;

				foreach (var syntaxNodeOrToken in node.ChildNodesAndTokens ()) {
					var syntaxNode = syntaxNodeOrToken.AsNode ();
					if (syntaxNode != null) {
						Visit (syntaxNode);
					} else {
						var syntaxToken = syntaxNodeOrToken.AsToken ();
						if (syntaxToken.Kind () == SyntaxKind.OpenBraceToken)
							curIter = Append (node);
						VisitToken (syntaxToken);
					}
				}
				curIter = oldIter;

			}
开发者ID:powerumc,项目名称:monodevelop_korean,代码行数:18,代码来源:CSharpOutlineTextEditorExtension.cs

示例7: GetAllSymbols

        private void GetAllSymbols(SemanticModel model, SyntaxNode node, List<ISymbol> list)
        {
            var symbol = model.GetDeclaredSymbol(node);
            if (symbol != null)
            {
                list.Add(symbol);
            }

            symbol = model.GetSymbolInfo(node).GetAnySymbol();
            if (symbol != null)
            {
                list.Add(symbol);
            }

            foreach (var child in node.ChildNodesAndTokens())
            {
                if (child.IsNode)
                {
                    GetAllSymbols(model, child.AsNode(), list);
                }
            }
        }
开发者ID:jkotas,项目名称:roslyn,代码行数:22,代码来源:SymbolKeyTests.cs


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