本文整理汇总了C#中SyntaxNodeOrToken.ChildNodesAndTokens方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNodeOrToken.ChildNodesAndTokens方法的具体用法?C# SyntaxNodeOrToken.ChildNodesAndTokens怎么用?C# SyntaxNodeOrToken.ChildNodesAndTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxNodeOrToken
的用法示例。
在下文中一共展示了SyntaxNodeOrToken.ChildNodesAndTokens方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GatherNodes
private static void GatherNodes(SyntaxNodeOrToken node, HashSet<GreenNode> hashSet)
{
hashSet.Add(node.UnderlyingNode);
foreach (var child in node.ChildNodesAndTokens())
{
GatherNodes(child, hashSet);
}
}
示例2: GetRebuiltNodes
private static void GetRebuiltNodes(SyntaxNodeOrToken newNode, HashSet<GreenNode> hashSet, ArrayBuilder<SyntaxNodeOrToken> nodes)
{
if (hashSet.Contains(newNode.UnderlyingNode))
{
return;
}
nodes.Add(newNode);
foreach (var child in newNode.ChildNodesAndTokens())
{
GetRebuiltNodes(child, hashSet, nodes);
}
}
示例3: CompareTreeEquivalence
private static void CompareTreeEquivalence(SyntaxNodeOrToken parsedTreeNode, SyntaxNodeOrToken incrementalTreeNode)
{
Assert.Equal(parsedTreeNode.Kind(), incrementalTreeNode.Kind());
Assert.Equal(parsedTreeNode.ChildNodesAndTokens().Count, incrementalTreeNode.ChildNodesAndTokens().Count);
for (int i = 0; i < parsedTreeNode.ChildNodesAndTokens().Count; i++)
{
CompareTreeEquivalence(parsedTreeNode.ChildNodesAndTokens()[i], incrementalTreeNode.ChildNodesAndTokens()[i]);
}
}
示例4: WalkTreeAndVerify
private void WalkTreeAndVerify(SyntaxNodeOrToken incNode, SyntaxNodeOrToken fullNode)
{
var incChildren = incNode.ChildNodesAndTokens();
var fullChildren = fullNode.ChildNodesAndTokens();
Assert.Equal(incChildren.Count, fullChildren.Count);
for (int i = 0; i < incChildren.Count; i++)
{
var incChild = incChildren[i];
var fullChild = fullChildren[i];
WalkTreeAndVerify(incChild, fullChild);
}
}
示例5: AssertNodesAreEquivalent
private void AssertNodesAreEquivalent(SyntaxNodeOrToken expectedNode, SyntaxNodeOrToken actualNode)
{
Assert.Equal(expectedNode.Kind(), actualNode.Kind());
Assert.Equal(expectedNode.FullSpan, actualNode.FullSpan);
Assert.Equal(expectedNode.ChildNodesAndTokens().Count, actualNode.ChildNodesAndTokens().Count);
for (var i = 0; i < expectedNode.ChildNodesAndTokens().Count; i++)
{
AssertNodesAreEquivalent(expectedNode.ChildNodesAndTokens()[i],
actualNode.ChildNodesAndTokens()[i]);
}
}
示例6: GetSimilarity
private int GetSimilarity(SyntaxNodeOrToken node1, SyntaxNodeOrToken node2)
{
// count the characters in the common/identical nodes
int w = 0;
_nodeSimilaritySet.Clear();
_tokenTextSimilaritySet.Clear();
if (node1.IsToken && node2.IsToken)
{
var text1 = node1.ToString();
var text2 = node2.ToString();
if (text1 == text2)
{
// main text of token is the same
w += text1.Length;
}
foreach (var tr in node1.GetLeadingTrivia())
{
_nodeSimilaritySet.Add(tr.UnderlyingNode);
}
foreach (var tr in node1.GetTrailingTrivia())
{
_nodeSimilaritySet.Add(tr.UnderlyingNode);
}
foreach (var tr in node2.GetLeadingTrivia())
{
if (_nodeSimilaritySet.Contains(tr.UnderlyingNode))
{
w += tr.FullSpan.Length;
}
}
foreach (var tr in node2.GetTrailingTrivia())
{
if (_nodeSimilaritySet.Contains(tr.UnderlyingNode))
{
w += tr.FullSpan.Length;
}
}
}
else
{
foreach (var n1 in node1.ChildNodesAndTokens())
{
_nodeSimilaritySet.Add(n1.UnderlyingNode);
if (n1.IsToken)
{
_tokenTextSimilaritySet.Add(n1.ToString());
}
}
foreach (var n2 in node2.ChildNodesAndTokens())
{
if (_nodeSimilaritySet.Contains(n2.UnderlyingNode))
{
w += n2.FullSpan.Length;
}
else if (n2.IsToken)
{
var tokenText = n2.ToString();
if (_tokenTextSimilaritySet.Contains(tokenText))
{
w += tokenText.Length;
}
}
}
}
return w;
}
示例7: GetDepth
private static int GetDepth(SyntaxNodeOrToken syntax, int depth = 0)
{
if (syntax.IsNode)
{
return syntax.ChildNodesAndTokens().Count == 0 ? depth : syntax.ChildNodesAndTokens().Max(x => GetDepth(x, depth + 1));
}
return (syntax.AsToken().HasLeadingTrivia || syntax.AsToken().HasTrailingTrivia) ? depth + 1 : depth;
}