Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24dc249
commit 8ccc782
Showing
5 changed files
with
20 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 10 additions & 23 deletions
33
CleanCode/src/CleanCode/Features/TooManyDependencies/TooManyDependenciesCheck.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,34 @@ | ||
using System.Linq; | ||
using CleanCode.Resources; | ||
using CleanCode.Settings; | ||
using JetBrains.Application.Settings; | ||
using JetBrains.ReSharper.Daemon.Stages.Dispatcher; | ||
using JetBrains.ReSharper.Feature.Services.Daemon; | ||
using JetBrains.ReSharper.Psi.CSharp.Tree; | ||
using JetBrains.ReSharper.Psi.Tree; | ||
using JetBrains.ReSharper.Psi.Util; | ||
|
||
namespace CleanCode.Features.TooManyDependencies | ||
{ | ||
public class TooManyDependenciesCheck : MonoValueCheck<IConstructorDeclaration, int> | ||
[ElementProblemAnalyzer(typeof(IConstructorDeclaration), HighlightingTypes = new [] | ||
{ | ||
public TooManyDependenciesCheck(IContextBoundSettingsStore settingsStore) | ||
: base(settingsStore) | ||
{ | ||
} | ||
|
||
protected override void ExecuteCore(IConstructorDeclaration constructorDeclaration, IHighlightingConsumer consumer) | ||
typeof(TooManyDependenciesHighlighting) | ||
})] | ||
public class TooManyDependenciesCheck : ElementProblemAnalyzer<IConstructorDeclaration> | ||
{ | ||
protected override void Run(IConstructorDeclaration element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer) | ||
{ | ||
var maxDependencies = Value; | ||
var maxDependencies = data.SettingsStore.GetValue((CleanCodeSettings s) => s.TooManyDependenciesMaximum); | ||
|
||
var dependencies = constructorDeclaration.ParameterDeclarations.Select( | ||
var dependencies = element.ParameterDeclarations.Select( | ||
declaration => declaration.DeclaredElement != null && | ||
declaration.DeclaredElement.Type.IsInterfaceType()); | ||
|
||
var dependenciesCount = dependencies.Count(); | ||
|
||
if (dependenciesCount > maxDependencies) | ||
{ | ||
var highlighting = new Highlighting(Warnings.TooManyDependencies, | ||
constructorDeclaration.GetNameDocumentRange()); | ||
var highlighting = new TooManyDependenciesHighlighting(element.GetNameDocumentRange()); | ||
consumer.AddHighlighting(highlighting); | ||
} | ||
} | ||
|
||
protected override int Value | ||
{ | ||
get { return SettingsStore.GetValue((CleanCodeSettings s) => s.TooManyDependenciesMaximum); } | ||
} | ||
|
||
protected override bool IsEnabled | ||
{ | ||
get { return SettingsStore.GetValue((CleanCodeSettings s) => s.TooManyDependenciesMaximumEnabled); } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters