Exemplo n.º 1
0
        /// <summary>
        /// This method checks if the given block syntaxes are too long based on the configured limits. If so, the block syntax
        /// and the corresponding limit configuration is put together in an instance of  <see cref="LongCodeBlockOccurrence">LongCodeBlockOccurrence</see>.
        /// </summary>
        /// <param name="codeBlocks">The list of block syntaxes that will be analyzed.</param>
        private void AnalyzeAndCacheLongCodeBlockOccurrences(IEnumerable <BlockSyntax> codeBlocks)
        {
            if (codeBlocks == null)
            {
                throw new ArgumentNullException(nameof(codeBlocks));
            }

            _longCodeBlockOccurrences.Clear();

            foreach (var codeBlock in codeBlocks)
            {
                var linesOfCode = codeBlock
                                  .WithoutLeadingTrivia()
                                  .WithoutTrailingTrivia()
                                  .GetText()
                                  .Lines
                                  .Count;
                var correspondingLimitConfiguration = null as LongMethodLimitConfiguration;

                foreach (var limitConfiguration in ConfigurationManager.Configuration.MethodTooLongLimits.OrderBy(limit => limit.Lines))
                {
                    if (linesOfCode < limitConfiguration.Lines)
                    {
                        break;
                    }

                    correspondingLimitConfiguration = limitConfiguration;
                }

                if (correspondingLimitConfiguration != null)
                {
                    var occurence = new LongCodeBlockOccurrence(codeBlock, correspondingLimitConfiguration);
                    _longCodeBlockOccurrences.Add(occurence);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method creates the visual for a code block background and moves it to the correct position.
        /// </summary>
        /// <param name="adornmentBounds">The bounds of the rectangular adornment.</param>
        /// <param name="longCodeBlockOccurence">The occurence of the code block for which the visual will be created.</param>
        /// <returns>Returns the image that is the visual adornment (code block background).</returns>
        private Image CreateAndPositionCodeBlockBackgroundVisual(Rect adornmentBounds, LongCodeBlockOccurrence longCodeBlockOccurence)
        {
            if (adornmentBounds == null)
            {
                throw new ArgumentNullException(nameof(adornmentBounds));
            }

            if (longCodeBlockOccurence == null)
            {
                throw new ArgumentNullException(nameof(longCodeBlockOccurence));
            }

            var backgroundGeometry = new RectangleGeometry(adornmentBounds);

            var backgroundBrush = new SolidColorBrush(longCodeBlockOccurence.LimitConfiguration.Color);

            backgroundBrush.Freeze();

            var drawing = new GeometryDrawing(backgroundBrush, ConfigurationManager.LongCodeBlockBorderPen, backgroundGeometry);

            drawing.Freeze();

            var drawingImage = new DrawingImage(drawing);

            drawingImage.Freeze();

            var image = new Image
            {
                Source = drawingImage
            };

            Canvas.SetLeft(image, adornmentBounds.Left);
            Canvas.SetTop(image, adornmentBounds.Top);

            return(image);
        }