コード例 #1
0
 // Ensure that commentBlock and element refer to the same file
 // which can happen when processing multiple files.
 private static void EnsureSameFile(Comments.CommentBlock commentBlock, ref KeyValuePair <Location, Label>?element)
 {
     if (element is not null && element.Value.Key.SourceTree != commentBlock.Location.SourceTree)
     {
         element = null;
     }
 }
コード例 #2
0
        /// <summary>
        /// Generate the bindings between a comment and program elements.
        /// Called once for each commentBlock.
        /// </summary>
        ///
        /// <param name="commentBlock">The comment block.</param>
        /// <param name="previousElement">The element before the comment block.</param>
        /// <param name="nextElement">The element after the comment block.</param>
        /// <param name="parentElement">The parent element of the comment block.</param>
        /// <param name="callback">Output binding information.</param>
        private void GenerateBindings(
            Comments.CommentBlock commentBlock,
            KeyValuePair <Location, Label>?previousElement,
            KeyValuePair <Location, Label>?nextElement,
            KeyValuePair <Location, Label>?parentElement,
            CommentBindingCallback callback
            )
        {
            EnsureSameFile(commentBlock, ref previousElement);
            EnsureSameFile(commentBlock, ref nextElement);
            EnsureSameFile(commentBlock, ref parentElement);

            if (previousElement is not null)
            {
                var key = previousElement.Value.Value;
                callback(key, GetDuplicationGuardKey(key), commentBlock, CommentBinding.Before);
            }

            if (nextElement is not null)
            {
                var key = nextElement.Value.Value;
                callback(key, GetDuplicationGuardKey(key), commentBlock, CommentBinding.After);
            }

            if (parentElement is not null)
            {
                var key = parentElement.Value.Value;
                callback(key, GetDuplicationGuardKey(key), commentBlock, CommentBinding.Parent);
            }

            // Heuristic to decide which is the "best" element associated with the comment.
            KeyValuePair <Location, Label>?bestElement;

            if (previousElement is not null && previousElement.Value.Key.EndLine() == commentBlock.Location.StartLine())
            {
                // 1. If the comment is on the same line as the previous element, use that
                bestElement = previousElement;
            }