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


C# SyntaxNode.ChildNodesAndTokens方法代码示例

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


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

示例1: DefaultVisit

        public override void DefaultVisit(SyntaxNode node)
        {
            var childCnt = node.ChildNodesAndTokens().Count;
            int i = 0;

            do
            {
                var child = ChildSyntaxList.ItemInternal((CSharpSyntaxNode)node, i);
                i++;

                var asNode = child.AsNode();
                if (asNode != null)
                {
                    if (this.Depth >= SyntaxWalkerDepth.Node)
                    {
                        this.Visit(asNode);
                    }
                }
                else
                {
                    if (this.Depth >= SyntaxWalkerDepth.Token)
                    {
                        this.VisitToken(child.AsToken());
                    }
                }
            } while (i < childCnt);
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:27,代码来源:CSharpSyntaxWalker.cs

示例2: AreSemanticallyEquivalentWorker

        private static bool AreSemanticallyEquivalentWorker(
            SemanticModel semanticModel1,
            SemanticModel semanticModel2,
            SyntaxNode node1,
            SyntaxNode node2,
            Func<SyntaxNode, bool> predicate)
        {
            if (node1 == node2)
            {
                return true;
            }

            if (predicate == null || predicate(node1))
            {
                var info1 = semanticModel1.GetSymbolInfo(node1);
                var info2 = semanticModel2.GetSymbolInfo(node2);

                if (!AreEquals(semanticModel1, semanticModel2, info1, info2))
                {
                    return false;
                }
            }

            var e1 = node1.ChildNodesAndTokens().GetEnumerator();
            var e2 = node2.ChildNodesAndTokens().GetEnumerator();

            while (true)
            {
                var b1 = e1.MoveNext();
                var b2 = e2.MoveNext();

                if (b1 != b2)
                {
                    Contract.Fail();
                    return false;
                }

                if (b1 == false)
                {
                    return true;
                }

                var c1 = e1.Current;
                var c2 = e2.Current;

                if (c1.IsNode && c2.IsNode)
                {
                    if (!AreSemanticallyEquivalentWorker(semanticModel1, semanticModel2, c1.AsNode(), c2.AsNode(), predicate))
                    {
                        return false;
                    }
                }
            }
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:54,代码来源:SemanticEquivalence.cs

示例3: EnumerateChildren

 private IEnumerable<SyntaxNode> EnumerateChildren(SyntaxNode node)
 {
     foreach (var child in node.ChildNodesAndTokens())
     {
         var childNode = child.AsNode();
         if (childNode != null && GetLabel(childNode) != IgnoredNode)
         {
             yield return childNode;
         }
     }
 }
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:11,代码来源:TopSyntaxComparer.cs

示例4: FindLeafNodeAndPartner

        public static void FindLeafNodeAndPartner(SyntaxNode leftRoot, int leftPosition, SyntaxNode rightRoot, out SyntaxNode leftNode, out SyntaxNode rightNode)
        {
            leftNode = leftRoot;
            rightNode = rightRoot;
            while (true)
            {
                Debug.Assert(leftNode.RawKind == rightNode.RawKind);
                var leftChild = leftNode.ChildThatContainsPosition(leftPosition, out var childIndex);
                if (leftChild.IsToken)
                {
                    return;
                }

                rightNode = rightNode.ChildNodesAndTokens()[childIndex].AsNode();
                leftNode = leftChild.AsNode();
            }
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:17,代码来源:SyntaxUtilities.cs

示例5: LastChildSpan

        public bool LastChildSpan(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText)
        {
            var retVal = true;
            var lastChild = nonTerminal.ChildNodesAndTokens().Last();
            if (nonTerminal.Span.End != lastChild.Span.End)
            {
                retVal = false;
                errorText = "End Span of last child of this non-terminal does not coincide with end Span of this non-terminal";
            }
            else if (nonTerminal.FullSpan.End != lastChild.FullSpan.End)
            {
                retVal = false;
                errorText = "End FullSpan of last child of this non-terminal does not coincide with end FullSpan of this non-terminal";
            }

            return retVal;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:17,代码来源:NodeRules.cs

示例6: FirstChildSpan

        public bool FirstChildSpan(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText)
        {
            var retVal = true;
            var firstChild = nonTerminal.ChildNodesAndTokens().First();
            if (nonTerminal.SpanStart != firstChild.SpanStart)
            {
                retVal = false;
                errorText = "Start Span of first child of this non-terminal does not coincide with start Span of this non-terminal";
            }
            else if (nonTerminal.FullSpan.Start != firstChild.FullSpan.Start)
            {
                retVal = false;
                errorText = "Start FullSpan of first child of this non-terminal does not coincide with start FullSpan of this non-terminal";
            }

            return retVal;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:17,代码来源:NodeRules.cs

示例7: EnumerateChildren

 private IEnumerable<SyntaxNode> EnumerateChildren(SyntaxNode node)
 {
     foreach (var child in node.ChildNodesAndTokens())
     {
         var childNode = child.AsNode();
         if (childNode != null)
         {
             if (GetLabel(childNode) != IgnoredNode)
             {
                 yield return childNode;
             }
             else
             {
                 foreach (var descendant in childNode.DescendantNodesAndTokens(SyntaxUtilities.IsNotLambda))
                 {
                     if (EnumerateExpressionDescendant(descendant.Kind()))
                     {
                         yield return descendant.AsNode();
                     }
                 }
             }
         }
     }
 }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:24,代码来源:StatementSyntaxComparer.cs

示例8: ProcessNode

        private static DgmlNode ProcessNode(SyntaxNode node, int indent = 0)
        {
            var dgmlNode = DgmlNode.Create(node);
            PrintNode(dgmlNode, indent);

            foreach (var childNodeOrToken in node.ChildNodesAndTokens())
            {
                if (childNodeOrToken.IsNode)
                    dgmlNode.AddChild(ProcessNode((SyntaxNode)childNodeOrToken, indent + 1));
                else if (childNodeOrToken.IsToken)
                    dgmlNode.AddChild(ProcessToken((SyntaxToken)childNodeOrToken, indent + 1));
            }

            return dgmlNode;
        }
开发者ID:plaurin,项目名称:RoslynDemo,代码行数:15,代码来源:Program.cs

示例9: InferTypeForFirstParameterOfLambda

            private ITypeSymbol InferTypeForFirstParameterOfLambda(
                string parameterName,
                SyntaxNode node)
            {
                if (node.IsKind(SyntaxKind.IdentifierName))
                {
                    var identifierName = (IdentifierNameSyntax)node;
                    if (identifierName.Identifier.ValueText.Equals(parameterName) &&
                        SemanticModel.GetSymbolInfo(identifierName.Identifier).Symbol?.Kind == SymbolKind.Parameter)
                    {
                        return InferTypes(identifierName).FirstOrDefault().InferredType;
                    }
                }
                else
                {
                    foreach (var child in node.ChildNodesAndTokens())
                    {
                        if (child.IsNode)
                        {
                            var type = InferTypeForFirstParameterOfLambda(parameterName, child.AsNode());
                            if (type != null)
                            {
                                return type;
                            }
                        }
                    }
                }

                return null;
            }
开发者ID:tvsonar,项目名称:roslyn,代码行数:30,代码来源:CSharpTypeInferenceService.TypeInferrer.cs

示例10: SpanAndFullSpanForNonTerminal

        public bool SpanAndFullSpanForNonTerminal(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText)
        {
            var retVal = true;
            if (nonTerminal.ChildNodesAndTokens().Any())
            {
                if (nonTerminal.FullSpan.Start > nonTerminal.SpanStart || nonTerminal.Span.End > nonTerminal.FullSpan.End)
                {
                    retVal = false;
                    errorText = "FullSpan of this non-terminal does not enclose its Span";
                }
            }
            else
            {
                retVal = false;
                errorText = "A non-terminal must have at least one child";
            }

            return retVal;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:19,代码来源:NodeRules.cs

示例11: GetHintSpan

        private static TextSpan GetHintSpan(SyntaxNode node, int endPos)
        {
            // Don't include attributes in the BlockSpan for a node.  When the user
            // hovers over the indent-guide we don't want to show them the line with
            // the attributes, we want to show them the line with the start of the
            // actual structure.
            foreach (var child in node.ChildNodesAndTokens())
            {
                if (child.Kind() != SyntaxKind.AttributeList)
                {
                    return TextSpan.FromBounds(child.SpanStart, endPos);
                }
            }

            return TextSpan.FromBounds(node.SpanStart, endPos);
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:16,代码来源:CSharpStructureHelpers.cs

示例12: ChildSpanWidth

        public bool ChildSpanWidth(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText)
        {
            var retVal = true;
            var total = 0;
            foreach (var child in nonTerminal.ChildNodesAndTokens())
            {
                total = child.FullSpan.Length;
            }

            if (nonTerminal.FullSpan.Length != total)
            {
                retVal = false;
                errorText = "FullSpan width of this non-terminal (" + nonTerminal.FullSpan.Length + ") does not match sum of FullSpan widths of its children (" + total + ")";
            }

            return retVal;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:17,代码来源:NodeRules.cs

示例13: ZeroWidthOrMissingNonTerminals

        public bool ZeroWidthOrMissingNonTerminals(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText)
        {
            var retVal = true;
            if (nonTerminal.ContainsDiagnostics || tree.GetDiagnostics().Any())
            {
                if (nonTerminal.IsMissing)
                {
                    if (nonTerminal.Span.Length == 0)
                    {
                        foreach (var child in nonTerminal.ChildNodesAndTokens())
                        {
                            if (child.IsNode && !child.AsNode().IsMissing)
                            {
                                retVal = false;
                                errorText = "This missing non-terminal has a non-missing child non-terminal";
                                continue;
                            }
                            else if (child.IsToken && !child.AsToken().IsMissing)
                            {
                                retVal = false;
                                errorText = "This missing non-terminal has a non-missing child token";
                                continue;
                            }
                        }
                    }
                    else
                    {
                        retVal = false;
                        errorText = "Missing non-terminals should have 0 Span width";
                    }
                }
                else if (nonTerminal.Span.Length == 0)
                {
                    var kind = nonTerminal.GetKind();
                    if (!(kind == "OmittedArgument" || kind.Contains("Bad") ||
                        (kind == "CompilationUnit" && 
                        nonTerminal.ChildNodesAndTokens().Count == 1 &&
                        nonTerminal.ChildNodesAndTokens().First().GetKind() == "EndOfFileToken")))
                    {
                        //Ignore BadStatement and BadDirective (these can only be present if tree has errors).
                        //Ignore case where code file is empty or file only includes trivia - in this case
                        //root node will have a single child ('EndOfFileToken') which has 0 width.
                        retVal = false;
                        errorText = "Non-terminals with 0 Span width should have IsMissing set to 'True'";
                    }
                }
            }
            else
            {
                if (nonTerminal.IsMissing)
                {
                    retVal = false;
                    errorText = "A tree with 0 errors should not contain missing non-terminals";
                }
                else if (nonTerminal.Span.Length == 0)
                {
                    var kind = nonTerminal.GetKind();
                    if (!(kind == "OmittedArgument" || (kind == "CompilationUnit" && nonTerminal.ChildNodesAndTokens().Count == 1 && nonTerminal.ChildNodesAndTokens().First().GetKind() == "EndOfFileToken")))
                    {
                        //Ignore case where code file is empty or file only includes trivia - in this case
                        //root node will have a single child ('EndOfFileToken') which has 0 width.
                        retVal = false;
                        errorText = "A tree with 0 errors should not contain non-terminals with 0 width";
                    }
                }
            }

            return retVal;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:69,代码来源:NodeRules.cs

示例14: ParentAndChildrenForNonTerminal

        public bool ParentAndChildrenForNonTerminal(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText)
        {
            var retVal = true;
            foreach (var child in nonTerminal.ChildNodesAndTokens())
            {
                if (child.Parent != nonTerminal)
                {
                    retVal = false;
                    errorText = "A child of this non-terminal does not have this non-terminal set as its parent";
                    continue;
                }
            }

            return retVal;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:15,代码来源:NodeRules.cs

示例15: GetSyntaxNodeList

        protected List<SyntaxNode> GetSyntaxNodeList(SyntaxNode node, List<SyntaxNode> synList)
        {
            if (synList == null)
                synList = new List<SyntaxNode>();

            synList.Add(node);

            foreach (var child in node.ChildNodesAndTokens())
            {
                if (child.IsNode)
                    synList = GetSyntaxNodeList(child.AsNode(), synList);
            }

            return synList;
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:15,代码来源:InteractiveSemanticModelTests.cs


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