本文整理汇总了C#中TokenData.GetPreviousTokenData方法的典型用法代码示例。如果您正苦于以下问题:C# TokenData.GetPreviousTokenData方法的具体用法?C# TokenData.GetPreviousTokenData怎么用?C# TokenData.GetPreviousTokenData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TokenData
的用法示例。
在下文中一共展示了TokenData.GetPreviousTokenData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetColumn
/// <summary>
/// Get column of the token
/// * column means text position on a line where all tabs are converted to spaces that first position on a line becomes 0
/// </summary>
private int GetColumn(TokenData tokenData, Func<TokenData, TokenData, TriviaData> triviaDataGetter)
{
// at the beginning of a file.
var previousToken = tokenData.GetPreviousTokenData();
var spaces = 0;
for (; previousToken.Token.RawKind != 0; previousToken = previousToken.GetPreviousTokenData())
{
var triviaInfo = triviaDataGetter(previousToken, tokenData);
if (triviaInfo.SecondTokenIsFirstTokenOnLine)
{
// current token is the first token on line.
// add up spaces so far and triviaInfo.Space which means indentation in this case
return spaces + triviaInfo.Spaces;
}
// add spaces so far
spaces += triviaInfo.Spaces;
// here, we can't just add token's length since there is token that span multiple lines.
GetTokenLength(previousToken.Token, out var tokenLength, out var multipleLines);
if (multipleLines)
{
return spaces + tokenLength;
}
spaces += tokenLength;
tokenData = previousToken;
}
// we reached beginning of the tree, add spaces at the beginning of the tree
return spaces + triviaDataGetter(previousToken, tokenData).Spaces;
}
示例2: GetColumn
/// <summary>
/// Get column of the token
/// * column means text position on a line where all tabs are converted to spaces that first position on a line becomes 0
/// </summary>
private int GetColumn(TokenData tokenData, Func<TokenData, TokenData, TriviaData> triviaDataGetter)
{
// at the beginning of a file.
var previousToken = tokenData.GetPreviousTokenData();
if (previousToken.Token.RawKind == 0)
{
// use space of the trivia data since it means indentation in this case
return triviaDataGetter(previousToken, tokenData).Spaces;
}
var spaces = 0;
for (; previousToken.Token.RawKind != 0; previousToken = previousToken.GetPreviousTokenData())
{
var triviaInfo = triviaDataGetter(previousToken, tokenData);
if (triviaInfo.SecondTokenIsFirstTokenOnLine)
{
// current token is the first token on line.
// add up spaces so far and triviaInfo.Space which means indentation in this case
return spaces + triviaInfo.Spaces;
}
// add spaces so far
spaces += triviaInfo.Spaces;
// here, we can't just add token's length since there is token that span multiple lines.
var text = previousToken.Token.ToString();
if (text.GetNumberOfLineBreaks() > 0)
{
// add up spaces so far and text indentation
return spaces + text.GetTextColumn(this.optionSet.GetOption(FormattingOptions.TabSize, this.treeData.Root.Language), initialColumn: 0);
}
// add spaces so far
if (text.ContainsTab())
{
// do expansive calculation
var initialColumn = this.treeData.GetOriginalColumn(this.optionSet.GetOption(FormattingOptions.TabSize, this.treeData.Root.Language), previousToken.Token);
spaces += text.ConvertTabToSpace(this.optionSet.GetOption(FormattingOptions.TabSize, this.treeData.Root.Language), initialColumn, text.Length);
}
else
{
spaces += text.Length;
}
tokenData = previousToken;
}
// we reached beginning of the tree, add spaces at the beginning of the tree
return spaces + triviaDataGetter(previousToken, tokenData).Spaces;
}