├── .build ├── MSBuild.Community.Tasks.dll └── MSBuild.Community.Tasks.targets ├── .gitignore ├── .hgignore ├── .nuget ├── NuGet.Config ├── NuGet.exe ├── NuGet.targets └── packages.config ├── Build.proj ├── CodeMetrics.Addin ├── CodeMetrics.Addin.csproj ├── CodeMetrics.AddinPackage.cs ├── GlobalSuppressions.cs ├── Guids.cs ├── Key.snk ├── Properties │ └── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Resources │ └── Package.ico ├── VSPackage.resx └── source.extension.vsixmanifest ├── CodeMetrics.Adornments ├── Adornments │ ├── ColorToBrushConverter.cs │ ├── ComplexityToColor.cs │ ├── IMetricsAdornment.cs │ ├── MeticsAdornmentFactory.cs │ └── MetricsAdornment.cs ├── CodeMetrics.Adornments.csproj ├── CodeMetrics.Adornments.csproj.user ├── CodeMetricsPackage.cs ├── GuidList.cs ├── Options │ ├── GeneralOptionsPage.cs │ ├── GeneralOptionsPageContent.Designer.cs │ ├── GeneralOptionsPageContent.cs │ ├── GeneralOptionsPageContent.resx │ ├── IOptions.cs │ ├── Options.cs │ └── Resources │ │ └── SettingsStorageCommand.png ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── UserControls │ ├── ColorChangedEventArgs.cs │ ├── ColorSelection.Designer.cs │ ├── ColorSelection.cs │ ├── ColorSelection.resx │ ├── ComplexityView.xaml │ ├── ComplexityView.xaml.cs │ └── ComplexityViewModel.cs ├── VSPackage.Designer.cs ├── VSPackage.resx ├── app.config ├── packages.config └── source.extension.vsixmanifest ├── CodeMetrics.Calculators ├── App.config ├── BranchesVisitor.cs ├── CodeMetrics.Calculators.csproj ├── Complexity.cs ├── ComplexityCalculator.cs ├── ConditionVisitor.cs ├── IComplexity.cs ├── IComplexityCalculator.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── CodeMetrics.Common ├── App.config ├── CodeMetrics.Common.csproj ├── ContainerFactory.cs ├── Properties │ └── AssemblyInfo.cs ├── RepositoriesInstaller.cs └── packages.config ├── CodeMetrics.DataTransferObjects ├── CodeMetrics.DataTransferObjects.csproj ├── Properties │ └── AssemblyInfo.cs └── TaskRequest.cs ├── CodeMetrics.Parsing ├── CodeMetrics.Parsing.csproj ├── ConstructorsVisitor.cs ├── IBranchesVisitor.cs ├── IMethod.cs ├── IMethodsExtractor.cs ├── IMethodsVisitor.cs ├── IMethodsVisitorFactory.cs ├── Location.cs ├── Method.cs ├── MethodsExtractor.cs ├── MethodsVisitor.cs ├── MethodsVisitorFactory.cs ├── NRefactoryExtensions.cs ├── Properties │ └── AssemblyInfo.cs ├── PropertyVisitor.cs └── packages.config ├── CodeMetrics.sln ├── Dependencies ├── NRefactory │ ├── ICSharpCode.NRefactory.CSharp.dll │ ├── ICSharpCode.NRefactory.CSharp.xml │ ├── ICSharpCode.NRefactory.Xml.dll │ ├── ICSharpCode.NRefactory.Xml.xml │ ├── ICSharpCode.NRefactory.dll │ └── ICSharpCode.NRefactory.xml ├── Nunit │ └── nunit.framework.dll └── Windsor │ ├── Castle.Core.dll │ ├── Castle.Core.pdb │ ├── Castle.Core.xml │ ├── Castle.Windsor.XML │ ├── Castle.Windsor.dll │ ├── Castle.Windsor.pdb │ ├── loggingFacility │ ├── Castle.Facilities.Logging.dll │ ├── Castle.Facilities.Logging.pdb │ ├── Castle.Facilities.Logging.xml │ ├── Castle.Services.Logging.Log4netIntegration.dll │ ├── Castle.Services.Logging.Log4netIntegration.pdb │ ├── Castle.Services.Logging.NLogIntegration.dll │ ├── Castle.Services.Logging.NLogIntegration.pdb │ ├── NLog.Extended.dll │ ├── NLog.Extended.xml │ ├── NLog.dll │ ├── NLog.netfx40.xsd │ ├── NLog.xml │ ├── NLog.xsd │ ├── log4net.dll │ ├── log4net.license.txt │ └── log4net.xml │ └── synchronizeFacility │ ├── Castle.Facilities.Synchronize.dll │ └── Castle.Facilities.Synchronize.pdb ├── License.txt ├── README.md ├── Tests ├── CodeMetrics.Adornments.Tests │ ├── CodeMetrics.Adornments.Tests.csproj │ ├── ColorConverterTest.cs │ ├── ColorToBrushConverterTests.cs │ ├── ComplexityViewModelTests.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── app.config │ └── packages.config ├── CodeMetrics.Calculators.Tests │ ├── CodeMetrics.Calculators.Tests.csproj │ ├── ComplexityCalculatorTests.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ToStringTests.cs │ ├── app.config │ └── packages.config └── CodeMetrics.Parsing.Tests │ ├── CodeMetrics.Parsing.Tests.csproj │ ├── ConstructorExtractorTests.cs │ ├── ExtractorsTestBase.cs │ ├── MethodsExtractorTests.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── PropertyExtractorTests.cs │ ├── ToStringTests.cs │ ├── app.config │ └── packages.config ├── Version └── VersionInfo.cs ├── build.xml └── packages └── repositories.config /.build/MSBuild.Community.Tasks.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/.build/MSBuild.Community.Tasks.dll -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/obj/** 2 | **/bin/** 3 | packages/** 4 | .vs/CodeMetrics/v15/.suo -------------------------------------------------------------------------------- /.hgignore: -------------------------------------------------------------------------------- 1 | syntax: glob 2 | _ReSharper* 3 | *.csproj.user 4 | */obj/* 5 | */bin/* 6 | *.ncb 7 | *.suo 8 | *.ReSharper.user 9 | CodeMetrics.sln.DotSettings.user 10 | packages/** 11 | TestResult.xml 12 | GlobalAssemblyInfo.cs 13 | -------------------------------------------------------------------------------- /.nuget/NuGet.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.nuget/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/.nuget/NuGet.exe -------------------------------------------------------------------------------- /.nuget/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Build.proj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(MSBuildProjectDirectory)\.build 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 1.0.0.0 13 | 1.0.0.0 14 | 1.0.0.0 15 | 16 | 17 | 18 | 19 | 1.0.0.0 20 | $(BUILD_NUMBER) 21 | $(BUILD_NUMBER) 22 | 23 | 24 | 25 | Release 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 36 | 37 | 38 | 39 | 40 | 41 | 49 | 50 | 51 | 52 | 53 | 54 | Configuration=$(BuildConfiguration) 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /CodeMetrics.Addin/CodeMetrics.Addin.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 2.0 7 | {4b9be9d4-ee3f-4ca0-936c-d3ea993b7153} 8 | {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 9 | Library 10 | Properties 11 | EliShalom.CodeMetrics_Addin 12 | CodeMetrics.Addin 13 | True 14 | Key.snk 15 | v4.0 16 | 17 | 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | true 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | false 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | {80CC9F66-E7D8-4DDD-85B6-D9E6CD0E93E2} 58 | 8 59 | 0 60 | 0 61 | primary 62 | False 63 | False 64 | 65 | 66 | {26AD1324-4B7C-44BC-84F8-B86AED45729F} 67 | 10 68 | 0 69 | 0 70 | primary 71 | False 72 | False 73 | 74 | 75 | {1A31287A-4D7D-413E-8E32-3B374931BD89} 76 | 8 77 | 0 78 | 0 79 | primary 80 | False 81 | False 82 | 83 | 84 | {2CE2370E-D744-4936-A090-3FFFE667B0E1} 85 | 9 86 | 0 87 | 0 88 | primary 89 | False 90 | False 91 | 92 | 93 | {1CBA492E-7263-47BB-87FE-639000619B15} 94 | 8 95 | 0 96 | 0 97 | primary 98 | False 99 | False 100 | 101 | 102 | {00020430-0000-0000-C000-000000000046} 103 | 2 104 | 0 105 | 0 106 | primary 107 | False 108 | False 109 | 110 | 111 | 112 | 113 | 114 | True 115 | True 116 | Resources.resx 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | ResXFileCodeGenerator 126 | Resources.Designer.cs 127 | Designer 128 | 129 | 130 | true 131 | VSPackage 132 | 133 | 134 | 135 | 136 | Designer 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | true 148 | 149 | 150 | 151 | 158 | 159 | -------------------------------------------------------------------------------- /CodeMetrics.Addin/CodeMetrics.AddinPackage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Globalization; 4 | using System.Runtime.InteropServices; 5 | using System.ComponentModel.Design; 6 | using System.Windows.Forms; 7 | using Microsoft.Win32; 8 | using Microsoft.VisualStudio; 9 | using Microsoft.VisualStudio.Shell.Interop; 10 | using Microsoft.VisualStudio.OLE.Interop; 11 | using Microsoft.VisualStudio.Shell; 12 | 13 | namespace EliShalom.CodeMetrics_Addin 14 | { 15 | /// 16 | /// This is the class that implements the package exposed by this assembly. 17 | /// 18 | /// The minimum requirement for a class to be considered a valid package for Visual Studio 19 | /// is to implement the IVsPackage interface and register itself with the shell. 20 | /// This package uses the helper classes defined inside the Managed Package Framework (MPF) 21 | /// to do it: it derives from the Package class that provides the implementation of the 22 | /// IVsPackage interface and uses the registration attributes defined in the framework to 23 | /// register itself and its components with the shell. 24 | /// 25 | // This attribute tells the PkgDef creation utility (CreatePkgDef.exe) that this class is 26 | // a package. 27 | [PackageRegistration(UseManagedResourcesOnly = true)] 28 | // This attribute is used to register the informations needed to show the this package 29 | // in the Help/About dialog of Visual Studio. 30 | [InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] 31 | [Guid(GuidList.guidCodeMetrics_AddinPkgString)] 32 | public sealed class CodeMetrics_AddinPackage : Package 33 | { 34 | /// 35 | /// Default constructor of the package. 36 | /// Inside this method you can place any initialization code that does not require 37 | /// any Visual Studio service because at this point the package object is created but 38 | /// not sited yet inside Visual Studio environment. The place to do all the other 39 | /// initialization is the Initialize method. 40 | /// 41 | public CodeMetrics_AddinPackage() 42 | { 43 | Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString())); 44 | } 45 | 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // Overriden Package Implementation 50 | #region Package Members 51 | 52 | /// 53 | /// Initialization of the package; this method is called right after the package is sited, so this is the place 54 | /// where you can put all the initilaization code that rely on services provided by VisualStudio. 55 | /// 56 | protected override void Initialize() 57 | { 58 | MessageBox.Show("Init"); 59 | Trace.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); 60 | base.Initialize(); 61 | 62 | } 63 | #endregion 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /CodeMetrics.Addin/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage 2 | // attributes that are applied to this project. Project-level 3 | // suppressions either have no target or are given a specific target 4 | // and scoped to a namespace, type, member, etc. 5 | // 6 | // To add a suppression to this file, right-click the message in the 7 | // Error List, point to "Suppress Message(s)", and click "In Project 8 | // Suppression File". You do not need to add suppressions to this 9 | // file manually. 10 | 11 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1017:MarkAssembliesWithComVisible")] 12 | -------------------------------------------------------------------------------- /CodeMetrics.Addin/Guids.cs: -------------------------------------------------------------------------------- 1 | // Guids.cs 2 | // MUST match guids.h 3 | using System; 4 | 5 | namespace EliShalom.CodeMetrics_Addin 6 | { 7 | static class GuidList 8 | { 9 | public const string guidCodeMetrics_AddinPkgString = "010275b7-93f0-49b4-a2d8-6a1eda131e57"; 10 | public const string guidCodeMetrics_AddinCmdSetString = "7d4c2edd-0f52-4db5-a45e-a173bdbc051a"; 11 | 12 | public static readonly Guid guidCodeMetrics_AddinCmdSet = new Guid(guidCodeMetrics_AddinCmdSetString); 13 | }; 14 | } -------------------------------------------------------------------------------- /CodeMetrics.Addin/Key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/CodeMetrics.Addin/Key.snk -------------------------------------------------------------------------------- /CodeMetrics.Addin/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Resources; 4 | using System.Runtime.CompilerServices; 5 | using System.Runtime.InteropServices; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | [assembly: AssemblyTitle("Code Metrics")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("Eli Shalom")] 14 | [assembly: AssemblyProduct("Code Metrics")] 15 | [assembly: AssemblyCopyright("")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | [assembly: ComVisible(false)] 19 | [assembly: CLSCompliant(false)] 20 | [assembly: NeutralResourcesLanguage("en-US")] 21 | 22 | // Version information for an assembly consists of the following four values: 23 | // 24 | // Major Version 25 | // Minor Version 26 | // Build Number 27 | // Revision 28 | // 29 | // You can specify all the values or you can default the Revision and Build Numbers 30 | // by using the '*' as shown below: 31 | 32 | [assembly: AssemblyVersion("1.0.0.0")] 33 | [assembly: AssemblyFileVersion("1.0.0.0")] 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /CodeMetrics.Addin/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:2.0.50727.42 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace EliShalom.CodeMetrics_Addin { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("EliShalom.CodeMetrics_Addin.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /CodeMetrics.Addin/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 11 | 12 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | text/microsoft-resx 119 | 120 | 121 | 2.0 122 | 123 | 124 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 125 | 126 | 127 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 128 | 129 | -------------------------------------------------------------------------------- /CodeMetrics.Addin/Resources/Package.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/CodeMetrics.Addin/Resources/Package.ico -------------------------------------------------------------------------------- /CodeMetrics.Addin/source.extension.vsixmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Code Metrics 5 | CodeMetrics 6 | 1.0 7 | Addin for Visual Studio for code metrics visualizations 8 | 1033 9 | false 10 | 11 | 12 | Pro 13 | 14 | 15 | 16 | 17 | 18 | 19 | Visual Studio MPF 20 | 21 | 22 | 23 | |%CurrentProject%;PkgdefProjectOutputGroup| 24 | 25 | 26 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/Adornments/ColorToBrushConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | using System.Windows.Media; 5 | 6 | namespace CodeMetrics.Adornments 7 | { 8 | public class ColorToBrushConverter : IValueConverter 9 | { 10 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 11 | { 12 | if (value is Color) 13 | { 14 | Color color = (Color)value; 15 | return new SolidColorBrush(color); 16 | } 17 | 18 | return Brushes.Transparent; 19 | } 20 | 21 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 22 | { 23 | throw new NotImplementedException(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/Adornments/ComplexityToColor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Media; 3 | using CodeMetrics.Options; 4 | 5 | namespace CodeMetrics.Adornments 6 | { 7 | internal class ComplexityToColor 8 | { 9 | private readonly IOptions options; 10 | 11 | private const int MaximumComplexityThreshold = 10; 12 | 13 | public ComplexityToColor(IOptions options) 14 | { 15 | this.options = options; 16 | } 17 | 18 | public Color Convert(int complexity) 19 | { 20 | var ratio = (Math.Min(complexity, MaximumComplexityThreshold))/ (double)MaximumComplexityThreshold; 21 | Color maximumColor = ToMediaColor(this.options.BadColor); 22 | Color minimumColor = ToMediaColor(this.options.GoodColor); 23 | return CombineColor(maximumColor, ratio, minimumColor); 24 | } 25 | 26 | private Color ToMediaColor(System.Drawing.Color source) 27 | { 28 | return Color.FromArgb(source.A, source.R, source.G, source.B); 29 | } 30 | 31 | private static Color CombineColor(Color color2, double ratio, Color color1) 32 | { 33 | return Color.FromRgb((byte)(color2.R*ratio + color1.R*(1D - ratio)), 34 | (byte)(color2.G*ratio + color1.G*(1D - ratio)), 35 | (byte)(color2.B*ratio + color1.B*(1D - ratio))); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /CodeMetrics.Adornments/Adornments/IMetricsAdornment.cs: -------------------------------------------------------------------------------- 1 | namespace CodeMetrics.Adornments 2 | { 3 | public interface IMetricsAdornment 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /CodeMetrics.Adornments/Adornments/MeticsAdornmentFactory.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.Composition; 2 | using Castle.Windsor; 3 | using CodeMetrics.Calculators; 4 | using CodeMetrics.Common; 5 | using CodeMetrics.Parsing; 6 | using Microsoft.VisualStudio.Text.Editor; 7 | using Microsoft.VisualStudio.Utilities; 8 | 9 | namespace CodeMetrics.Adornments 10 | { 11 | [Export(typeof(IWpfTextViewCreationListener))] 12 | [ContentType("csharp")] 13 | [TextViewRole(PredefinedTextViewRoles.Document)] 14 | internal sealed class MeticsAdornmentFactory : IWpfTextViewCreationListener 15 | { 16 | public const string ADORNMENT_NAME = "MetricsAdornment"; 17 | 18 | [Export(typeof(AdornmentLayerDefinition))] 19 | [Name(ADORNMENT_NAME)] 20 | [Order(After = PredefinedAdornmentLayers.Selection, Before = PredefinedAdornmentLayers.Text)] 21 | [TextViewRole(PredefinedTextViewRoles.Document)] 22 | public AdornmentLayerDefinition EditorAdornmentLayer; 23 | 24 | public void TextViewCreated(IWpfTextView textView) 25 | { 26 | WindsorContainer container = ContainerFactory.CreateContainer(); 27 | 28 | var methodsExtractor = container.Resolve(); 29 | var complexityCalculator = container.Resolve(); 30 | new MetricsAdornment(textView, methodsExtractor, complexityCalculator); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /CodeMetrics.Adornments/Adornments/MetricsAdornment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | using System.Windows.Controls; 5 | using CodeMetrics.Calculators; 6 | using CodeMetrics.Parsing; 7 | using CodeMetrics.UserControls; 8 | using Microsoft.VisualStudio.Text; 9 | using Microsoft.VisualStudio.Text.Editor; 10 | using System.Linq; 11 | 12 | namespace CodeMetrics.Adornments 13 | { 14 | public class MetricsAdornment : IMetricsAdornment 15 | { 16 | readonly IAdornmentLayer layer; 17 | readonly IWpfTextView view; 18 | private readonly IMethodsExtractor methodsExtractor; 19 | private readonly IComplexityCalculator complexityCalculator; 20 | 21 | private Dictionary methodToText; 22 | 23 | private readonly Options.Options options = new Options.Options(); 24 | 25 | public MetricsAdornment(IWpfTextView view, IMethodsExtractor methodsExtractor, IComplexityCalculator complexityCalculator) 26 | { 27 | this.view = view; 28 | layer = view.GetAdornmentLayer(MeticsAdornmentFactory.ADORNMENT_NAME); 29 | 30 | this.view.LayoutChanged += OnLayoutChanged; 31 | this.view.TextBuffer.PostChanged += OnTextBufferChanged; 32 | 33 | this.methodsExtractor = methodsExtractor; 34 | this.complexityCalculator = complexityCalculator; 35 | 36 | Init(view.TextSnapshot); 37 | } 38 | 39 | private void OnTextBufferChanged(object sender, EventArgs eventArgs) 40 | { 41 | var textSnapshot = view.TextSnapshot; 42 | Init(textSnapshot); 43 | } 44 | 45 | private void Init(ITextSnapshot textSnapshot) 46 | { 47 | IEnumerable methods = methodsExtractor.Extract(textSnapshot.GetText()) 48 | .Where(method => method.BodyEnd.Line >= 0); 49 | 50 | methodToText = methods.ToDictionary(method => method, method => GetText(textSnapshot, method)); 51 | } 52 | 53 | private string GetText(ITextSnapshot textSnapshot, IMethod method) 54 | { 55 | return textSnapshot.GetText(GetMethodSpan(method)); 56 | } 57 | 58 | private Span GetMethodSpan(IMethod method) 59 | { 60 | var startLine = view.TextSnapshot.GetLineFromLineNumber(method.BodyStart.Line); 61 | var endLine = view.TextSnapshot.GetLineFromLineNumber(method.BodyEnd.Line); 62 | 63 | int startPosition = startLine.Start.Position + method.BodyStart.Column; 64 | int endPosition = endLine.Start.Position + method.BodyEnd.Column; 65 | 66 | return Span.FromBounds(startPosition, endPosition); 67 | } 68 | 69 | private void OnLayoutChanged(object sender, TextViewLayoutChangedEventArgs e) 70 | { 71 | var isVisibleAreaChanged = IsVisibleAreaChanged(e); 72 | if (isVisibleAreaChanged && e.OldSnapshot != e.NewSnapshot) 73 | { 74 | return; 75 | } 76 | var textSnapshot = view.TextSnapshot; 77 | 78 | RepaintComplexity(textSnapshot); 79 | } 80 | 81 | private static bool IsVisibleAreaChanged(TextViewLayoutChangedEventArgs e) 82 | { 83 | ViewState newState = e.NewViewState; 84 | ViewState oldState = e.OldViewState; 85 | bool isVisibleAreaChanged = newState.ViewportBottom == oldState.ViewportBottom && 86 | newState.ViewportHeight == oldState.ViewportHeight && 87 | newState.ViewportLeft == oldState.ViewportLeft && 88 | newState.ViewportRight == oldState.ViewportRight && 89 | newState.ViewportTop == oldState.ViewportTop && 90 | newState.ViewportWidth == oldState.ViewportWidth; 91 | return isVisibleAreaChanged; 92 | } 93 | 94 | private void RepaintComplexity(ITextSnapshot textSnapshot) 95 | { 96 | IWpfTextViewLineCollection textViewLines = view.TextViewLines; 97 | 98 | if(textViewLines is null) 99 | { 100 | return; 101 | } 102 | 103 | layer.RemoveAllAdornments(); 104 | options.LoadSettingsFromStorage(); 105 | 106 | foreach (var pair in methodToText) 107 | { 108 | var geometry = textViewLines.GetMarkerGeometry(textSnapshot.GetLineFromLineNumber(pair.Key.Decleration.Line).Extent); 109 | var isMethodVisible = geometry != null; 110 | if (!isMethodVisible) 111 | { 112 | continue; 113 | } 114 | 115 | string methodText = methodToText[pair.Key]; 116 | 117 | var complexityViewModel = new ComplexityViewModel(options); 118 | var complexityView = new ComplexityView 119 | { 120 | DataContext = complexityViewModel 121 | }; 122 | new Task(() => complexityViewModel.UpdateComplexity(complexityCalculator.Calculate(methodText))).Start(); 123 | 124 | Canvas.SetLeft(complexityView, geometry.Bounds.Left); 125 | Canvas.SetTop(complexityView, geometry.Bounds.Top); 126 | 127 | layer.AddAdornment(AdornmentPositioningBehavior.ViewportRelative, null, null, complexityView, null); 128 | } 129 | } 130 | } 131 | } -------------------------------------------------------------------------------- /CodeMetrics.Adornments/CodeMetrics.Adornments.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Program 5 | C:\Program Files %28x86%29\Microsoft Visual Studio\2019\Community\Common7\IDE\devenv.exe 6 | /RootSuffix Exp 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | en-US 17 | false 18 | ProjectFiles 19 | 20 | 21 | Program 22 | C:\Program Files %28x86%29\Microsoft Visual Studio\2019\Community\Common7\IDE\devenv.exe 23 | /RootSuffix Exp 24 | 25 | 26 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/CodeMetricsPackage.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.Shell; 2 | using System.Runtime.InteropServices; 3 | using CodeMetrics.Options; 4 | using Microsoft.VisualStudio; 5 | 6 | namespace CodeMetrics 7 | { 8 | [PackageRegistration(UseManagedResourcesOnly = true)] 9 | [InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] 10 | [ProvideMenuResource("Menus.ctmenu", 1)] 11 | [Guid(GuidList.CodeMetricsPackage)] 12 | [ProvideOptionPage(typeof(GeneralOptionsPage), "Code Metrics", "General", 0, 0, true)] 13 | [ProvideProfileAttribute(typeof(GeneralOptionsPage), "Code Metrics", "General", 106, 107, true, DescriptionResourceID = 108)] 14 | [ProvideAutoLoad(VSConstants.UICONTEXT.NoSolution_string)] 15 | public class CodeMetricsPackage : Package 16 | { 17 | public static CodeMetricsPackage Instance { get; private set; } 18 | 19 | public CodeMetricsPackage() 20 | { 21 | Instance = this; 22 | } 23 | 24 | public GeneralOptionsPage GeneralOptions => (GeneralOptionsPage) GetDialogPage(typeof (GeneralOptionsPage)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/GuidList.cs: -------------------------------------------------------------------------------- 1 | namespace CodeMetrics 2 | { 3 | public class GuidList 4 | { 5 | public const string CodeMetricsPackage = "D1D827C4-B64D-437F-9F64-7554887CEC10"; 6 | public const string CodeMetricsOptionsPage = "4EA086D4-2AA3-4E13-A4B7-226BB712D096"; 7 | } 8 | } -------------------------------------------------------------------------------- /CodeMetrics.Adornments/Options/GeneralOptionsPage.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | using Microsoft.VisualStudio.Shell; 3 | using System.Runtime.InteropServices; 4 | using System.Windows.Forms; 5 | 6 | namespace CodeMetrics.Options 7 | { 8 | [Guid(GuidList.CodeMetricsOptionsPage)] 9 | public class GeneralOptionsPage : DialogPage 10 | { 11 | private readonly Options options = new Options(); 12 | 13 | public int Threshold 14 | { 15 | get 16 | { 17 | return this.options.MinimumToShow; 18 | } 19 | set 20 | { 21 | this.options.MinimumToShow = value; 22 | } 23 | } 24 | 25 | public Color GoodColor 26 | { 27 | get 28 | { 29 | return this.options.GoodColor; 30 | } 31 | set 32 | { 33 | this.options.GoodColor = value; 34 | } 35 | } 36 | 37 | public Color BadColor 38 | { 39 | get 40 | { 41 | return this.options.BadColor; 42 | } 43 | set 44 | { 45 | this.options.BadColor = value; 46 | } 47 | } 48 | 49 | protected override IWin32Window Window 50 | { 51 | get 52 | { 53 | var page = new GeneralOptionsPageContent(); 54 | page.OptionsPage = this; 55 | page.Initialize(); 56 | return page; 57 | } 58 | } 59 | 60 | public override void ResetSettings() 61 | { 62 | this.options.ResetSettings(); 63 | } 64 | 65 | public override void LoadSettingsFromStorage() 66 | { 67 | this.options.LoadSettingsFromStorage(); 68 | } 69 | 70 | public override void SaveSettingsToStorage() 71 | { 72 | this.options.SaveSettingsToStorage(); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/Options/GeneralOptionsPageContent.Designer.cs: -------------------------------------------------------------------------------- 1 | using CodeMetrics.UserControls; 2 | 3 | namespace CodeMetrics.Options 4 | { 5 | partial class GeneralOptionsPageContent 6 | { 7 | /// 8 | /// Required designer variable. 9 | /// 10 | private System.ComponentModel.IContainer components = null; 11 | 12 | /// 13 | /// Clean up any resources being used. 14 | /// 15 | /// true if managed resources should be disposed; otherwise, false. 16 | protected override void Dispose(bool disposing) 17 | { 18 | if (disposing && (components != null)) 19 | { 20 | components.Dispose(); 21 | } 22 | base.Dispose(disposing); 23 | } 24 | 25 | #region Component Designer generated code 26 | 27 | /// 28 | /// Required method for Designer support - do not modify 29 | /// the contents of this method with the code editor. 30 | /// 31 | private void InitializeComponent() 32 | { 33 | this.components = new System.ComponentModel.Container(); 34 | this.thresholdTextbox = new System.Windows.Forms.TextBox(); 35 | this.thresholdLabel = new System.Windows.Forms.Label(); 36 | this.mainToolTip = new System.Windows.Forms.ToolTip(this.components); 37 | this.minimumColorLabel = new System.Windows.Forms.Label(); 38 | this.minimumColorSelection = new CodeMetrics.Options.ColorSelection(); 39 | this.maximumColorLabel = new System.Windows.Forms.Label(); 40 | this.maximumColorSelection = new CodeMetrics.Options.ColorSelection(); 41 | this.thresholdErrorProvider = new System.Windows.Forms.ErrorProvider(this.components); 42 | ((System.ComponentModel.ISupportInitialize)(this.thresholdErrorProvider)).BeginInit(); 43 | this.SuspendLayout(); 44 | // 45 | // thresholdTextbox 46 | // 47 | this.thresholdTextbox.Location = new System.Drawing.Point(164, 31); 48 | this.thresholdTextbox.Name = "thresholdTextbox"; 49 | this.thresholdTextbox.Size = new System.Drawing.Size(48, 20); 50 | this.thresholdTextbox.TabIndex = 0; 51 | this.mainToolTip.SetToolTip(this.thresholdTextbox, "Define minum number of fomplexity to show.\r\nHas to be a number higher or equals t" + 52 | "han 1."); 53 | this.thresholdTextbox.TextChanged += new System.EventHandler(this.TextBoxTextChanged); 54 | // 55 | // thresholdLabel 56 | // 57 | this.thresholdLabel.AutoSize = true; 58 | this.thresholdLabel.Location = new System.Drawing.Point(14, 34); 59 | this.thresholdLabel.Name = "thresholdLabel"; 60 | this.thresholdLabel.Size = new System.Drawing.Size(144, 13); 61 | this.thresholdLabel.TabIndex = 1; 62 | this.thresholdLabel.Text = "Minimum Complexity to show:"; 63 | this.thresholdLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight; 64 | // 65 | // minimumColorLabel 66 | // 67 | this.minimumColorLabel.AutoSize = true; 68 | this.minimumColorLabel.Location = new System.Drawing.Point(43, 62); 69 | this.minimumColorLabel.Name = "minimumColorLabel"; 70 | this.minimumColorLabel.Size = new System.Drawing.Size(115, 13); 71 | this.minimumColorLabel.TabIndex = 2; 72 | this.minimumColorLabel.Text = "Good complexity Color:"; 73 | this.minimumColorLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight; 74 | // 75 | // minimumColorSelection 76 | // 77 | this.minimumColorSelection.Location = new System.Drawing.Point(164, 58); 78 | this.minimumColorSelection.Name = "minimumColorSelection"; 79 | this.minimumColorSelection.Size = new System.Drawing.Size(63, 24); 80 | this.minimumColorSelection.TabIndex = 3; 81 | this.minimumColorSelection.SelectedColorChanged += new System.EventHandler(this.MinimumColorSelection_SelectedColorChanged); 82 | // 83 | // maximumColorLabel 84 | // 85 | this.maximumColorLabel.AutoSize = true; 86 | this.maximumColorLabel.Location = new System.Drawing.Point(50, 93); 87 | this.maximumColorLabel.Name = "maximumColorLabel"; 88 | this.maximumColorLabel.Size = new System.Drawing.Size(108, 13); 89 | this.maximumColorLabel.TabIndex = 4; 90 | this.maximumColorLabel.Text = "Bad complexity Color:"; 91 | this.maximumColorLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight; 92 | // 93 | // maximumColorSelection 94 | // 95 | this.maximumColorSelection.Location = new System.Drawing.Point(164, 88); 96 | this.maximumColorSelection.Name = "maximumColorSelection"; 97 | this.maximumColorSelection.Size = new System.Drawing.Size(63, 24); 98 | this.maximumColorSelection.TabIndex = 5; 99 | this.maximumColorSelection.SelectedColorChanged += new System.EventHandler(this.MaximumColorSelection_SelectedColorChanged); 100 | // 101 | // thresholdErrorProvider 102 | // 103 | this.thresholdErrorProvider.ContainerControl = this; 104 | // 105 | // GeneralOptionsPageContent 106 | // 107 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 108 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 109 | this.Controls.Add(this.maximumColorSelection); 110 | this.Controls.Add(this.maximumColorLabel); 111 | this.Controls.Add(this.minimumColorSelection); 112 | this.Controls.Add(this.minimumColorLabel); 113 | this.Controls.Add(this.thresholdLabel); 114 | this.Controls.Add(this.thresholdTextbox); 115 | this.Name = "GeneralOptionsPageContent"; 116 | this.Size = new System.Drawing.Size(688, 350); 117 | ((System.ComponentModel.ISupportInitialize)(this.thresholdErrorProvider)).EndInit(); 118 | this.ResumeLayout(false); 119 | this.PerformLayout(); 120 | 121 | } 122 | 123 | #endregion 124 | 125 | private System.Windows.Forms.TextBox thresholdTextbox; 126 | private System.Windows.Forms.ToolTip mainToolTip; 127 | private System.Windows.Forms.Label thresholdLabel; 128 | private System.Windows.Forms.Label minimumColorLabel; 129 | private ColorSelection minimumColorSelection; 130 | private System.Windows.Forms.Label maximumColorLabel; 131 | private ColorSelection maximumColorSelection; 132 | private System.Windows.Forms.ErrorProvider thresholdErrorProvider; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/Options/GeneralOptionsPageContent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Forms; 4 | using CodeMetrics.UserControls; 5 | 6 | namespace CodeMetrics.Options 7 | { 8 | public partial class GeneralOptionsPageContent : UserControl 9 | { 10 | internal GeneralOptionsPage OptionsPage { get; set; } 11 | 12 | public GeneralOptionsPageContent() 13 | { 14 | InitializeComponent(); 15 | } 16 | 17 | public void Initialize() 18 | { 19 | this.thresholdTextbox.Text = this.OptionsPage.Threshold.ToString(CultureInfo.InvariantCulture); 20 | this.minimumColorSelection.SelectedColor = this.OptionsPage.GoodColor; 21 | this.maximumColorSelection.SelectedColor = this.OptionsPage.BadColor; 22 | } 23 | 24 | private void TextBoxTextChanged(object sender, EventArgs e) 25 | { 26 | int newValue = 1; 27 | if (int.TryParse(this.thresholdTextbox.Text, out newValue)) 28 | { 29 | this.OptionsPage.Threshold = newValue; 30 | this.thresholdErrorProvider.SetError(this.thresholdTextbox, string.Empty); 31 | } 32 | else 33 | { 34 | this.thresholdErrorProvider.SetError(this.thresholdTextbox, Properties.Resources.ThresholdErrorMessage); 35 | } 36 | } 37 | 38 | private void MinimumColorSelection_SelectedColorChanged(object sender, ColorChangedEventArgs e) 39 | { 40 | this.OptionsPage.GoodColor = e.NewColor; 41 | } 42 | 43 | private void MaximumColorSelection_SelectedColorChanged(object sender, ColorChangedEventArgs e) 44 | { 45 | this.OptionsPage.BadColor = e.NewColor; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/Options/GeneralOptionsPageContent.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | 124 | 17, 17 125 | 126 | 127 | 136, 17 128 | 129 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/Options/IOptions.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | 3 | namespace CodeMetrics.Options 4 | { 5 | public interface IOptions 6 | { 7 | int MinimumToShow { get; set; } 8 | 9 | Color GoodColor { get; set; } 10 | 11 | Color BadColor { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /CodeMetrics.Adornments/Options/Options.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | using Microsoft.VisualStudio.Settings; 3 | using Microsoft.VisualStudio.Shell; 4 | using Microsoft.VisualStudio.Shell.Settings; 5 | 6 | namespace CodeMetrics.Options 7 | { 8 | internal class Options : IOptions 9 | { 10 | private const string SettingsCollectionName = "Code Metrics"; 11 | 12 | private const string MinimumToShowName = "MinimumToShow"; 13 | private const string GoodColorName = "GoodColor"; 14 | private const string BadColorName = "BadColor"; 15 | 16 | public static readonly string DefaultGoodColor = ColorTranslator.ToHtml(Color.DarkGreen); 17 | public static readonly string DefaultBadColor = ColorTranslator.ToHtml(Color.Red); 18 | 19 | private const int DefaultToShow = 1; 20 | 21 | private ShellSettingsManager settingsManager; 22 | 23 | private readonly WritableSettingsStore userSettingsStore; 24 | 25 | public int MinimumToShow { get; set; } 26 | 27 | public Color GoodColor { get; set; } 28 | 29 | public Color BadColor { get; set; } 30 | 31 | public Options() 32 | { 33 | settingsManager = new ShellSettingsManager(ServiceProvider.GlobalProvider); 34 | userSettingsStore = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings); 35 | } 36 | 37 | internal void ResetSettings() 38 | { 39 | userSettingsStore.SetInt32(SettingsCollectionName, MinimumToShowName, DefaultToShow); 40 | userSettingsStore.SetString(SettingsCollectionName, GoodColorName, DefaultGoodColor); 41 | userSettingsStore.SetString(SettingsCollectionName, BadColorName, DefaultBadColor); 42 | } 43 | 44 | internal void LoadSettingsFromStorage() 45 | { 46 | var installed = userSettingsStore.CollectionExists(SettingsCollectionName); 47 | if (!installed) 48 | { 49 | userSettingsStore.CreateCollection(SettingsCollectionName); 50 | ResetSettings(); 51 | } 52 | 53 | this.MinimumToShow = userSettingsStore.GetInt32(SettingsCollectionName, MinimumToShowName, DefaultToShow); 54 | this.GoodColor = this.ResolveSettingsColor(GoodColorName, DefaultGoodColor); 55 | this.BadColor = this.ResolveSettingsColor(BadColorName, DefaultBadColor); 56 | } 57 | 58 | private Color ResolveSettingsColor(string minimumColorName, string defaultColor) 59 | { 60 | string minimumColor = this.userSettingsStore.GetString(SettingsCollectionName, minimumColorName, defaultColor); 61 | return ColorTranslator.FromHtml(minimumColor); 62 | } 63 | 64 | internal void SaveSettingsToStorage() 65 | { 66 | userSettingsStore.SetInt32(SettingsCollectionName, MinimumToShowName, this.MinimumToShow); 67 | this.SaveColor(this.GoodColor, GoodColorName); 68 | this.SaveColor(this.BadColor, BadColorName); 69 | } 70 | 71 | private void SaveColor(Color newColor, string settingKey) 72 | { 73 | var newMinColor = ColorTranslator.ToHtml(newColor); 74 | this.userSettingsStore.SetString(SettingsCollectionName, settingKey, newMinColor); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/Options/Resources/SettingsStorageCommand.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/CodeMetrics.Adornments/Options/Resources/SettingsStorageCommand.png -------------------------------------------------------------------------------- /CodeMetrics.Adornments/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | [assembly: AssemblyTitle("CodeMetrics.Adornments")] 5 | [assembly: InternalsVisibleTo("CodeMetrics.Adornments.Tests")] -------------------------------------------------------------------------------- /CodeMetrics.Adornments/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace CodeMetrics.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CodeMetrics.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized string similar to Minimum Complexity has to be a number higher or equals 1.. 65 | /// 66 | internal static string ThresholdErrorMessage { 67 | get { 68 | return ResourceManager.GetString("ThresholdErrorMessage", resourceCulture); 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | Minimum Complexity has to be a number higher or equals 1. 122 | 123 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/UserControls/ColorChangedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | 4 | namespace CodeMetrics.Options 5 | { 6 | internal class ColorChangedEventArgs : EventArgs 7 | { 8 | public Color NewColor { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /CodeMetrics.Adornments/UserControls/ColorSelection.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace CodeMetrics.Options 2 | { 3 | partial class ColorSelection 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Component Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.editButton = new System.Windows.Forms.Button(); 32 | this.previewPanel = new System.Windows.Forms.Panel(); 33 | this.rangeColorDialog = new System.Windows.Forms.ColorDialog(); 34 | this.SuspendLayout(); 35 | // 36 | // editButton 37 | // 38 | this.editButton.Location = new System.Drawing.Point(35, 0); 39 | this.editButton.Name = "editButton"; 40 | this.editButton.Size = new System.Drawing.Size(27, 23); 41 | this.editButton.TabIndex = 4; 42 | this.editButton.Text = "..."; 43 | this.editButton.UseVisualStyleBackColor = true; 44 | this.editButton.Click += new System.EventHandler(this.ChangeColorButtonClick); 45 | // 46 | // previewPanel 47 | // 48 | this.previewPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; 49 | this.previewPanel.Location = new System.Drawing.Point(0, 0); 50 | this.previewPanel.Name = "previewPanel"; 51 | this.previewPanel.Size = new System.Drawing.Size(30, 23); 52 | this.previewPanel.TabIndex = 5; 53 | this.previewPanel.DoubleClick += new System.EventHandler(this.ChangeColorButtonClick); 54 | // 55 | // ColorSelection 56 | // 57 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 58 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 59 | this.Controls.Add(this.editButton); 60 | this.Controls.Add(this.previewPanel); 61 | this.Name = "ColorSelection"; 62 | this.Size = new System.Drawing.Size(64, 23); 63 | this.ResumeLayout(false); 64 | 65 | } 66 | 67 | #endregion 68 | 69 | private System.Windows.Forms.Button editButton; 70 | private System.Windows.Forms.Panel previewPanel; 71 | private System.Windows.Forms.ColorDialog rangeColorDialog; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/UserControls/ColorSelection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Windows.Forms; 4 | 5 | namespace CodeMetrics.Options 6 | { 7 | internal partial class ColorSelection : UserControl 8 | { 9 | public event EventHandler SelectedColorChanged; 10 | 11 | internal Color SelectedColor 12 | { 13 | get 14 | { 15 | return this.previewPanel.BackColor; 16 | } 17 | set 18 | { 19 | this.previewPanel.BackColor = value; 20 | } 21 | } 22 | 23 | public ColorSelection() 24 | { 25 | InitializeComponent(); 26 | } 27 | 28 | private void ChangeColorButtonClick(object sender, EventArgs e) 29 | { 30 | this.rangeColorDialog.Color = this.SelectedColor; 31 | 32 | if (this.rangeColorDialog.ShowDialog() == DialogResult.OK) 33 | { 34 | this.SelectedColor = this.rangeColorDialog.Color; 35 | FireColorChanged(); 36 | } 37 | } 38 | 39 | private void FireColorChanged() 40 | { 41 | if (SelectedColorChanged != null) 42 | { 43 | var args = new ColorChangedEventArgs() { NewColor = this.SelectedColor }; 44 | SelectedColorChanged(this, args); 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/UserControls/ColorSelection.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/UserControls/ComplexityView.xaml: -------------------------------------------------------------------------------- 1 |  8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/UserControls/ComplexityView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls; 2 | 3 | namespace CodeMetrics.UserControls 4 | { 5 | /// 6 | /// Interaction logic for ComplexityView.xaml 7 | /// 8 | public partial class ComplexityView : UserControl 9 | { 10 | public ComplexityView() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/UserControls/ComplexityViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Globalization; 3 | using System.Windows.Media; 4 | using CodeMetrics.Adornments; 5 | using CodeMetrics.Calculators; 6 | using CodeMetrics.Options; 7 | 8 | namespace CodeMetrics.UserControls 9 | { 10 | internal class ComplexityViewModel : INotifyPropertyChanged 11 | { 12 | private readonly IOptions options; 13 | 14 | public event PropertyChangedEventHandler PropertyChanged; 15 | 16 | private IComplexity complexity; 17 | 18 | private readonly ComplexityToColor converter; 19 | 20 | public int Value { get { return this.complexity == null ? 0 : this.complexity.Value; } } 21 | 22 | public Color Color 23 | { 24 | get 25 | { 26 | return this.converter.Convert(this.Value); 27 | } 28 | } 29 | 30 | public bool Visible 31 | { 32 | get 33 | { 34 | return this.options.MinimumToShow <= Value; 35 | } 36 | } 37 | 38 | public ComplexityViewModel(IOptions options) 39 | { 40 | this.options = options; 41 | this.converter = new ComplexityToColor(options); 42 | } 43 | 44 | public void InvokePropertyChanged(PropertyChangedEventArgs e) 45 | { 46 | if (PropertyChanged != null) 47 | { 48 | PropertyChanged(this, e); 49 | } 50 | } 51 | 52 | public void UpdateComplexity(IComplexity complexity) 53 | { 54 | this.complexity = complexity; 55 | InvokePropertyChanged(new PropertyChangedEventArgs(null)); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/VSPackage.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace CodeMetrics { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class VSPackage { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal VSPackage() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CodeMetrics.VSPackage", typeof(VSPackage).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized string similar to Code Metrics. 65 | /// 66 | internal static string _106 { 67 | get { 68 | return ResourceManager.GetString("106", resourceCulture); 69 | } 70 | } 71 | 72 | /// 73 | /// Looks up a localized string similar to General Settings. 74 | /// 75 | internal static string _107 { 76 | get { 77 | return ResourceManager.GetString("107", resourceCulture); 78 | } 79 | } 80 | 81 | /// 82 | /// Looks up a localized string similar to Code Metrics General Settings. 83 | /// 84 | internal static string _108 { 85 | get { 86 | return ResourceManager.GetString("108", resourceCulture); 87 | } 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/VSPackage.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | Code Metrics 122 | 123 | 124 | Code Metrics 125 | 126 | 127 | Code Metrics General Settings 128 | 129 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /CodeMetrics.Adornments/source.extension.vsixmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Code Metrices 6 | Code complexity addin 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /CodeMetrics.Calculators/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /CodeMetrics.Calculators/BranchesVisitor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using CodeMetrics.Parsing; 4 | using ICSharpCode.NRefactory.CSharp; 5 | using ICSharpCode.NRefactory.PatternMatching; 6 | 7 | namespace CodeMetrics.Calculators 8 | { 9 | 10 | 11 | public class BranchesVisitor : DepthFirstAstVisitor, IBranchesVisitor 12 | { 13 | private readonly Dictionary declarationsDictionary = new Dictionary(); 14 | 15 | public int BranchesCounter { get; protected set; } 16 | 17 | public override void VisitTryCatchStatement(TryCatchStatement tryCatchStatement) 18 | { 19 | base.VisitTryCatchStatement(tryCatchStatement); 20 | BranchesCounter++; 21 | } 22 | 23 | public override void VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression) 24 | { 25 | base.VisitBinaryOperatorExpression(binaryOperatorExpression); 26 | 27 | if(binaryOperatorExpression.Operator == BinaryOperatorType.NullCoalescing) 28 | { 29 | BranchesCounter += 2; 30 | } 31 | } 32 | 33 | public override void VisitConditionalExpression(ConditionalExpression conditionalExpression) 34 | { 35 | base.VisitConditionalExpression(conditionalExpression); 36 | BranchesCounter += 2; 37 | } 38 | 39 | public override void VisitIfElseStatement(IfElseStatement ifElseStatement) 40 | { 41 | base.VisitIfElseStatement(ifElseStatement); 42 | 43 | BranchesCounter++; 44 | 45 | if (!ifElseStatement.FalseStatement.IsNull) 46 | { 47 | BranchesCounter++; 48 | } 49 | 50 | var conditionComplexity = GetConditionComplexity(ifElseStatement.Condition); 51 | BranchesCounter += conditionComplexity; 52 | } 53 | 54 | private int GetConditionComplexity(Expression condition) 55 | { 56 | var branchesVisitorImpl = new ConditionVisitor(declarationsDictionary); 57 | condition.AcceptVisitor(branchesVisitorImpl); 58 | 59 | return branchesVisitorImpl.BranchesCounter; 60 | } 61 | 62 | public override void VisitForStatement(ForStatement forStatement) 63 | { 64 | base.VisitForStatement(forStatement); 65 | 66 | BranchesCounter++; 67 | var conditionComplexity = GetConditionComplexity(forStatement.Condition); 68 | BranchesCounter += conditionComplexity; 69 | } 70 | 71 | public override void VisitForeachStatement(ForeachStatement foreachStatement) 72 | { 73 | base.VisitForeachStatement(foreachStatement); 74 | 75 | BranchesCounter++; 76 | } 77 | 78 | 79 | public override void VisitWhileStatement(WhileStatement whileStatement) 80 | { 81 | base.VisitWhileStatement(whileStatement); 82 | 83 | BranchesCounter++; 84 | 85 | var conditionComplexity = GetConditionComplexity(whileStatement.Condition); 86 | BranchesCounter += conditionComplexity; 87 | } 88 | 89 | public override void VisitDoWhileStatement(DoWhileStatement doLoopStatement) 90 | { 91 | base.VisitDoWhileStatement(doLoopStatement); 92 | 93 | BranchesCounter++; 94 | var conditionComplexity = GetConditionComplexity(doLoopStatement.Condition); 95 | BranchesCounter += conditionComplexity; 96 | } 97 | 98 | public override void VisitSwitchSection(SwitchSection switchSection) 99 | { 100 | base.VisitSwitchSection(switchSection); 101 | 102 | if (!IsDefaultCase(switchSection)) 103 | { 104 | BranchesCounter++; 105 | } 106 | } 107 | 108 | public override void VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement) 109 | { 110 | base.VisitVariableDeclarationStatement(variableDeclarationStatement); 111 | 112 | if (isDeclaringCondition(variableDeclarationStatement)) 113 | { 114 | foreach (var variable in variableDeclarationStatement.Variables) 115 | { 116 | declarationsDictionary[variable.Name] = variable.Initializer; 117 | } 118 | } 119 | } 120 | 121 | private static bool isDeclaringCondition(VariableDeclarationStatement variableDeclarationStatement) 122 | { 123 | var conditionalAndPattern = new VariableDeclarationStatement 124 | { 125 | Type = new AnyNode(), 126 | Variables = 127 | { 128 | new VariableInitializer 129 | { 130 | Name = Pattern.AnyString, 131 | Initializer = new BinaryOperatorExpression 132 | { 133 | Left = new AnyNode(), 134 | Operator = BinaryOperatorType.ConditionalAnd, 135 | Right = new AnyNode() 136 | } 137 | } 138 | } 139 | }; 140 | 141 | var conditionalOrPattern = new VariableDeclarationStatement 142 | { 143 | Type = new AnyNode(), 144 | Variables = 145 | { 146 | new VariableInitializer 147 | { 148 | Name = Pattern.AnyString, 149 | Initializer = new BinaryOperatorExpression 150 | { 151 | Left = new AnyNode(), 152 | Operator = BinaryOperatorType.ConditionalOr, 153 | Right = new AnyNode() 154 | } 155 | } 156 | } 157 | }; 158 | 159 | return conditionalAndPattern.IsMatch(variableDeclarationStatement) || 160 | conditionalOrPattern.IsMatch(variableDeclarationStatement); 161 | } 162 | 163 | private static bool IsDefaultCase(SwitchSection switchSection) 164 | { 165 | CaseLabel firstCaseLabel = switchSection.CaseLabels.FirstOrNullObject(); 166 | return firstCaseLabel.Expression.IsNull; 167 | } 168 | } 169 | } -------------------------------------------------------------------------------- /CodeMetrics.Calculators/CodeMetrics.Calculators.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {CF35E234-7831-4A2B-8F18-BBB0F8621B10} 9 | Library 10 | Properties 11 | CodeMetrics.Calculators 12 | CodeMetrics.Calculators 13 | v4.6.1 14 | 512 15 | 16 | ..\ 17 | true 18 | 19 | 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | false 28 | false 29 | 30 | 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | false 38 | 39 | 40 | false 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | ..\packages\ICSharpCode.NRefactory.5.5.1\lib\Net40\ICSharpCode.NRefactory.dll 49 | True 50 | 51 | 52 | ..\packages\ICSharpCode.NRefactory.5.5.1\lib\Net40\ICSharpCode.NRefactory.Cecil.dll 53 | True 54 | 55 | 56 | ..\packages\ICSharpCode.NRefactory.5.5.1\lib\Net40\ICSharpCode.NRefactory.CSharp.dll 57 | True 58 | 59 | 60 | ..\packages\ICSharpCode.NRefactory.5.5.1\lib\Net40\ICSharpCode.NRefactory.Xml.dll 61 | True 62 | 63 | 64 | ..\packages\Mono.Cecil.0.9.6.1\lib\net40\Mono.Cecil.dll 65 | True 66 | 67 | 68 | ..\packages\Mono.Cecil.0.9.6.1\lib\net40\Mono.Cecil.Mdb.dll 69 | True 70 | 71 | 72 | ..\packages\Mono.Cecil.0.9.6.1\lib\net40\Mono.Cecil.Pdb.dll 73 | True 74 | 75 | 76 | ..\packages\Mono.Cecil.0.9.6.1\lib\net40\Mono.Cecil.Rocks.dll 77 | True 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | VersionInfo.cs 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | {4F281F92-DFF0-44DF-A150-A95DC83D727D} 101 | CodeMetrics.Parsing 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 113 | 114 | 115 | 116 | 123 | -------------------------------------------------------------------------------- /CodeMetrics.Calculators/Complexity.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace CodeMetrics.Calculators 4 | { 5 | public class Complexity : IComplexity, INotifyPropertyChanged 6 | { 7 | private int value; 8 | public int Value 9 | { 10 | get { return value; } 11 | set 12 | { 13 | this.value = value; 14 | PropertyChanged(this, new PropertyChangedEventArgs("Value")); 15 | } 16 | } 17 | 18 | public Complexity(int value) 19 | { 20 | Value = value; 21 | } 22 | 23 | public event PropertyChangedEventHandler PropertyChanged = (sender, args) => { }; 24 | 25 | public override string ToString() 26 | { 27 | return string.Format("Complexity:{0}", value); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /CodeMetrics.Calculators/ComplexityCalculator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using CodeMetrics.Parsing; 4 | using ICSharpCode.NRefactory.CSharp; 5 | 6 | namespace CodeMetrics.Calculators 7 | { 8 | public class ComplexityCalculator : IComplexityCalculator 9 | { 10 | private readonly IBranchesVisitorFactory methodsVisitorFactory; 11 | 12 | public ComplexityCalculator(IBranchesVisitorFactory methodsVisitorFactory) 13 | { 14 | this.methodsVisitorFactory = methodsVisitorFactory; 15 | } 16 | 17 | public IComplexity Calculate(string method) 18 | { 19 | try 20 | { 21 | return TryCalculate(method); 22 | } 23 | catch (NullReferenceException) 24 | { 25 | return new Complexity(1); 26 | } 27 | } 28 | 29 | private IComplexity TryCalculate(string method) 30 | { 31 | IEnumerable blockStatement = ParseStatements(method); 32 | var visitor = methodsVisitorFactory.CreateBranchesVisitor(); 33 | AcceptVisitors(blockStatement, visitor); 34 | return new Complexity(visitor.BranchesCounter + 1); 35 | } 36 | 37 | private static void AcceptVisitors(IEnumerable blockStatement, IBranchesVisitor visitor) 38 | { 39 | foreach (var statement in blockStatement) 40 | { 41 | statement.AcceptVisitor(visitor); 42 | } 43 | } 44 | 45 | private static IEnumerable ParseStatements(string method) 46 | { 47 | var parser = new CSharpParser(); 48 | return parser.ParseStatements(method); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /CodeMetrics.Calculators/ConditionVisitor.cs: -------------------------------------------------------------------------------- 1 | using CodeMetrics.Parsing; 2 | using ICSharpCode.NRefactory.CSharp; 3 | 4 | namespace CodeMetrics.Calculators 5 | { 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | 9 | public class ConditionVisitor : DepthFirstAstVisitor, IBranchesVisitor 10 | { 11 | public int BranchesCounter { get; private set; } 12 | 13 | private IDictionary declerationsDictionary; 14 | 15 | public ConditionVisitor(IDictionary dictionary = null) 16 | { 17 | declerationsDictionary = dictionary ?? new Dictionary(); 18 | } 19 | 20 | public override void VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression) 21 | { 22 | base.VisitBinaryOperatorExpression(binaryOperatorExpression); 23 | 24 | if (binaryOperatorExpression.Operator == BinaryOperatorType.ConditionalAnd || binaryOperatorExpression.Operator == BinaryOperatorType.ConditionalOr) 25 | { 26 | BranchesCounter++; 27 | } 28 | } 29 | 30 | public override void VisitIdentifier(Identifier identifier) 31 | { 32 | base.VisitIdentifier(identifier); 33 | 34 | if (declerationsDictionary.ContainsKey(identifier.Name)) 35 | { 36 | declerationsDictionary[identifier.Name].AcceptVisitor(this); 37 | } 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /CodeMetrics.Calculators/IComplexity.cs: -------------------------------------------------------------------------------- 1 | namespace CodeMetrics.Calculators 2 | { 3 | public interface IComplexity 4 | { 5 | int Value { get; } 6 | } 7 | } -------------------------------------------------------------------------------- /CodeMetrics.Calculators/IComplexityCalculator.cs: -------------------------------------------------------------------------------- 1 | namespace CodeMetrics.Calculators 2 | { 3 | public interface IComplexityCalculator 4 | { 5 | IComplexity Calculate(string method); 6 | } 7 | } -------------------------------------------------------------------------------- /CodeMetrics.Calculators/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | [assembly: AssemblyTitle("CodeMetrics.Calculators")] -------------------------------------------------------------------------------- /CodeMetrics.Calculators/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /CodeMetrics.Common/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /CodeMetrics.Common/ContainerFactory.cs: -------------------------------------------------------------------------------- 1 | using Castle.Windsor; 2 | using Castle.Windsor.Installer; 3 | 4 | namespace CodeMetrics.Common 5 | { 6 | public class ContainerFactory 7 | { 8 | public static WindsorContainer CreateContainer() 9 | { 10 | var container = new WindsorContainer(); 11 | container.Install(new RepositoriesInstaller()); 12 | return container; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /CodeMetrics.Common/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | [assembly: AssemblyTitle("CodeMetrics.Common")] -------------------------------------------------------------------------------- /CodeMetrics.Common/RepositoriesInstaller.cs: -------------------------------------------------------------------------------- 1 | using Castle.Facilities.TypedFactory; 2 | using Castle.MicroKernel.Registration; 3 | using Castle.MicroKernel.SubSystems.Configuration; 4 | using Castle.Windsor; 5 | using CodeMetrics.Calculators; 6 | using CodeMetrics.Parsing; 7 | 8 | namespace CodeMetrics.Common 9 | { 10 | public class RepositoriesInstaller : IWindsorInstaller 11 | { 12 | public void Install(IWindsorContainer container, IConfigurationStore store) 13 | { 14 | container.AddFacility(); 15 | container.Register(Component.For().AsFactory()); 16 | container.Register(Component.For().AsFactory()); 17 | 18 | container.Register(Component.For().ImplementedBy().LifeStyle.Transient); 19 | container.Register(Component.For().ImplementedBy().LifeStyle.Transient); 20 | 21 | var parsingAssembly = typeof(IMethodsExtractor).Assembly; 22 | var calculatorsAssembly = typeof(IComplexityCalculator).Assembly; 23 | container.Register(Classes.FromAssembly(parsingAssembly).Pick().WithServiceDefaultInterfaces()); 24 | container.Register(Classes.FromAssembly(calculatorsAssembly).Pick().WithServiceDefaultInterfaces()); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /CodeMetrics.Common/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CodeMetrics.DataTransferObjects/CodeMetrics.DataTransferObjects.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {BC25CBE0-AE56-4174-918E-F54CA39F56C5} 9 | Library 10 | Properties 11 | CodeMetrics.DataTransferObjects 12 | CodeMetrics.DataTransferObjects 13 | v3.5 14 | 512 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 54 | -------------------------------------------------------------------------------- /CodeMetrics.DataTransferObjects/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("CodeMetrics.DataTransferObjects")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("CodeMetrics.DataTransferObjects")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("578bfc09-c318-49cd-baa2-f64268589d0a")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /CodeMetrics.DataTransferObjects/TaskRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace CodeMetrics.DataTransferObjects 5 | { 6 | [DataContract] 7 | public class TaskRequest 8 | { 9 | [DataMember] 10 | public Guid ID { get; set; } 11 | 12 | [DataMember] 13 | public string MethodBody { get; set; } 14 | } 15 | 16 | [DataContract] 17 | public class TaskResult 18 | { 19 | [DataMember] 20 | public Guid ID { get; set; } 21 | 22 | [DataMember] 23 | public int ComplexityValue { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /CodeMetrics.Parsing/CodeMetrics.Parsing.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {4F281F92-DFF0-44DF-A150-A95DC83D727D} 9 | Library 10 | Properties 11 | CodeMetrics.Parsing 12 | CodeMetrics.Parsing 13 | v4.6.1 14 | 512 15 | ..\ 16 | true 17 | 18 | 19 | 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | false 28 | 29 | 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | false 37 | 38 | 39 | false 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | ..\packages\ICSharpCode.NRefactory.5.5.1\lib\Net40\ICSharpCode.NRefactory.dll 48 | True 49 | 50 | 51 | ..\packages\ICSharpCode.NRefactory.5.5.1\lib\Net40\ICSharpCode.NRefactory.Cecil.dll 52 | True 53 | 54 | 55 | ..\packages\ICSharpCode.NRefactory.5.5.1\lib\Net40\ICSharpCode.NRefactory.CSharp.dll 56 | True 57 | 58 | 59 | ..\packages\ICSharpCode.NRefactory.5.5.1\lib\Net40\ICSharpCode.NRefactory.Xml.dll 60 | True 61 | 62 | 63 | ..\packages\Mono.Cecil.0.9.6.1\lib\net40\Mono.Cecil.dll 64 | True 65 | 66 | 67 | ..\packages\Mono.Cecil.0.9.6.1\lib\net40\Mono.Cecil.Mdb.dll 68 | True 69 | 70 | 71 | ..\packages\Mono.Cecil.0.9.6.1\lib\net40\Mono.Cecil.Pdb.dll 72 | True 73 | 74 | 75 | ..\packages\Mono.Cecil.0.9.6.1\lib\net40\Mono.Cecil.Rocks.dll 76 | True 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | VersionInfo.cs 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 110 | 111 | 112 | 113 | 120 | -------------------------------------------------------------------------------- /CodeMetrics.Parsing/ConstructorsVisitor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ICSharpCode.NRefactory.CSharp; 3 | 4 | namespace CodeMetrics.Parsing 5 | { 6 | public class ConstructorsVisitor : DepthFirstAstVisitor, IMethodsVisitor 7 | { 8 | private readonly List constructors; 9 | 10 | public ConstructorsVisitor() 11 | { 12 | constructors = new List(); 13 | } 14 | 15 | public IEnumerable Methods 16 | { 17 | get { return constructors; } 18 | } 19 | 20 | public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) 21 | { 22 | base.VisitConstructorDeclaration(constructorDeclaration); 23 | 24 | var declarationLocation = constructorDeclaration.StartLocation.AsLocation(); 25 | var bodyStartLocation = constructorDeclaration.Body.StartLocation.AsLocation(); 26 | var bodyEndLocation = constructorDeclaration.Body.EndLocation.AsLocation(); 27 | constructors.Add(new Method(declarationLocation, bodyStartLocation, bodyEndLocation)); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /CodeMetrics.Parsing/IBranchesVisitor.cs: -------------------------------------------------------------------------------- 1 | using ICSharpCode.NRefactory; 2 | using ICSharpCode.NRefactory.CSharp; 3 | 4 | namespace CodeMetrics.Parsing 5 | { 6 | public interface IBranchesVisitor : IAstVisitor 7 | { 8 | int BranchesCounter { get; } 9 | } 10 | } -------------------------------------------------------------------------------- /CodeMetrics.Parsing/IMethod.cs: -------------------------------------------------------------------------------- 1 | namespace CodeMetrics.Parsing 2 | { 3 | public interface IMethod 4 | { 5 | Location Decleration { get; } 6 | Location BodyStart { get; } 7 | Location BodyEnd { get; } 8 | } 9 | } -------------------------------------------------------------------------------- /CodeMetrics.Parsing/IMethodsExtractor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CodeMetrics.Parsing 4 | { 5 | public interface IMethodsExtractor 6 | { 7 | IEnumerable Extract(string fileCode); 8 | } 9 | } -------------------------------------------------------------------------------- /CodeMetrics.Parsing/IMethodsVisitor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ICSharpCode.NRefactory.CSharp; 3 | 4 | namespace CodeMetrics.Parsing 5 | { 6 | public interface IMethodsVisitor : IAstVisitor 7 | { 8 | IEnumerable Methods { get; } 9 | } 10 | } -------------------------------------------------------------------------------- /CodeMetrics.Parsing/IMethodsVisitorFactory.cs: -------------------------------------------------------------------------------- 1 | namespace CodeMetrics.Parsing 2 | { 3 | public interface IBranchesVisitorFactory 4 | { 5 | IBranchesVisitor CreateBranchesVisitor(); 6 | } 7 | 8 | public interface IMethodsVisitorFactory 9 | { 10 | IMethodsVisitor CreateMethodsVisitor(); 11 | } 12 | } -------------------------------------------------------------------------------- /CodeMetrics.Parsing/Location.cs: -------------------------------------------------------------------------------- 1 | namespace CodeMetrics.Parsing 2 | { 3 | public class Location 4 | { 5 | public int Line { get; private set; } 6 | public int Column { get; private set; } 7 | 8 | public Location(int line, int column) 9 | { 10 | Line = line; 11 | Column = column; 12 | } 13 | 14 | public override string ToString() 15 | { 16 | return string.Format("Location:{0},{1}", Line, Column); 17 | } 18 | 19 | internal string ToShortString() 20 | { 21 | return string.Format("{0},{1}", Line, Column); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /CodeMetrics.Parsing/Method.cs: -------------------------------------------------------------------------------- 1 | namespace CodeMetrics.Parsing 2 | { 3 | public class Method : IMethod 4 | { 5 | public Method(Location methodDeclaration, Location bodyStart, Location bodyEnd) 6 | { 7 | Decleration = methodDeclaration; 8 | BodyStart = bodyStart; 9 | BodyEnd = bodyEnd; 10 | } 11 | 12 | public Location Decleration { get; private set; } 13 | public Location BodyStart { get; private set; } 14 | public Location BodyEnd { get; private set; } 15 | 16 | public override string ToString() 17 | { 18 | string declaration = Decleration.ToShortString(); 19 | string bodyStart = BodyStart.ToShortString(); 20 | string bodyEnd = BodyEnd.ToShortString(); 21 | return string.Format("Method:[{0}-{1}-{2}]",declaration, bodyStart, bodyEnd); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /CodeMetrics.Parsing/MethodsExtractor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using ICSharpCode.NRefactory.CSharp; 4 | 5 | namespace CodeMetrics.Parsing 6 | { 7 | public class MethodsExtractor : IMethodsExtractor 8 | { 9 | private readonly IMethodsVisitorFactory visitorsFactory; 10 | 11 | public MethodsExtractor(IMethodsVisitorFactory visitorsFactory) 12 | { 13 | this.visitorsFactory = visitorsFactory; 14 | } 15 | 16 | public IEnumerable Extract(string fileCode) 17 | { 18 | var parser = new CSharpParser(); 19 | SyntaxTree syntaxTree = parser.Parse(new StringReader(fileCode)); 20 | 21 | IMethodsVisitor methodsVisitor = visitorsFactory.CreateMethodsVisitor(); 22 | syntaxTree.AcceptVisitor(methodsVisitor); 23 | return methodsVisitor.Methods; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /CodeMetrics.Parsing/MethodsVisitor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ICSharpCode.NRefactory.CSharp; 3 | 4 | namespace CodeMetrics.Parsing 5 | { 6 | public class MethodsVisitor : DepthFirstAstVisitor, IMethodsVisitor 7 | { 8 | private readonly List methods = new List(); 9 | 10 | public IEnumerable Methods 11 | { 12 | get { return methods; } 13 | } 14 | 15 | public override void VisitMethodDeclaration(MethodDeclaration methodDeclaration) 16 | { 17 | base.VisitMethodDeclaration(methodDeclaration); 18 | 19 | AddMethod(methodDeclaration, methodDeclaration.Body); 20 | } 21 | 22 | public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) 23 | { 24 | base.VisitConstructorDeclaration(constructorDeclaration); 25 | 26 | AddMethod(constructorDeclaration, constructorDeclaration.Body); 27 | } 28 | 29 | public override void VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration) 30 | { 31 | base.VisitPropertyDeclaration(propertyDeclaration); 32 | 33 | AddAccessorMethod(propertyDeclaration.Getter); 34 | AddAccessorMethod(propertyDeclaration.Setter); 35 | } 36 | 37 | private void AddMethod(EntityDeclaration methodDeclaration, BlockStatement body) 38 | { 39 | if (body.IsNull) 40 | { 41 | return; 42 | } 43 | 44 | var declarationLocation = methodDeclaration.StartLocation.AsLocation(); 45 | var bodyStartLocation = body.StartLocation.AsLocation(); 46 | var bodyEndLocation = body.EndLocation.AsLocation(); 47 | methods.Add(new Method(declarationLocation, bodyStartLocation, bodyEndLocation)); 48 | } 49 | 50 | private void AddAccessorMethod(Accessor accessor) 51 | { 52 | AddMethod(accessor, accessor.Body); 53 | } 54 | 55 | } 56 | } -------------------------------------------------------------------------------- /CodeMetrics.Parsing/MethodsVisitorFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CodeMetrics.Parsing 4 | { 5 | public class MethodsVisitorFactory : IMethodsVisitorFactory 6 | { 7 | public IEnumerable CreateMethodsVisitor() 8 | { 9 | return new List() 10 | { 11 | new MethodsVisitor(), 12 | new ConstructorsVisitor(), 13 | new PropertyVisitor() 14 | }; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /CodeMetrics.Parsing/NRefactoryExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace CodeMetrics.Parsing 2 | { 3 | public static class NRefactoryExtensions 4 | { 5 | public static Location AsLocation(this ICSharpCode.NRefactory.TextLocation location) 6 | { 7 | return new Location(location.Line - 1, location.Column - 1); 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /CodeMetrics.Parsing/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | [assembly: AssemblyTitle("CodeMetrics.Parsing")] 4 | -------------------------------------------------------------------------------- /CodeMetrics.Parsing/PropertyVisitor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ICSharpCode.NRefactory.CSharp; 3 | 4 | namespace CodeMetrics.Parsing 5 | { 6 | public class PropertyVisitor : DepthFirstAstVisitor, IMethodsVisitor 7 | { 8 | private readonly List properties; 9 | 10 | public PropertyVisitor() 11 | { 12 | properties = new List(); 13 | } 14 | 15 | public IEnumerable Methods 16 | { 17 | get 18 | { 19 | return properties; 20 | } 21 | } 22 | 23 | public override void VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration) 24 | { 25 | base.VisitPropertyDeclaration(propertyDeclaration); 26 | 27 | AddAccessorMethod(propertyDeclaration.Getter); 28 | AddAccessorMethod(propertyDeclaration.Setter); 29 | } 30 | 31 | private void AddAccessorMethod(Accessor accessor) 32 | { 33 | // getter or setter is missing 34 | if (accessor.StartLocation.Line <= 0) 35 | return; 36 | 37 | var accessorStartLocation = accessor.StartLocation.AsLocation(); 38 | var accessorEndLocation = accessor.EndLocation.AsLocation(); 39 | properties.Add(new Method(accessorStartLocation, accessorStartLocation, accessorEndLocation)); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /CodeMetrics.Parsing/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /CodeMetrics.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26403.7 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{D37907FE-7116-4160-B753-A1E49421FB55}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DAE626FB-6399-4520-85D5-94203304101B}" 9 | ProjectSection(SolutionItems) = preProject 10 | License.txt = License.txt 11 | EndProjectSection 12 | EndProject 13 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{4CE7064A-8B25-48E3-87CF-F4CA94110A21}" 14 | ProjectSection(SolutionItems) = preProject 15 | .nuget\NuGet.Config = .nuget\NuGet.Config 16 | .nuget\NuGet.exe = .nuget\NuGet.exe 17 | .nuget\NuGet.targets = .nuget\NuGet.targets 18 | .nuget\packages.config = .nuget\packages.config 19 | EndProjectSection 20 | EndProject 21 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeMetrics.Calculators", "CodeMetrics.Calculators\CodeMetrics.Calculators.csproj", "{CF35E234-7831-4A2B-8F18-BBB0F8621B10}" 22 | EndProject 23 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeMetrics.Calculators.Tests", "Tests\CodeMetrics.Calculators.Tests\CodeMetrics.Calculators.Tests.csproj", "{410CD13E-9ED3-48BD-B0CD-875AF5CC778A}" 24 | EndProject 25 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeMetrics.Adornments", "CodeMetrics.Adornments\CodeMetrics.Adornments.csproj", "{761E5998-C690-4B1A-949F-6298F7C50464}" 26 | EndProject 27 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeMetrics.Parsing", "CodeMetrics.Parsing\CodeMetrics.Parsing.csproj", "{4F281F92-DFF0-44DF-A150-A95DC83D727D}" 28 | EndProject 29 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeMetrics.Parsing.Tests", "Tests\CodeMetrics.Parsing.Tests\CodeMetrics.Parsing.Tests.csproj", "{1026543B-0009-4BBE-AABB-7295291BE6E6}" 30 | EndProject 31 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeMetrics.Common", "CodeMetrics.Common\CodeMetrics.Common.csproj", "{85E6E6BC-C02E-4A46-9779-BD8AC95A46A7}" 32 | EndProject 33 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeMetrics.Adornments.Tests", "Tests\CodeMetrics.Adornments.Tests\CodeMetrics.Adornments.Tests.csproj", "{1DC8AAB3-3056-4D90-9DAE-1BAA7E0BE68F}" 34 | EndProject 35 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".build", ".build", "{D7FD4063-A4A1-4179-83C3-912A672A9A7F}" 36 | ProjectSection(SolutionItems) = preProject 37 | Build.proj = Build.proj 38 | packages\MSBuildTasks.1.4.0.128\tools\MSBuild.Community.Tasks.dll = packages\MSBuildTasks.1.4.0.128\tools\MSBuild.Community.Tasks.dll 39 | packages\MSBuildTasks.1.4.0.128\tools\MSBuild.Community.Tasks.Targets = packages\MSBuildTasks.1.4.0.128\tools\MSBuild.Community.Tasks.Targets 40 | EndProjectSection 41 | EndProject 42 | Global 43 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 44 | Debug|Any CPU = Debug|Any CPU 45 | Release|Any CPU = Release|Any CPU 46 | EndGlobalSection 47 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 48 | {CF35E234-7831-4A2B-8F18-BBB0F8621B10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 49 | {CF35E234-7831-4A2B-8F18-BBB0F8621B10}.Debug|Any CPU.Build.0 = Debug|Any CPU 50 | {CF35E234-7831-4A2B-8F18-BBB0F8621B10}.Release|Any CPU.ActiveCfg = Release|Any CPU 51 | {CF35E234-7831-4A2B-8F18-BBB0F8621B10}.Release|Any CPU.Build.0 = Release|Any CPU 52 | {410CD13E-9ED3-48BD-B0CD-875AF5CC778A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 53 | {410CD13E-9ED3-48BD-B0CD-875AF5CC778A}.Debug|Any CPU.Build.0 = Debug|Any CPU 54 | {410CD13E-9ED3-48BD-B0CD-875AF5CC778A}.Release|Any CPU.ActiveCfg = Release|Any CPU 55 | {410CD13E-9ED3-48BD-B0CD-875AF5CC778A}.Release|Any CPU.Build.0 = Release|Any CPU 56 | {761E5998-C690-4B1A-949F-6298F7C50464}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 57 | {761E5998-C690-4B1A-949F-6298F7C50464}.Debug|Any CPU.Build.0 = Debug|Any CPU 58 | {761E5998-C690-4B1A-949F-6298F7C50464}.Release|Any CPU.ActiveCfg = Release|Any CPU 59 | {761E5998-C690-4B1A-949F-6298F7C50464}.Release|Any CPU.Build.0 = Release|Any CPU 60 | {4F281F92-DFF0-44DF-A150-A95DC83D727D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 61 | {4F281F92-DFF0-44DF-A150-A95DC83D727D}.Debug|Any CPU.Build.0 = Debug|Any CPU 62 | {4F281F92-DFF0-44DF-A150-A95DC83D727D}.Release|Any CPU.ActiveCfg = Release|Any CPU 63 | {4F281F92-DFF0-44DF-A150-A95DC83D727D}.Release|Any CPU.Build.0 = Release|Any CPU 64 | {1026543B-0009-4BBE-AABB-7295291BE6E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 65 | {1026543B-0009-4BBE-AABB-7295291BE6E6}.Debug|Any CPU.Build.0 = Debug|Any CPU 66 | {1026543B-0009-4BBE-AABB-7295291BE6E6}.Release|Any CPU.ActiveCfg = Release|Any CPU 67 | {1026543B-0009-4BBE-AABB-7295291BE6E6}.Release|Any CPU.Build.0 = Release|Any CPU 68 | {85E6E6BC-C02E-4A46-9779-BD8AC95A46A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 69 | {85E6E6BC-C02E-4A46-9779-BD8AC95A46A7}.Debug|Any CPU.Build.0 = Debug|Any CPU 70 | {85E6E6BC-C02E-4A46-9779-BD8AC95A46A7}.Release|Any CPU.ActiveCfg = Release|Any CPU 71 | {85E6E6BC-C02E-4A46-9779-BD8AC95A46A7}.Release|Any CPU.Build.0 = Release|Any CPU 72 | {1DC8AAB3-3056-4D90-9DAE-1BAA7E0BE68F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 73 | {1DC8AAB3-3056-4D90-9DAE-1BAA7E0BE68F}.Debug|Any CPU.Build.0 = Debug|Any CPU 74 | {1DC8AAB3-3056-4D90-9DAE-1BAA7E0BE68F}.Release|Any CPU.ActiveCfg = Release|Any CPU 75 | {1DC8AAB3-3056-4D90-9DAE-1BAA7E0BE68F}.Release|Any CPU.Build.0 = Release|Any CPU 76 | EndGlobalSection 77 | GlobalSection(SolutionProperties) = preSolution 78 | HideSolutionNode = FALSE 79 | EndGlobalSection 80 | GlobalSection(NestedProjects) = preSolution 81 | {410CD13E-9ED3-48BD-B0CD-875AF5CC778A} = {D37907FE-7116-4160-B753-A1E49421FB55} 82 | {1026543B-0009-4BBE-AABB-7295291BE6E6} = {D37907FE-7116-4160-B753-A1E49421FB55} 83 | {1DC8AAB3-3056-4D90-9DAE-1BAA7E0BE68F} = {D37907FE-7116-4160-B753-A1E49421FB55} 84 | EndGlobalSection 85 | EndGlobal 86 | -------------------------------------------------------------------------------- /Dependencies/NRefactory/ICSharpCode.NRefactory.CSharp.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/Dependencies/NRefactory/ICSharpCode.NRefactory.CSharp.dll -------------------------------------------------------------------------------- /Dependencies/NRefactory/ICSharpCode.NRefactory.Xml.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/Dependencies/NRefactory/ICSharpCode.NRefactory.Xml.dll -------------------------------------------------------------------------------- /Dependencies/NRefactory/ICSharpCode.NRefactory.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/Dependencies/NRefactory/ICSharpCode.NRefactory.dll -------------------------------------------------------------------------------- /Dependencies/Nunit/nunit.framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/Dependencies/Nunit/nunit.framework.dll -------------------------------------------------------------------------------- /Dependencies/Windsor/Castle.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/Dependencies/Windsor/Castle.Core.dll -------------------------------------------------------------------------------- /Dependencies/Windsor/Castle.Core.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/Dependencies/Windsor/Castle.Core.pdb -------------------------------------------------------------------------------- /Dependencies/Windsor/Castle.Windsor.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/Dependencies/Windsor/Castle.Windsor.dll -------------------------------------------------------------------------------- /Dependencies/Windsor/Castle.Windsor.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/Dependencies/Windsor/Castle.Windsor.pdb -------------------------------------------------------------------------------- /Dependencies/Windsor/loggingFacility/Castle.Facilities.Logging.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/Dependencies/Windsor/loggingFacility/Castle.Facilities.Logging.dll -------------------------------------------------------------------------------- /Dependencies/Windsor/loggingFacility/Castle.Facilities.Logging.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/Dependencies/Windsor/loggingFacility/Castle.Facilities.Logging.pdb -------------------------------------------------------------------------------- /Dependencies/Windsor/loggingFacility/Castle.Facilities.Logging.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Castle.Facilities.Logging 5 | 6 | 7 | 8 | 9 | The supported implementations 10 | 11 | 12 | 13 | 14 | Custom resolver used by Windsor. It gives 15 | us some contextual information that we use to set up a logging 16 | before satisfying the dependency 17 | 18 | 19 | 20 | 21 | A facility for logging support. 22 | 23 | 24 | 25 | 26 | Initializes a new instance of the class. 27 | 28 | 29 | 30 | 31 | Initializes a new instance of the class. 32 | 33 | 34 | The LoggerImplementation that should be used 35 | 36 | 37 | 38 | 39 | Initializes a new instance of the class. 40 | 41 | 42 | The LoggerImplementation that should be used 43 | 44 | 45 | The configuration file that should be used by the chosen LoggerImplementation 46 | 47 | 48 | 49 | 50 | Initializes a new instance of the class using a custom LoggerImplementation 51 | 52 | 53 | The configuration file that should be used by the chosen LoggerImplementation 54 | 55 | 56 | The type name of the type of the custom logger factory. 57 | 58 | 59 | 60 | 61 | Initializes a new instance of the class. 62 | 63 | 64 | The LoggerImplementation that should be used 65 | 66 | 67 | The configuration file that should be used by the chosen LoggerImplementation 68 | 69 | 70 | The type name of the type of the custom logger factory. (only used when loggingApi is set to LoggerImplementation.Custom) 71 | 72 | 73 | 74 | 75 | loads configuration from current AppDomain's config file (aka web.config/app.config) 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /Dependencies/Windsor/loggingFacility/Castle.Services.Logging.Log4netIntegration.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/Dependencies/Windsor/loggingFacility/Castle.Services.Logging.Log4netIntegration.dll -------------------------------------------------------------------------------- /Dependencies/Windsor/loggingFacility/Castle.Services.Logging.Log4netIntegration.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/Dependencies/Windsor/loggingFacility/Castle.Services.Logging.Log4netIntegration.pdb -------------------------------------------------------------------------------- /Dependencies/Windsor/loggingFacility/Castle.Services.Logging.NLogIntegration.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/Dependencies/Windsor/loggingFacility/Castle.Services.Logging.NLogIntegration.dll -------------------------------------------------------------------------------- /Dependencies/Windsor/loggingFacility/Castle.Services.Logging.NLogIntegration.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/Dependencies/Windsor/loggingFacility/Castle.Services.Logging.NLogIntegration.pdb -------------------------------------------------------------------------------- /Dependencies/Windsor/loggingFacility/NLog.Extended.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/Dependencies/Windsor/loggingFacility/NLog.Extended.dll -------------------------------------------------------------------------------- /Dependencies/Windsor/loggingFacility/NLog.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/Dependencies/Windsor/loggingFacility/NLog.dll -------------------------------------------------------------------------------- /Dependencies/Windsor/loggingFacility/log4net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/Dependencies/Windsor/loggingFacility/log4net.dll -------------------------------------------------------------------------------- /Dependencies/Windsor/synchronizeFacility/Castle.Facilities.Synchronize.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/Dependencies/Windsor/synchronizeFacility/Castle.Facilities.Synchronize.dll -------------------------------------------------------------------------------- /Dependencies/Windsor/synchronizeFacility/Castle.Facilities.Synchronize.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishalom/netcodemetrics/845b6682500eab770ba8ce1ef7e49e5d1a7cdca0/Dependencies/Windsor/synchronizeFacility/Castle.Facilities.Synchronize.pdb -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | New BSD License (BSD) 2 | Copyright (c) 2011, The code metrics project 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 8 | 9 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 10 | 11 | * Neither the name of The code metrics project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # netcodemetrics 2 | 3 | This project is a VS extension that computes code complexity as-you-type. 4 | 5 | The extension is supported by Visual Studio versions 2012 - 2019. 6 | 7 | The complexity being computed is Simple Complexity, as introduced in the Code-Complete book. 8 | The computed complexity reflects how many decision points are in a given function, and the numbers should encourage developers to refactor over-complicated functions. 9 | 10 | The extension is listed in VS Gallery: http://bit.ly/2LAADFY 11 | -------------------------------------------------------------------------------- /Tests/CodeMetrics.Adornments.Tests/CodeMetrics.Adornments.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | {1DC8AAB3-3056-4D90-9DAE-1BAA7E0BE68F} 7 | Library 8 | Properties 9 | CodeMetrics.Adornments.Tests 10 | CodeMetrics.Adornments.Tests 11 | v4.6.1 12 | 512 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 10.0 15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 17 | False 18 | UnitTest 19 | 20 | ..\..\ 21 | true 22 | 23 | 24 | true 25 | full 26 | false 27 | bin\Debug\ 28 | DEBUG;TRACE 29 | prompt 30 | 4 31 | false 32 | 33 | 34 | pdbonly 35 | true 36 | bin\Release\ 37 | TRACE 38 | prompt 39 | 4 40 | false 41 | 42 | 43 | 44 | ..\..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll 45 | True 46 | 47 | 48 | ..\..\packages\NUnit.3.0.1\lib\net45\nunit.framework.dll 49 | True 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | {761e5998-c690-4b1a-949f-6298f7c50464} 74 | CodeMetrics.Adornments 75 | 76 | 77 | {CF35E234-7831-4A2B-8F18-BBB0F8621B10} 78 | CodeMetrics.Calculators 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | False 90 | 91 | 92 | False 93 | 94 | 95 | False 96 | 97 | 98 | False 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 109 | 110 | 111 | 112 | 119 | -------------------------------------------------------------------------------- /Tests/CodeMetrics.Adornments.Tests/ColorConverterTest.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Media; 2 | using CodeMetrics.Options; 3 | using Moq; 4 | using NUnit.Framework; 5 | 6 | namespace CodeMetrics.Adornments.Tests 7 | { 8 | [TestFixture] 9 | public class ColorConverterTest 10 | { 11 | [Test] 12 | public void ComplexityZeroConvertsToDefaultAllowedColor() 13 | { 14 | const int complexity = 0; 15 | Color color = ConvertToBrush(complexity); 16 | 17 | Assert.That(color, Is.EqualTo(Colors.Green), "Complexity 0 has to equal to default Allowed color"); 18 | } 19 | 20 | [Test] 21 | public void ComplexityTenConvertsToDefaultAllowedColor() 22 | { 23 | const int complexity = 10; 24 | Color color = ConvertToBrush(complexity); 25 | 26 | Assert.That(color, Is.EqualTo(Colors.Red), "Complexity 10 has to equal to default Error color"); 27 | } 28 | 29 | private static Color ConvertToBrush(int complexity) 30 | { 31 | Mock optionsMock = CreateOptionsMock(); 32 | 33 | var converter = new ComplexityToColor(optionsMock.Object); 34 | return converter.Convert(complexity); 35 | } 36 | 37 | internal static Mock CreateOptionsMock() 38 | { 39 | var optionsMock = new Mock(); 40 | optionsMock.SetupGet(o => o.MinimumToShow).Returns(0); 41 | optionsMock.SetupGet(o => o.GoodColor).Returns(System.Drawing.Color.Green); 42 | optionsMock.SetupGet(o => o.BadColor).Returns(System.Drawing.Color.Red); 43 | return optionsMock; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Tests/CodeMetrics.Adornments.Tests/ColorToBrushConverterTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Media; 4 | using NUnit.Framework; 5 | 6 | namespace CodeMetrics.Adornments.Tests 7 | { 8 | [TestFixture] 9 | public class ColorToBrushConverterTests 10 | { 11 | [Test] 12 | public void Null_Convert_ReturnTransparentBrush() 13 | { 14 | var brush = this.Convert(null); 15 | Assert.That(brush, Is.EqualTo(Brushes.Transparent)); 16 | } 17 | 18 | [Test] 19 | public void Object_Convert_ReturnTransparentBrush() 20 | { 21 | var brush = this.Convert(new object()); 22 | Assert.That(brush, Is.EqualTo(Brushes.Transparent)); 23 | } 24 | 25 | [Test] 26 | public void GreenColor_Convert_ReturnGreenBrush() 27 | { 28 | Color expected = Colors.Green; 29 | var brush = this.Convert(expected); 30 | Assert.That(brush.Color, Is.EqualTo(expected)); 31 | } 32 | 33 | [Test] 34 | public void TransparentBrush_ConvertBack_ThrowsNotImplementedException() 35 | { 36 | var converter = new ColorToBrushConverter(); 37 | 38 | Assert.That(() => converter.ConvertBack(Brushes.Transparent, typeof(Brush), null, CultureInfo.InvariantCulture), 39 | Throws.TypeOf()); 40 | } 41 | 42 | private SolidColorBrush Convert(object toConvert) 43 | { 44 | var converter = new ColorToBrushConverter(); 45 | return (SolidColorBrush)converter.Convert(toConvert, typeof(Color), null, CultureInfo.InvariantCulture); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Tests/CodeMetrics.Adornments.Tests/ComplexityViewModelTests.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Media; 2 | using CodeMetrics.Calculators; 3 | using CodeMetrics.Options; 4 | using CodeMetrics.UserControls; 5 | using Moq; 6 | using NUnit.Framework; 7 | 8 | namespace CodeMetrics.Adornments.Tests 9 | { 10 | [TestFixture] 11 | public class ComplexityViewModelTests 12 | { 13 | private const int Expected = 5; 14 | 15 | [Test] 16 | public void NewComplexity_UpdateComplexity_FiresNotifyPropertyChanged() 17 | { 18 | bool eventFired = false; 19 | var model = CreateViewModel(); 20 | model.PropertyChanged += (sender, args) => eventFired = true; 21 | var complexityMock = CreateComplexityMock(); 22 | model.UpdateComplexity(complexityMock.Object); 23 | Assert.That(eventFired, Is.True, "ViewMoled bindings in UI require property working notify property changed."); 24 | } 25 | 26 | [Test] 27 | public void NoComplexitySet_GetValue_Returns0() 28 | { 29 | ComplexityViewModel model = CreateViewModel(); 30 | Assert.That(model.Value, Is.EqualTo(0), "Default complexity value should be zero."); 31 | } 32 | 33 | [Test] 34 | public void AfterUpdateComplexity5_GetValue_Returns5() 35 | { 36 | ComplexityViewModel model = AssignComplexity(); 37 | Assert.That(model.Value, Is.EqualTo(Expected), "View model wraps last assigned complexity."); 38 | } 39 | 40 | [Test] 41 | public void AfterUpdateComplexity0_GetColor_ReturnsGreen() 42 | { 43 | ComplexityViewModel model = AssignComplexity(0); 44 | Assert.That(model.Color, Is.EqualTo(Colors.Green), "Zero complexity is converted to allowed color.."); 45 | } 46 | 47 | [Test] 48 | public void MiminumToShow3Complexity5_GetVisible_ReturnsTrue() 49 | { 50 | ComplexityViewModel model = CreateViewModelByOptions(3); 51 | Assert.That(model.Visible, Is.True); 52 | } 53 | 54 | [Test] 55 | public void MiminumToShow5Complexity5_GetVisible_ReturnsTrue() 56 | { 57 | ComplexityViewModel model = CreateViewModelByOptions(5); 58 | Assert.That(model.Visible, Is.True); 59 | } 60 | 61 | [Test] 62 | public void MiminumToShow7Complexity5_GetVisible_ReturnsFalse() 63 | { 64 | ComplexityViewModel model = CreateViewModelByOptions(7); 65 | Assert.That(model.Visible, Is.False); 66 | } 67 | 68 | private static ComplexityViewModel CreateViewModelByOptions(int minimumToShow) 69 | { 70 | Mock optionsMock = new Mock(); 71 | optionsMock.SetupGet(o => o.MinimumToShow).Returns(minimumToShow); 72 | return AssigComplexity(optionsMock); 73 | } 74 | 75 | private static ComplexityViewModel AssignComplexity(int expected = Expected) 76 | { 77 | Mock optionsMock = ColorConverterTest.CreateOptionsMock(); 78 | return AssigComplexity(optionsMock, expected); 79 | } 80 | 81 | private static ComplexityViewModel AssigComplexity(Mock optionsMock, int expected = Expected) 82 | { 83 | Mock mockComplexity = CreateComplexityMock(expected); 84 | var model = new ComplexityViewModel(optionsMock.Object); 85 | model.UpdateComplexity(mockComplexity.Object); 86 | return model; 87 | } 88 | 89 | private static ComplexityViewModel CreateViewModel() 90 | { 91 | Mock optionsMock = ColorConverterTest.CreateOptionsMock(); 92 | return new ComplexityViewModel(optionsMock.Object); 93 | } 94 | 95 | private static Mock CreateComplexityMock(int expected = Expected) 96 | { 97 | var mockComplexity = new Mock(); 98 | mockComplexity.SetupGet(c => c.Value) 99 | .Returns(() => expected); 100 | return mockComplexity; 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /Tests/CodeMetrics.Adornments.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("CodeMetrics.Adornments.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("CodeMetrics.Adornments.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("e063f0f5-8be1-47ab-b281-75160b91be03")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Tests/CodeMetrics.Adornments.Tests/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Tests/CodeMetrics.Adornments.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Tests/CodeMetrics.Calculators.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("CodeMetrics.Calculators.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("CodeMetrics.Calculators.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("1e132c3a-e5bb-44a9-bdbc-238ce0554629")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Tests/CodeMetrics.Calculators.Tests/ToStringTests.cs: -------------------------------------------------------------------------------- 1 | using CodeMetrics.Parsing; 2 | using NUnit.Framework; 3 | 4 | namespace CodeMetrics.Calculators.Tests 5 | { 6 | [TestFixture] 7 | internal class ToStringTests 8 | { 9 | [Test] 10 | public void ComplexityToString_ReturnsValue() 11 | { 12 | var complexity = new Complexity(5); 13 | string complexityText = complexity.ToString(); 14 | Assert.AreEqual("Complexity:5", complexityText, "Complexity ToString should return formated value."); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Tests/CodeMetrics.Calculators.Tests/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Tests/CodeMetrics.Calculators.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Tests/CodeMetrics.Parsing.Tests/CodeMetrics.Parsing.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {1026543B-0009-4BBE-AABB-7295291BE6E6} 9 | Library 10 | Properties 11 | CodeMetrics.Parsing.Tests 12 | CodeMetrics.Parsing.Tests 13 | v4.6.1 14 | 512 15 | ..\..\ 16 | true 17 | 18 | 19 | 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | false 28 | 29 | 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | false 37 | 38 | 39 | 40 | ..\..\packages\Castle.Core.3.3.3\lib\net40-client\Castle.Core.dll 41 | True 42 | 43 | 44 | ..\..\packages\Castle.Windsor.3.3.0\lib\net40\Castle.Windsor.dll 45 | True 46 | 47 | 48 | ..\..\packages\NUnit.3.0.1\lib\net40\nunit.framework.dll 49 | True 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | {85E6E6BC-C02E-4A46-9779-BD8AC95A46A7} 70 | CodeMetrics.Common 71 | 72 | 73 | {4F281F92-DFF0-44DF-A150-A95DC83D727D} 74 | CodeMetrics.Parsing 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 86 | 87 | 88 | 89 | 96 | -------------------------------------------------------------------------------- /Tests/CodeMetrics.Parsing.Tests/ConstructorExtractorTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using CodeMetrics.Common; 4 | using NUnit.Framework; 5 | 6 | namespace CodeMetrics.Parsing.Tests 7 | { 8 | /// 9 | /// learning tests for parsing the class Constructors 10 | /// 11 | [TestFixture] 12 | public class ConstructorExtractorTests : ExtractorsTestBase 13 | { 14 | [Test] 15 | public void Extract_FileWithSingleClassWithNoConstructor_ReturnNoConstructor() 16 | { 17 | var methods = ExtractMethods(OneEmptyClass); 18 | 19 | Assert.That(methods, Is.Empty); 20 | } 21 | 22 | [Test] 23 | public void Extract_FileWithSingleClassWithParameterLessConstructor_ReturnsOneMethod() 24 | { 25 | const string fileCode = @"using System; 26 | namespace MyNamespace 27 | { 28 | public class MyCalss 29 | { 30 | public MyCalss() 31 | { 32 | } 33 | } 34 | }"; 35 | var methods = ExtractMethods(fileCode); 36 | 37 | Assert.That(methods.Count(), Is.EqualTo(1)); 38 | } 39 | 40 | [Test] 41 | public void Extract_FileWithSingleClassWithParameterConstructor_ReturnOneMethod() 42 | { 43 | const string fileCode = @"using System; 44 | namespace MyNamespace 45 | { 46 | public class MyCalss 47 | { 48 | public MyCalss(string construtorParam) 49 | { 50 | } 51 | } 52 | }"; 53 | var methods = ExtractMethods(fileCode); 54 | 55 | Assert.That(methods.Count(), Is.EqualTo(1)); 56 | } 57 | 58 | [Test] 59 | public void Extract_FileWithSingleClassWithTwoConstructors_ReturnTwoMethods() 60 | { 61 | const string fileCode = @"using System; 62 | namespace MyNamespace 63 | { 64 | public class MyCalss 65 | { 66 | public MyCalss(string construtorParam) 67 | { 68 | } 69 | 70 | public MyCalss(int construtorParam) 71 | { 72 | } 73 | } 74 | }"; 75 | var methods = ExtractMethods(fileCode); 76 | 77 | Assert.That(methods.Count(), Is.EqualTo(2)); 78 | } 79 | 80 | [Test] 81 | public void Extract_FileWithSingleClassWithDerivedConstructor_ReturnOneMethod() 82 | { 83 | const string fileCode = @"using System; 84 | namespace MyNamespace 85 | { 86 | public class MyCalss 87 | { 88 | public MyCalss(string construtorParam) : base() 89 | { 90 | } 91 | } 92 | }"; 93 | var methods = ExtractMethods(fileCode); 94 | 95 | Assert.That(methods.Count(), Is.EqualTo(1)); 96 | } 97 | 98 | [Test] 99 | public void Extract_FileWithSingleClassWithReferencedConstructor_ReturnTwoMethods() 100 | { 101 | const string fileCode = @"using System; 102 | namespace MyNamespace 103 | { 104 | public class MyCalss 105 | { 106 | public MyCalss(string construtorParam) : this() 107 | { 108 | } 109 | 110 | public MyCalss() 111 | { 112 | } 113 | } 114 | }"; 115 | var methods = ExtractMethods(fileCode); 116 | 117 | Assert.That(methods.Count(), Is.EqualTo(2)); 118 | } 119 | 120 | [Test] 121 | public void Extract_FileWithTwoClassesWithOneConstructor_ReturnTwoMethods() 122 | { 123 | const string fileCode = @"using System; 124 | namespace MyNamespace 125 | { 126 | public class MyCalss 127 | { 128 | public MyCalss() 129 | { 130 | } 131 | } 132 | 133 | public class MyCalssB 134 | { 135 | public MyCalssB() 136 | { 137 | } 138 | } 139 | }"; 140 | var methods = ExtractMethods(fileCode); 141 | 142 | Assert.That(methods.Count(), Is.EqualTo(2)); 143 | } 144 | 145 | [Test] 146 | public void Extract_FileWithNestedClassWithOneConstructor_ReturnTwoMethods() 147 | { 148 | const string fileCode = @"using System; 149 | namespace MyNamespace 150 | { 151 | public class MyCalss 152 | { 153 | public MyCalss() 154 | { 155 | } 156 | 157 | public class MyCalssB 158 | { 159 | public MyCalssB() 160 | { 161 | } 162 | } 163 | } 164 | }"; 165 | var methods = ExtractMethods(fileCode); 166 | 167 | Assert.That(methods.Count(), Is.EqualTo(2)); 168 | } 169 | 170 | [Test] 171 | public void Extract_FileWithOneClassWithInLineConstructor_ReturnOneMethod() 172 | { 173 | const string fileCode = @"using System; 174 | namespace MyNamespace 175 | { 176 | public class MyCalss 177 | { 178 | public MyCalss() { } 179 | } 180 | }"; 181 | var methods = ExtractMethods(fileCode); 182 | 183 | Assert.That(methods.Count(), Is.EqualTo(1)); 184 | } 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /Tests/CodeMetrics.Parsing.Tests/ExtractorsTestBase.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using CodeMetrics.Common; 3 | using NUnit.Framework; 4 | 5 | namespace CodeMetrics.Parsing.Tests 6 | { 7 | /// 8 | /// Fresh Test fixture for all kind of extractors 9 | /// 10 | [TestFixture] 11 | public class ExtractorsTestBase 12 | { 13 | protected const string OneEmptyClass = @"using System; 14 | namespace MyNamespace 15 | { 16 | public class MyCalss 17 | { 18 | } 19 | }"; 20 | 21 | private IMethodsVisitorFactory factory; 22 | 23 | [SetUp] 24 | public void Setup() 25 | { 26 | var windsorContainer = ContainerFactory.CreateContainer(); 27 | factory = windsorContainer.Resolve(); 28 | } 29 | 30 | protected IEnumerable ExtractMethods(string fileCode) 31 | { 32 | var methodsExtractor = new MethodsExtractor(factory); 33 | return methodsExtractor.Extract(fileCode); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Tests/CodeMetrics.Parsing.Tests/MethodsExtractorTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using NUnit.Framework; 3 | 4 | namespace CodeMetrics.Parsing.Tests 5 | { 6 | [TestFixture] 7 | public class MethodsExtractorTests : ExtractorsTestBase 8 | { 9 | [Test] 10 | public void Extract_FileWithSingleClassWithNoMethods_ReturnNoMethods() 11 | { 12 | const string fileCode = @"using System; 13 | namespace MyNamespace 14 | { 15 | public class MyCalss 16 | { 17 | } 18 | }"; 19 | 20 | 21 | var methods = ExtractMethods(fileCode); 22 | 23 | Assert.That(methods, Is.Empty); 24 | } 25 | 26 | [Test] 27 | public void Extract_FileWithSingleClassWithSingleMethod_ReturnOneMethod() 28 | { 29 | const string fileCode = @"using System; 30 | namespace MyNamespace 31 | { 32 | public class MyCalss 33 | { 34 | public void MyMethod() { } 35 | } 36 | }"; 37 | var methods = ExtractMethods(fileCode); 38 | 39 | Assert.That(methods.Count(), Is.EqualTo(1)); 40 | } 41 | 42 | [Test] 43 | public void Extract_FileWithSingleClassWithTwoMethods_ReturnTwoMethods() 44 | { 45 | const string fileCode = @"using System; 46 | namespace MyNamespace 47 | { 48 | public class MyCalss 49 | { 50 | public void MyMethod1() { } 51 | public void MyMethod2() { } 52 | } 53 | }"; 54 | var methods = ExtractMethods(fileCode); 55 | 56 | Assert.That(methods.Count(), Is.EqualTo(2)); 57 | } 58 | 59 | [Test] 60 | public void Extract_FilePrefixedWithTwoUsingsWithSingleClassWithSingleMethod_ReturnOneMethod() 61 | { 62 | const string fileCode = @"using System; 63 | using System.Reflection; 64 | namespace MyNamespace 65 | { 66 | public class MyCalss 67 | { 68 | public void MyMethod() { } 69 | } 70 | }"; 71 | var methods = ExtractMethods(fileCode); 72 | 73 | Assert.That(methods.Count(), Is.EqualTo(1)); 74 | } 75 | 76 | [Test] 77 | public void Extract_FileWithTwoClassesWithSingleMethodEach_ReturnTwoMethod() 78 | { 79 | const string fileCode = @"using System; 80 | namespace MyNamespace 81 | { 82 | public class MyCalss1 83 | { 84 | public void MyMethod1() { } 85 | } 86 | public class MyCalss2 87 | { 88 | public void MyMethod2() { } 89 | } 90 | }"; 91 | var methods = ExtractMethods(fileCode); 92 | 93 | Assert.That(methods.Count(), Is.EqualTo(2)); 94 | } 95 | 96 | [Test] 97 | public void Extract_FileWithNestedClassWithSingleMethod_ReturnOneMethod() 98 | { 99 | const string fileCode = @"using System; 100 | namespace MyNamespace 101 | { 102 | public class MyCalss 103 | { 104 | public class MyNestedCalss 105 | { 106 | public void MyMethod() { } 107 | } 108 | } 109 | }"; 110 | var methods = ExtractMethods(fileCode); 111 | 112 | Assert.That(methods.Count(), Is.EqualTo(1)); 113 | } 114 | 115 | [Test] 116 | public void Extract_FileWithSingleClassWithSingleMethod_MethodStartLineIsCorrect() 117 | { 118 | const string fileCode = @"using System; 119 | namespace MyNamespace 120 | { 121 | public class MyCalss 122 | { 123 | public void MyMethod() { } 124 | } 125 | }"; 126 | var methods = ExtractMethods(fileCode); 127 | 128 | Assert.That(methods.First().Decleration.Line, Is.EqualTo(5)); 129 | } 130 | 131 | [Test] 132 | public void Extract_FileWithSingleClassWithSingleMethodWithOptParameter_MethodStartLineIsCorrect() 133 | { 134 | const string fileCode = @"using System; 135 | namespace MyNamespace 136 | { 137 | public class MyCalss 138 | { 139 | public void MyMethod(int x = 0) { } 140 | } 141 | }"; 142 | var methods = ExtractMethods(fileCode); 143 | 144 | Assert.That(methods.First().Decleration.Line, Is.EqualTo(5)); 145 | } 146 | 147 | [Test] 148 | public void Extract_FileWithSingleClassWithSingleMethod_MethodStartColumnIsCorrect() 149 | { 150 | const string fileCode = @"using System; 151 | namespace MyNamespace 152 | { 153 | public class MyCalss 154 | { 155 | public void MyMethod() { } 156 | } 157 | }"; 158 | var methods = ExtractMethods(fileCode); 159 | 160 | Assert.That(methods.First().Decleration.Column, Is.EqualTo(8)); 161 | } 162 | 163 | [Test] 164 | public void Extract_FileWithSingleClassWithSingleMethod_MethodEndLineIsCorrect() 165 | { 166 | const string fileCode = @"using System; 167 | namespace MyNamespace 168 | { 169 | public class MyCalss 170 | { 171 | public void MyMethod() { } 172 | } 173 | }"; 174 | var methods = ExtractMethods(fileCode); 175 | 176 | Assert.That(methods.First().BodyEnd.Line, Is.EqualTo(5)); 177 | } 178 | [Test] 179 | public void Extract_FileWithSingleClassWithSingleMethod_MethodEndColumnIsCorrect() 180 | { 181 | const string fileCode = @"using System; 182 | namespace MyNamespace 183 | { 184 | public class MyCalss 185 | { 186 | public void MyMethod() { } 187 | } 188 | }"; 189 | 190 | var methods = ExtractMethods(fileCode); 191 | 192 | Assert.That(methods.First().BodyEnd.Column, Is.EqualTo(34)); 193 | } 194 | 195 | [Test] 196 | public void Extract_FileWithSingleClassWithSingleMethod_MethodStartLineBodyIsCorrect() 197 | { 198 | const string fileCode = @"using System; 199 | namespace MyNamespace 200 | { 201 | public class MyCalss 202 | { 203 | public void MyMethod() 204 | { 205 | } 206 | } 207 | }"; 208 | 209 | var methods = ExtractMethods(fileCode); 210 | 211 | Assert.That(methods.First().BodyStart.Line, Is.EqualTo(6)); 212 | } 213 | 214 | [Test] 215 | public void Extract_FileWithSingleClassWithSingleMethod_MethodStartColumnBodyIsCorrect() 216 | { 217 | const string fileCode = @"using System; 218 | namespace MyNamespace 219 | { 220 | public class MyCalss 221 | { 222 | public void MyMethod() 223 | { 224 | } 225 | } 226 | }"; 227 | 228 | var methods = ExtractMethods(fileCode); 229 | 230 | Assert.That(methods.First().BodyStart.Column, Is.EqualTo(8)); 231 | } 232 | 233 | 234 | } 235 | } -------------------------------------------------------------------------------- /Tests/CodeMetrics.Parsing.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("CodeMetrics.Parsing.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("CodeMetrics.Parsing.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2011")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("1d7ede54-843d-45a5-a142-d893ffacaa66")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Tests/CodeMetrics.Parsing.Tests/PropertyExtractorTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using NUnit.Framework; 3 | 4 | namespace CodeMetrics.Parsing.Tests 5 | { 6 | [TestFixture] 7 | public class PropertyExtractorTests : ExtractorsTestBase 8 | { 9 | private const string AutomaticPropertyOnTwoLines = @"using System; 10 | namespace MyNamespace 11 | { 12 | public class MyCalss 13 | { 14 | public string MyProperty 15 | { 16 | get; 17 | set; 18 | } 19 | } 20 | }"; 21 | 22 | private const string FieldPropertyOnTwoLines = @"using System; 23 | namespace MyNamespace 24 | { 25 | public class MyCalss 26 | { 27 | public string MyProperty 28 | { 29 | get { return string.Empty; } 30 | set { } 31 | } 32 | } 33 | }"; 34 | 35 | [Test] 36 | public void Extract_FileWithSingleClassWithAutomaticProperty_IgnoresAccessors() 37 | { 38 | var methods = ExtractMethods(AutomaticPropertyOnTwoLines); 39 | 40 | Assert.That(methods, Is.Empty); 41 | } 42 | 43 | [Test] 44 | public void Extract_FileWithSingleClassWithFieldProperty_CorrectGetterLine() 45 | { 46 | var methods = ExtractMethods(FieldPropertyOnTwoLines); 47 | int getterStart = methods.First().BodyStart.Line; 48 | 49 | Assert.That(getterStart, Is.EqualTo(7)); 50 | } 51 | 52 | [Test] 53 | public void Extract_FileWithSingleClassWithFieldProperty_CorrectSetterLine() 54 | { 55 | var methods = ExtractMethods(FieldPropertyOnTwoLines); 56 | int setterStart = methods.ToList()[1].BodyStart.Line; 57 | 58 | Assert.That(setterStart, Is.EqualTo(8)); 59 | } 60 | 61 | [Test] 62 | public void Extract_FileWithSingleClassWithNoProperty_ReturnNoMethod() 63 | { 64 | var methods = ExtractMethods(OneEmptyClass); 65 | 66 | Assert.That(methods, Is.Empty); 67 | } 68 | 69 | [Test] 70 | public void Extract_FileWithSingleClassWithAutomaticProperty_IgnoresProperty() 71 | { 72 | const string fileCode = @"using System; 73 | namespace MyNamespace 74 | { 75 | public class MyCalss 76 | { 77 | public string MyProperty { get; set; } 78 | } 79 | }"; 80 | 81 | var methods = ExtractMethods(fileCode); 82 | 83 | Assert.That(methods.Count(), Is.EqualTo(0)); 84 | } 85 | 86 | [Test] 87 | public void Extract_FileWithSingleClassWithGetterOnlyProperty_ReturnOneMethod() 88 | { 89 | const string fileCode = @"using System; 90 | namespace MyNamespace 91 | { 92 | public class MyCalss 93 | { 94 | public string MyProperty 95 | { 96 | get { return string.Empty; } 97 | } 98 | } 99 | }"; 100 | 101 | var methods = ExtractMethods(fileCode); 102 | 103 | Assert.That(methods.Count(), Is.EqualTo(1)); 104 | } 105 | 106 | [Test] 107 | public void Extract_FileWithSingleClassWithSetterOnlyProperty_ReturnOneMethod() 108 | { 109 | const string fileCode = @"using System; 110 | namespace MyNamespace 111 | { 112 | public class MyCalss 113 | { 114 | public string MyProperty { set { } } 115 | } 116 | }"; 117 | 118 | var methods = ExtractMethods(fileCode); 119 | 120 | Assert.That(methods.Count(), Is.EqualTo(1)); 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /Tests/CodeMetrics.Parsing.Tests/ToStringTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | namespace CodeMetrics.Parsing.Tests 4 | { 5 | [TestFixture] 6 | internal class ToStringTests 7 | { 8 | [Test] 9 | public void ValidLocationToString_ReturnsLineAndColumn() 10 | { 11 | var location = new Location(1, 2); 12 | string locationText = location.ToString(); 13 | Assert.AreEqual("Location:1,2", locationText, "Location ToString method should return line and column values"); 14 | } 15 | 16 | [Test] 17 | public void ValidMethodToString_ReturnsAllConcatenatedLocations() 18 | { 19 | var declaration = new Location(1, 2); 20 | var start = new Location(2, 3); 21 | var end = new Location(4, 5); 22 | var method = new Method(declaration, start, end); 23 | string methodText = method.ToString(); 24 | Assert.AreEqual("Method:[1,2-2,3-4,5]", methodText, "Method ToString method should return line and column values"); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Tests/CodeMetrics.Parsing.Tests/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Tests/CodeMetrics.Parsing.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Version/VersionInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | [assembly: AssemblyVersion("0.9.0.0")] 4 | [assembly: AssemblyFileVersion("0.9.0.0")] 5 | -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /packages/repositories.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | --------------------------------------------------------------------------------