9
9
10
10
namespace Rubberduck . Inspections . Abstract
11
11
{
12
- public abstract class DeclarationInspectionBase : InspectionBase
12
+ public abstract class DeclarationInspectionBase : DeclarationInspectionBaseBase
13
13
{
14
- protected readonly DeclarationType [ ] RelevantDeclarationTypes ;
15
- protected readonly DeclarationType [ ] ExcludeDeclarationTypes ;
16
-
17
14
protected DeclarationInspectionBase ( RubberduckParserState state , params DeclarationType [ ] relevantDeclarationTypes )
18
- : base ( state )
19
- {
20
- RelevantDeclarationTypes = relevantDeclarationTypes ;
21
- ExcludeDeclarationTypes = new DeclarationType [ 0 ] ;
22
- }
15
+ : base ( state , relevantDeclarationTypes )
16
+ { }
23
17
24
18
protected DeclarationInspectionBase ( RubberduckParserState state , DeclarationType [ ] relevantDeclarationTypes , DeclarationType [ ] excludeDeclarationTypes )
25
- : base ( state )
26
- {
27
- RelevantDeclarationTypes = relevantDeclarationTypes ;
28
- ExcludeDeclarationTypes = excludeDeclarationTypes ;
29
- }
19
+ : base ( state , relevantDeclarationTypes , excludeDeclarationTypes )
20
+ { }
30
21
31
22
protected abstract bool IsResultDeclaration ( Declaration declaration , DeclarationFinder finder ) ;
32
23
protected abstract string ResultDescription ( Declaration declaration ) ;
33
24
34
25
protected virtual ICollection < string > DisabledQuickFixes ( Declaration declaration ) => new List < string > ( ) ;
35
26
36
- protected override IEnumerable < IInspectionResult > DoGetInspectionResults ( )
37
- {
38
- var finder = DeclarationFinderProvider . DeclarationFinder ;
39
-
40
- var results = new List < IInspectionResult > ( ) ;
41
- foreach ( var moduleDeclaration in State . DeclarationFinder . UserDeclarations ( DeclarationType . Module ) )
42
- {
43
- if ( moduleDeclaration == null )
44
- {
45
- continue ;
46
- }
47
-
48
- var module = moduleDeclaration . QualifiedModuleName ;
49
- results . AddRange ( DoGetInspectionResults ( module , finder ) ) ;
50
- }
51
-
52
- return results ;
53
- }
54
-
55
- private IEnumerable < IInspectionResult > DoGetInspectionResults ( QualifiedModuleName module )
56
- {
57
- var finder = DeclarationFinderProvider . DeclarationFinder ;
58
- return DoGetInspectionResults ( module , finder ) ;
59
- }
60
-
61
- private IEnumerable < IInspectionResult > DoGetInspectionResults ( QualifiedModuleName module , DeclarationFinder finder )
27
+ protected override IEnumerable < IInspectionResult > DoGetInspectionResults ( QualifiedModuleName module , DeclarationFinder finder )
62
28
{
63
29
var objectionableDeclarations = RelevantDeclarationsInModule ( module , finder )
64
30
. Where ( declaration => IsResultDeclaration ( declaration , finder ) ) ;
@@ -68,17 +34,6 @@ private IEnumerable<IInspectionResult> DoGetInspectionResults(QualifiedModuleNam
68
34
. ToList ( ) ;
69
35
}
70
36
71
- protected virtual IEnumerable < Declaration > RelevantDeclarationsInModule ( QualifiedModuleName module , DeclarationFinder finder )
72
- {
73
- var potentiallyRelevantDeclarations = RelevantDeclarationTypes . Length == 0
74
- ? finder . AllUserDeclarations
75
- : RelevantDeclarationTypes
76
- . SelectMany ( declarationType => finder . Members ( module , declarationType ) )
77
- . Distinct ( ) ;
78
- return potentiallyRelevantDeclarations
79
- . Where ( declaration => ! ExcludeDeclarationTypes . Contains ( declaration . DeclarationType ) ) ;
80
- }
81
-
82
37
protected virtual IInspectionResult InspectionResult ( Declaration declaration )
83
38
{
84
39
return new DeclarationInspectionResult (
@@ -89,56 +44,22 @@ protected virtual IInspectionResult InspectionResult(Declaration declaration)
89
44
}
90
45
}
91
46
92
- public abstract class DeclarationInspectionBase < T > : InspectionBase
47
+ public abstract class DeclarationInspectionBase < T > : DeclarationInspectionBaseBase
93
48
{
94
- protected readonly DeclarationType [ ] RelevantDeclarationTypes ;
95
- protected readonly DeclarationType [ ] ExcludeDeclarationTypes ;
96
-
97
49
protected DeclarationInspectionBase ( RubberduckParserState state , params DeclarationType [ ] relevantDeclarationTypes )
98
- : base ( state )
99
- {
100
- RelevantDeclarationTypes = relevantDeclarationTypes ;
101
- ExcludeDeclarationTypes = new DeclarationType [ 0 ] ;
102
- }
50
+ : base ( state , relevantDeclarationTypes )
51
+ { }
103
52
104
53
protected DeclarationInspectionBase ( RubberduckParserState state , DeclarationType [ ] relevantDeclarationTypes , DeclarationType [ ] excludeDeclarationTypes )
105
- : base ( state )
106
- {
107
- RelevantDeclarationTypes = relevantDeclarationTypes ;
108
- ExcludeDeclarationTypes = excludeDeclarationTypes ;
109
- }
54
+ : base ( state , relevantDeclarationTypes , excludeDeclarationTypes )
55
+ { }
110
56
111
57
protected abstract ( bool isResult , T properties ) IsResultDeclarationWithAdditionalProperties ( Declaration declaration , DeclarationFinder finder ) ;
112
58
protected abstract string ResultDescription ( Declaration declaration , T properties ) ;
113
59
114
60
protected virtual ICollection < string > DisabledQuickFixes ( Declaration declaration , T properties ) => new List < string > ( ) ;
115
61
116
- protected override IEnumerable < IInspectionResult > DoGetInspectionResults ( )
117
- {
118
- var finder = DeclarationFinderProvider . DeclarationFinder ;
119
-
120
- var results = new List < IInspectionResult > ( ) ;
121
- foreach ( var moduleDeclaration in State . DeclarationFinder . UserDeclarations ( DeclarationType . Module ) )
122
- {
123
- if ( moduleDeclaration == null )
124
- {
125
- continue ;
126
- }
127
-
128
- var module = moduleDeclaration . QualifiedModuleName ;
129
- results . AddRange ( DoGetInspectionResults ( module , finder ) ) ;
130
- }
131
-
132
- return results ;
133
- }
134
-
135
- private IEnumerable < IInspectionResult > DoGetInspectionResults ( QualifiedModuleName module )
136
- {
137
- var finder = DeclarationFinderProvider . DeclarationFinder ;
138
- return DoGetInspectionResults ( module , finder ) ;
139
- }
140
-
141
- private IEnumerable < IInspectionResult > DoGetInspectionResults ( QualifiedModuleName module , DeclarationFinder finder )
62
+ protected override IEnumerable < IInspectionResult > DoGetInspectionResults ( QualifiedModuleName module , DeclarationFinder finder )
142
63
{
143
64
var objectionableDeclarationsWithAdditionalProperties = RelevantDeclarationsInModule ( module , finder )
144
65
. Select ( declaration => ( declaration , IsResultDeclarationWithAdditionalProperties ( declaration , finder ) ) )
@@ -150,17 +71,6 @@ private IEnumerable<IInspectionResult> DoGetInspectionResults(QualifiedModuleNam
150
71
. ToList ( ) ;
151
72
}
152
73
153
- protected virtual IEnumerable < Declaration > RelevantDeclarationsInModule ( QualifiedModuleName module , DeclarationFinder finder )
154
- {
155
- var potentiallyRelevantDeclarations = RelevantDeclarationTypes . Length == 0
156
- ? finder . AllUserDeclarations
157
- : RelevantDeclarationTypes
158
- . SelectMany ( declarationType => finder . Members ( module , declarationType ) )
159
- . Distinct ( ) ;
160
- return potentiallyRelevantDeclarations
161
- . Where ( declaration => ! ExcludeDeclarationTypes . Contains ( declaration . DeclarationType ) ) ;
162
- }
163
-
164
74
protected virtual IInspectionResult InspectionResult ( Declaration declaration , T properties )
165
75
{
166
76
return new DeclarationInspectionResult < T > (
0 commit comments