本文整理汇总了C#中SyntaxToken.GetKind方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxToken.GetKind方法的具体用法?C# SyntaxToken.GetKind怎么用?C# SyntaxToken.GetKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxToken
的用法示例。
在下文中一共展示了SyntaxToken.GetKind方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddToken
private void AddToken(TreeViewItem parentItem, SyntaxToken token)
{
var kind = token.GetKind();
var tag = new SyntaxTag()
{
SyntaxToken = token,
Category = SyntaxCategory.SyntaxToken,
Span = token.Span,
FullSpan = token.FullSpan,
Kind = kind,
ParentItem = parentItem
};
var item = new TreeViewItem()
{
Tag = tag,
IsExpanded = false,
Foreground = Brushes.DarkGreen,
Background = token.ContainsDiagnostics ? Brushes.Pink : Brushes.White,
Header = tag.Kind + " " + token.Span.ToString()
};
if (SyntaxTree != null && token.ContainsDiagnostics)
{
item.ToolTip = string.Empty;
foreach (var diagnostic in SyntaxTree.GetDiagnostics(token))
{
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 = token.GetType().Name;
kindValueLabel.Content = kind;
_propertyGrid.SelectedObject = token;
item.IsExpanded = true;
if (!_isNavigatingFromSourceToTree && SyntaxTokenNavigationToSourceRequested != null)
{
SyntaxTokenNavigationToSourceRequested(token);
}
_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 trivia in token.LeadingTrivia)
{
AddTrivia(item, trivia, true);
}
foreach (var trivia in token.TrailingTrivia)
{
AddTrivia(item, trivia, false);
}
}
});
if (parentItem == null)
{
treeView.Items.Clear();
treeView.Items.Add(item);
}
else
{
parentItem.Items.Add(item);
}
if (token.HasLeadingTrivia || token.HasTrailingTrivia)
{
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 trivia in token.LeadingTrivia)
{
AddTrivia(item, trivia, true);
}
foreach (var trivia in token.TrailingTrivia)
{
AddTrivia(item, trivia, false);
//.........这里部分代码省略.........
示例2: ValidateToken
private bool ValidateToken(SyntaxToken token, SyntaxTree tree, string filename = "", List<Failure> failures = null)
{
var retVal = true;
foreach (var leadingTrivia in token.LeadingTrivia)
{
retVal = retVal & ValidateTrivia(leadingTrivia, tree, filename, failures);
}
foreach (var trailingTrivia in token.TrailingTrivia)
{
retVal = retVal & ValidateTrivia(trailingTrivia, tree, filename, failures);
}
bool pass = false;
foreach (var rule in m_TokenRules.Values)
{
var errorText = string.Empty;
pass = rule.Test(token, tree, ref errorText);
if (!pass)
{
if (failures != null)
{
failures.Add(new Failure(filename, rule, token.GetKind(), errorText, new FailureLocation(token.Span, tree)));
}
ValidationFailed(errorText, rule);
}
retVal = retVal & pass;
}
return retVal;
}
示例3: BadTokens
public bool BadTokens(SyntaxToken token, SyntaxTree tree, ref string errorText)
{
var retVal = true;
var kind = token.GetKind();
if (tree.GetDiagnostics().Any())
{
if (kind.Contains("Bad"))
{
if (tree.GetDiagnostics(token).Any())
{
}
else
{
retVal = false;
errorText = "Bad tokens 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 tokens";
}
return retVal;
}
示例4: WhiteSpaceInTokens
public bool WhiteSpaceInTokens(SyntaxToken token, SyntaxTree tree, ref string errorText)
{
var retVal = true;
var kind = token.GetKind();
if (kind != "StatementTerminatorToken" && kind != "DateLiteralToken" && kind != "StringLiteralToken" && kind != "CharacterLiteralToken" && kind != "XmlTextLiteralToken" && kind != "XmlAttributeDataToken" && kind != "XmlCommentDataToken" && kind != "XmlCDataToken" && kind != "XmlProcessingInstructionDataToken" && kind != "XmlTextLiteralNewLineToken" && kind != "LessThanEqualsToken" && kind != "GreaterThanEqualsToken" && kind != "LessThanGreaterThanToken" && kind != "ColonEqualsToken" && kind != "CaretEqualsToken" && kind != "AsteriskEqualsToken" && kind != "PlusEqualsToken" && kind != "MinusEqualsToken" && kind != "SlashEqualsToken" && kind != "BackslashEqualsToken" && kind != "LessThanLessThanToken" && kind != "GreaterThanGreaterThanToken" && kind != "LessThanLessThanEqualsToken" && kind != "GreaterThanGreaterThanEqualsToken" && kind != "AmpersandEqualsToken")
{
var text = token.ToString();
if ((text.Contains(" ") || text.Contains('\t') || text.Contains('\r') || text.Contains('\n') || text.Contains("\r\n")))
{
retVal = false;
errorText = "The text of this token should not contain any whitespace";
}
}
return retVal;
}
示例5: ZeroWidthOrMissingTokens
public bool ZeroWidthOrMissingTokens(SyntaxToken token, SyntaxTree tree, ref string errorText)
{
var retVal = true;
if (token.ContainsDiagnostics || tree.GetDiagnostics().Any())
{
if (token.IsMissing)
{
if (token.Span.Length == 0)
{
if (token.LeadingTrivia.Any() || token.TrailingTrivia.Any())
{
var atleastOneSkippedTrivia = (
from leadingTrivia in token.LeadingTrivia
let kind = leadingTrivia.GetKind()
where kind == "SkippedTextTrivia" || kind == "SkippedTokens"
select new
{
leadingTrivia,
kind
}
).Any();
if (!atleastOneSkippedTrivia)
{
atleastOneSkippedTrivia = (
from trailingTrivia in token.TrailingTrivia
let kind = trailingTrivia.GetKind()
where kind == "SkippedTextTrivia" || kind == "SkippedTokens"
select new
{
trailingTrivia,
kind
}
).Any();
if (!atleastOneSkippedTrivia)
{
retVal = false;
errorText = "Missing tokens should have at least one trivia with kind SkippedTextTrivia OR SkippedTokens";
}
}
}
}
else
{
retVal = false;
errorText = "Missing tokens should have 0 Span width";
}
}
else if (token.Span.Length == 0)
{
var kind = token.GetKind();
if (!(kind == "EndOfFileToken" || kind == "EmptyToken" || kind == "EndOfDocumentationCommentToken" || kind == "EndOfDirectiveToken" || kind.Contains("Bad")))
{
//BadToken only appears in error trees for C#.
retVal = false;
errorText = "Tokens with 0 Span width should have IsMissing set to 'True'";
}
}
}
else
{
if (token.IsMissing)
{
retVal = false;
errorText = "A tree with 0 errors should not contain missing tokens";
}
else if (token.Span.Length == 0)
{
var kind = token.GetKind();
if (!(kind == "EndOfFileToken" || kind == "EmptyToken" || kind == "EndOfDocumentationCommentToken" || kind == "EndOfDirectiveToken"))
{
//EmptyToken can be present even in non-error cases in VB (it is used for OmittedArgument).
retVal = false;
errorText = "A tree with 0 errors should not contain tokens with 0 width";
}
}
}
return retVal;
}