public TokenStream(TreeData treeData, OptionSet optionSet, TextSpan spanToFormat, AbstractTriviaDataFactory factory) { using (Logger.LogBlock(FunctionId.Formatting_TokenStreamConstruction, CancellationToken.None)) { // initialize basic info _factory = factory; _treeData = treeData; _optionSet = optionSet; // use some heuristics to get initial size of list rather than blindly start from default size == 4 int sizeOfList = spanToFormat.Length / MagicTextLengthToTokensRatio; _tokens = new List<SyntaxToken>(sizeOfList); _tokens.AddRange(_treeData.GetApplicableTokens(spanToFormat)); Contract.Requires(this.TokenCount > 0); // initialize trivia related info _cachedOriginalTriviaInfo = new TriviaData[this.TokenCount - 1]; _tokenToIndexMap = new Dictionary<SyntaxToken, int>(this.TokenCount); for (int i = 0; i < this.TokenCount; i++) { _tokenToIndexMap.Add(_tokens[i], i); } // Func Cache _getTriviaData = this.GetTriviaData; _getOriginalTriviaData = this.GetOriginalTriviaData; } DebugCheckTokenOrder(); }
public TokenStream(TreeData treeData, OptionSet optionSet, TextSpan spanToFormat, AbstractTriviaDataFactory factory) { using (Logger.LogBlock(FunctionId.Formatting_TokenStreamConstruction, CancellationToken.None)) { // initialize basic info this.factory = factory; this.treeData = treeData; this.optionSet = optionSet; // use some heuristics to get initial size of list rather than blindly start from default size == 4 int sizeOfList = spanToFormat.Length / MagicTextLengthToTokensRatio; this.tokens = new List <SyntaxToken>(sizeOfList); this.tokens.AddRange(this.treeData.GetApplicableTokens(spanToFormat)); Contract.Requires(this.TokenCount > 0); // initialize trivia related info this.changes = new Changes(); this.cachedOriginalTriviaInfo = new TriviaData[this.TokenCount - 1]; this.tokenToIndexMap = new Dictionary <SyntaxToken, int>(this.TokenCount); for (int i = 0; i < this.TokenCount; i++) { this.tokenToIndexMap.Add(this.tokens[i], i); } // Func Cache this.getTriviaData = this.GetTriviaData; this.getOriginalTriviaData = this.GetOriginalTriviaData; } DebugCheckTokenOrder(); }
public TokenStream(TreeData treeData, AnalyzerConfigOptions options, TextSpan spanToFormat, AbstractTriviaDataFactory factory) { using (Logger.LogBlock(FunctionId.Formatting_TokenStreamConstruction, CancellationToken.None)) { // initialize basic info _factory = factory; _treeData = treeData; _options = options; // use some heuristics to get initial size of list rather than blindly start from default size == 4 var sizeOfList = spanToFormat.Length / MagicTextLengthToTokensRatio; _tokens = new List <SyntaxToken>(sizeOfList); _tokens.AddRange(_treeData.GetApplicableTokens(spanToFormat)); Debug.Assert(this.TokenCount > 0); // initialize trivia related info _cachedOriginalTriviaInfo = new TriviaData[this.TokenCount - 1]; // Func Cache _getTriviaData = this.GetTriviaData; _getOriginalTriviaData = this.GetOriginalTriviaData; } DebugCheckTokenOrder(); }