コード例 #1
0
        /// <summary>Returns a list of all related <see cref="HostfileLine"/> objects that are part of the same multiline comment; if the specified <paramref name="line"/> is a multiline comment.</summary>
        /// <param name="line">The <see cref="HostfileLine"/> which is a member of a multiline comment.</param>
        /// <returns>A <see cref="List{HostfileLine}"/> of all related <see cref="HostfileLine"/> objects that are part of the same multiline comment; if the specified <paramref name="line"/> is a multiline comment.</returns>
        private List <HostfileLine> GetAllRelatedComments(HostfileLine line)
        {
            if (line == null)
            {
                return(null);
            }

            /* navigate to the beginning of the multi-line comment */
            while (line.Previous != null && line.Previous.IsMultiLineComment)
            {
                line = line.Previous;
            }

            int          currentLineNumber = line.LineNumber;
            int          nextNonMultiLineCommentLineNumber = this.LineByLineNavigator.Count;
            HostfileLine nextNonMultiLineComment           = this.LineByLineNavigator.Where(l => l.LineNumber > currentLineNumber && l.IsMultiLineComment == false).FirstOrDefault();

            if (nextNonMultiLineComment != null)
            {
                nextNonMultiLineCommentLineNumber = nextNonMultiLineComment.LineNumber;
            }

            List <HostfileLine> comments =
                this.LineByLineNavigator.Where(
                    l =>
                    l.LineNumber >= currentLineNumber && l.LineNumber < nextNonMultiLineCommentLineNumber &&
                    l.IsMultiLineComment).ToList();

            return(comments);
        }
コード例 #2
0
        /// <summary>Return the parent <see cref="HostfileLine"/> which marks the group-start for the specified <paramref name="line"/>; if the specified <paramref name="line"/> is part of a group.</summary>
        /// <param name="line">The <see cref="HostfileLine"/> object that is part of group.</param>
        /// <returns>The parent <see cref="HostfileLine"/> which marks the group-start for the specified <paramref name="line"/>; if the specified <paramref name="line"/> is part of a group. Otherwise null.</returns>
        private static HostfileLine GetParentHostGroup(HostfileLine line)
        {
            bool isAGroupControlElement = line.IsGroupStart || line.IsGroupEnd;

            if (isAGroupControlElement == false)
            {
                while ((line = line.Previous) != null)
                {
                    if (line.IsGroupEnd)
                    {
                        return(null);
                    }

                    if (line.IsGroupStart)
                    {
                        return(line);
                    }
                }
            }
            else
            {
                return(line);
            }

            return(null);
        }
コード例 #3
0
        /// <summary>Returns the text of a multiline comment if the specified <paramref name="line"/> is part of a multiline comment.</summary>
        /// <param name="line">The <see cref="HostfileLine"/> which is a member of a multiline comment.</param>
        /// <returns>The text of a multiline comment if the specified <paramref name="line"/> is part of a multiline comment; otherwise null.</returns>
        private string GetMultiLineCommentText(HostfileLine line)
        {
            List <HostfileLine> relatedComments = this.GetAllRelatedComments(line);

            if (relatedComments != null && relatedComments.Count > 0)
            {
                return(relatedComments.Select(l => l.Values.FirstOrDefault()).Aggregate((l1, l2) => string.Concat(l1, Environment.NewLine, l2)));
            }

            return(null);
        }
コード例 #4
0
        /// <summary>Returns the text of a multiline comment if the specified <paramref name="line"/> is part of a multiline comment.</summary>
        /// <param name="line">The <see cref="HostfileLine"/> which is a member of a multiline comment.</param>
        /// <returns>The text of a multiline comment if the specified <paramref name="line"/> is part of a multiline comment; otherwise null.</returns>
        private string GetMultiLineCommentText(HostfileLine line)
        {
            List<HostfileLine> relatedComments = this.GetAllRelatedComments(line);
            if (relatedComments != null && relatedComments.Count > 0)
            {
                return relatedComments.Select(l => l.Values.FirstOrDefault()).Aggregate((l1, l2) => string.Concat(l1, Environment.NewLine, l2));
            }

            return null;
        }
コード例 #5
0
        /// <summary>Returns a list of all related <see cref="HostfileLine"/> objects that are part of the same multiline comment; if the specified <paramref name="line"/> is a multiline comment.</summary>
        /// <param name="line">The <see cref="HostfileLine"/> which is a member of a multiline comment.</param>
        /// <returns>A <see cref="List{HostfileLine}"/> of all related <see cref="HostfileLine"/> objects that are part of the same multiline comment; if the specified <paramref name="line"/> is a multiline comment.</returns>
        private List<HostfileLine> GetAllRelatedComments(HostfileLine line)
        {
            if (line == null)
            {
                return null;
            }

            /* navigate to the beginning of the multi-line comment */
            while (line.Previous != null && line.Previous.IsMultiLineComment)
            {
                line = line.Previous;
            }

            int currentLineNumber = line.LineNumber;
            int nextNonMultiLineCommentLineNumber = this.LineByLineNavigator.Count;
            HostfileLine nextNonMultiLineComment = this.LineByLineNavigator.Where(l => l.LineNumber > currentLineNumber && l.IsMultiLineComment == false).FirstOrDefault();
            if (nextNonMultiLineComment != null)
            {
                nextNonMultiLineCommentLineNumber = nextNonMultiLineComment.LineNumber;
            }

            List<HostfileLine> comments =
                this.LineByLineNavigator.Where(
                    l =>
                    l.LineNumber >= currentLineNumber && l.LineNumber < nextNonMultiLineCommentLineNumber &&
                    l.IsMultiLineComment).ToList();

            return comments;
        }
コード例 #6
0
        /// <summary>Return the parent <see cref="HostfileLine"/> which marks the group-start for the specified <paramref name="line"/>; if the specified <paramref name="line"/> is part of a group.</summary>
        /// <param name="line">The <see cref="HostfileLine"/> object that is part of group.</param>
        /// <returns>The parent <see cref="HostfileLine"/> which marks the group-start for the specified <paramref name="line"/>; if the specified <paramref name="line"/> is part of a group. Otherwise null.</returns>
        private static HostfileLine GetParentHostGroup(HostfileLine line)
        {
            bool isAGroupControlElement = line.IsGroupStart || line.IsGroupEnd;

            if (isAGroupControlElement == false)
            {
                while ((line = line.Previous) != null)
                {
                    if (line.IsGroupEnd)
                    {
                        return null;
                    }

                    if (line.IsGroupStart)
                    {
                        return line;
                    }
                }
            }
            else
            {
                return line;
            }

            return null;
        }