Ejemplo n.º 1
0
        /////// <summary>
        /////// Joins the locations of the two tokens.
        /////// </summary>
        /////// <param name="token1">The first token.</param>
        /////// <param name="location2">The second location.</param>
        /////// <returns>Returns the joined locations.</returns>
        ////internal static CodeLocation JoinLocations(Node<CsToken> token1, CodeLocation location2)
        ////{
        ////    Param.Ignore(token1, location2);
        ////    return CsToken.JoinLocations(token1 == null ? null : token1.Value, location2);
        ////}

        /// <summary>
        /// Joins the locations of the two tokens.
        /// </summary>
        /// <param name="token1">
        /// The first token.
        /// </param>
        /// <param name="token2">
        /// The second token.
        /// </param>
        /// <returns>
        /// Returns the joined locations.
        /// </returns>
        internal static CodeLocation JoinLocations(CsToken token1, CsToken token2)
        {
            Param.AssertNotNull(token1, "token1");
            Param.AssertNotNull(token2, "token2");

            return(CodeLocation.Join(token1.Location, token2.Location));
        }
Ejemplo n.º 2
0
        /// <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;

            Debug.Assert(adjustedStartIndex >= 0 && adjustedStartIndex < this.symbols.Count, "The adjusted start index should be within the symbol list");
            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.
            Symbol 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>
            /// Gets the location of one of the arguments in the list.
            /// </summary>
            /// <param name="index">The index of an argument in the list.</param>
            /// <returns>Returns the location of the arguments.</returns>
            public CodeLocation Location(int index)
            {
                Param.AssertValueBetween(index, 0, this.argumentList.Count - 1, "index");

                Argument argument = this.argumentList[index];

                // The location must be calculated by finding the first and last items
                // in the argument and joining their locations.
                CodeUnit firstItem = null;

                for (CodeUnit item = argument.FindFirstChild(); item != null; item = item.FindNextSibling())
                {
                    if (!item.Is(LexicalElementType.WhiteSpace) &&
                        !item.Is(LexicalElementType.EndOfLine) &&
                        !item.Is(CommentType.SingleLineComment) &&
                        !item.Is(CommentType.MultilineComment))
                    {
                        firstItem = item;
                        break;
                    }
                }

                if (firstItem != null)
                {
                    return(CodeLocation.Join(firstItem.Location, argument.FindLast().Location));
                }

                return(argument.Location);
            }
Ejemplo n.º 4
0
            /// <summary>
            /// Gets the location of one of the parameters in the list.
            /// </summary>
            /// <param name="index">
            /// The index of a parameter in the list.
            /// </param>
            /// <returns>
            /// Returns the location of the parameters.
            /// </returns>
            public CodeLocation Location(int index)
            {
                Param.AssertValueBetween(index, 0, this.parameters.Count - 1, "index");

                // The location must be calculated by finding the first and last tokens
                // in the parameter and joining their locations.
                CsTokenList tokens = this.parameters[index].Tokens;

                CsToken firstToken = null;

                for (Node <CsToken> tokenNode = tokens.First.Previous; tokenNode != null; tokenNode = tokenNode.Previous)
                {
                    if (tokenNode.Value.CsTokenType == CsTokenType.Comma || tokenNode.Value.CsTokenType == CsTokenType.OpenSquareBracket ||
                        tokenNode.Value.CsTokenType == CsTokenType.OpenParenthesis)
                    {
                        // We've found the start of the parameter list. Now move forward to find the first word.
                        for (tokenNode = tokenNode.Next; tokenNode != null; tokenNode = tokenNode.Next)
                        {
                            if (tokenNode.Value.CsTokenType != CsTokenType.Attribute && tokenNode.Value.CsTokenType != CsTokenType.WhiteSpace &&
                                tokenNode.Value.CsTokenType != CsTokenType.EndOfLine && tokenNode.Value.CsTokenType != CsTokenType.SingleLineComment &&
                                tokenNode.Value.CsTokenType != CsTokenType.MultiLineComment)
                            {
                                firstToken = tokenNode.Value;
                                break;
                            }
                        }

                        break;
                    }
                }

                if (firstToken != null)
                {
                    return(CodeLocation.Join(firstToken.Location, tokens.Last.Value.Location));
                }

                return(this.parameters[index].Location);
            }
Ejemplo n.º 5
0
 /// <summary>
 /// Joins the locations of the two tokens.
 /// </summary>
 /// <param name="location1">
 /// The first location.
 /// </param>
 /// <param name="token2">
 /// The second token.
 /// </param>
 /// <returns>
 /// Returns the joined locations.
 /// </returns>
 internal static CodeLocation JoinLocations(CodeLocation location1, CsToken token2)
 {
     Param.Ignore(location1, token2);
     return(token2 == null?CodeLocation.Join(location1, null) : CodeLocation.Join(location1, token2.Location));
 }