本文整理汇总了C#中SyntaxNode.GetKind方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.GetKind方法的具体用法?C# SyntaxNode.GetKind怎么用?C# SyntaxNode.GetKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxNode
的用法示例。
在下文中一共展示了SyntaxNode.GetKind方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValidateNonTerminal
private bool ValidateNonTerminal(SyntaxNode nonTerminal, SyntaxTree tree, string filename = "", List<Failure> failures = null)
{
var retVal = true;
if (!string.IsNullOrEmpty(filename))
{
filename = Path.GetFullPath(filename);
}
else if (filename == null)
{
filename = string.Empty;
}
if (nonTerminal != null)
{
foreach (var child in nonTerminal.ChildNodesAndTokens())
{
retVal = retVal & ValidateNodeOrToken(child, tree, filename, failures);
}
bool pass = false;
foreach (var rule in m_NonTerminalRules.Values)
{
var errorText = string.Empty;
pass = rule.Test(nonTerminal, tree, ref errorText);
if (!pass)
{
if (failures != null)
{
failures.Add(new Failure(filename, rule, nonTerminal.GetKind(), errorText, new FailureLocation(nonTerminal.Span, tree)));
}
ValidationFailed(errorText, rule);
}
retVal = retVal & pass;
}
}
return retVal;
}
示例2: 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;
}
示例3: BadNonTerminals
public bool BadNonTerminals(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText)
{
var retVal = true;
var kind = nonTerminal.GetKind();
if (tree.GetDiagnostics().Any())
{
if (kind.Contains("Bad"))
{
if (tree.GetDiagnostics(nonTerminal).Any())
{
}
else
{
retVal = false;
errorText = "Bad non-terminals should have at least one error on them";
}
}
}
else if (kind.Contains("Bad"))
{
retVal = false;
errorText = "A tree with 0 errors should not contain Bad non-terminals";
}
return retVal;
}
示例4: ParentForNonTerminal
public bool ParentForNonTerminal(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText)
{
var retVal = true;
if (nonTerminal.Parent == null)
{
if (!nonTerminal.IsStructuredTrivia && nonTerminal.GetKind() != "CompilationUnit")
{
retVal = false;
errorText = "This non-terminal has a null parent";
}
}
else
{
if (nonTerminal.IsStructuredTrivia)
{
retVal = false;
errorText = "This structured trivia has a non-null parent";
}
}
return retVal;
}