Example #1
0
        /// <summary>
        /// This method checks the given method declarations are too long based on the configured limits. If so, the method
        /// declaration and the corresponding limit configuration is put together in an instance of  <see cref="LongMethodOccurrence">LongMethodOccurrence</see>.
        /// </summary>
        /// <param name="methodDeclarations">The list of method declarations that will be analyzed.</param>
        private void AnalyzeAndCacheLongMethodOccurrences(IEnumerable <MethodDeclarationSyntax> methodDeclarations)
        {
            if (methodDeclarations == null)
            {
                throw new ArgumentNullException(nameof(methodDeclarations));
            }

            _longMethodOccurrences.Clear();

            foreach (var methodDeclaration in methodDeclarations)
            {
                var linesOfCode = methodDeclaration.Body.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 LongMethodOccurrence(methodDeclaration, correspondingLimitConfiguration);
                    _longMethodOccurrences.Add(occurence);
                }
            }
        }
Example #2
0
        /// <summary>
        /// This method creates the visual for a method background and moves it to the correct position.
        /// </summary>
        /// <param name="adornmentBounds">The bounds of the rectangular adornment.</param>
        /// <param name="longMethodOccurence">The occurence of the method declaration for which the visual will be created.</param>
        /// <returns>Returns the image that is the visual adornment (method background).</returns>
        private Image CreateAndPositionMethodBackgroundVisual(Rect adornmentBounds, LongMethodOccurrence longMethodOccurence)
        {
            if (adornmentBounds == null)
            {
                throw new ArgumentNullException(nameof(adornmentBounds));
            }

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

            var backgroundGeometry = new RectangleGeometry(adornmentBounds);

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

            backgroundBrush.Freeze();

            var drawing = new GeometryDrawing(backgroundBrush, ConfigurationManager.LongMethodBorderPen, 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);
        }