/// <summary> /// Combines a range of symbols into a single symbol. /// </summary> /// <param name="startIndex">The start peek index of the first symbol to combine.</param> /// <param name="endIndex">The end peek index of the last symbol to combine.</param> /// <param name="text">The text for the new symbol.</param> /// <param name="type">The type of the new symbol.</param> public void Combine(int startIndex, int endIndex, string text, SymbolType type) { Param.AssertGreaterThanOrEqualToZero(startIndex, "startIndex"); Param.AssertGreaterThanOrEqualTo(endIndex, startIndex, "endIndex"); Param.AssertValidString(text, "text"); Param.Ignore(type); // Adjust the indexes. int adjustedStartIndex = startIndex + this.index; int adjustedEndIndex = endIndex + this.index; CsLanguageService.Debug.Assert(adjustedStartIndex >= 0 && adjustedStartIndex < this.symbols.Count, "The adjusted start index should be within the symbol list"); CsLanguageService.Debug.Assert(adjustedEndIndex >= 0 && adjustedEndIndex < this.symbols.Count, "The adjusted end index should be within the symbol list"); // Map the new location of the combined symbol. CodeLocation location = CodeLocation.Join( this.symbols[adjustedStartIndex].Location, this.symbols[adjustedEndIndex].Location); // Create the new symbol. var symbol = new Symbol(text, type, location); // Replace the first symbol. this.symbols[adjustedStartIndex] = symbol; // Remove the rest of the symbols. ++adjustedStartIndex; if (adjustedStartIndex <= adjustedEndIndex) { this.symbols.RemoveRange(adjustedStartIndex, adjustedEndIndex - adjustedStartIndex + 1); } }
/// <summary> /// Joins the locations of the two code units. /// </summary> /// <param name="codeUnit1">The first code unit.</param> /// <param name="location2">The second location.</param> /// <returns>Returns the joined location.</returns> internal static CodeLocation JoinLocations(CodeUnit codeUnit1, CodeLocation location2) { Param.Ignore(codeUnit1, location2); if (codeUnit1 == null) { if (location2 == null) { return(CodeLocation.Empty); } return(location2); } else if (location2 == null) { return(CodeLocation.Join(codeUnit1.Location, null)); } else { return(CodeLocation.Join(codeUnit1.Location, location2)); } }