本文整理汇总了C#中SyntaxNodeOrToken.GetLeadingTrivia方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNodeOrToken.GetLeadingTrivia方法的具体用法?C# SyntaxNodeOrToken.GetLeadingTrivia怎么用?C# SyntaxNodeOrToken.GetLeadingTrivia使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxNodeOrToken
的用法示例。
在下文中一共展示了SyntaxNodeOrToken.GetLeadingTrivia方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NamedImpl
private void NamedImpl(SyntaxNodeOrToken nodeOrToken)
{
string name = null;
string astType = null;
string comments = nodeOrToken.GetLeadingTrivia().ToFullString();
string parentComments = nodeOrToken.Parent != null ? nodeOrToken.Parent.GetLeadingTrivia().ToFullString() : null;
//if this is the hightest ast node for this comment, look for 1 bang, else 2 bangs
string regex = @"@(?<ast_type>[^:\s]+):(?<name>\S+)";
Match match = Regex.Match(comments, regex);
if (match.Success)
{
name = match.Groups["name"].Value;
astType = match.Groups["ast_type"].Value;
SyntaxKind syntaxKind = (SyntaxKind)Enum.Parse(typeof(SyntaxKind), astType);
if (nodeOrToken.Kind() == syntaxKind)
{
names.Add(nodeOrToken, name);
}
}
}
示例2: 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;
}