本文整理汇总了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);
}
示例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;
}
}
}
}
示例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;
}
}
}
示例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();
}
}
示例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;
}
示例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;
}
示例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();
}
}
}
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}