1
- using System . Collections . Generic ;
2
- using System . Globalization ;
3
- using System . Linq ;
4
- using Rubberduck . Inspections . Abstract ;
5
- using Rubberduck . Inspections . Results ;
6
- using Rubberduck . JunkDrawer . Extensions ;
1
+ using Rubberduck . Inspections . Abstract ;
2
+ using Rubberduck . Inspections . Inspections . Extensions ;
7
3
using Rubberduck . Parsing . Grammar ;
8
- using Rubberduck . Parsing . Inspections . Abstract ;
9
4
using Rubberduck . Parsing . Symbols ;
10
5
using Rubberduck . Parsing . VBA ;
11
- using Rubberduck . Resources ;
6
+ using Rubberduck . Parsing . VBA . DeclarationCaching ;
12
7
13
8
namespace Rubberduck . Inspections . Concrete
14
9
{
@@ -35,41 +30,57 @@ namespace Rubberduck.Inspections.Concrete
35
30
/// End Sub
36
31
/// ]]>
37
32
/// </example>
38
- public sealed class IntegerDataTypeInspection : InspectionBase
33
+ public sealed class IntegerDataTypeInspection : DeclarationInspectionBase
39
34
{
40
- public IntegerDataTypeInspection ( RubberduckParserState state ) : base ( state )
41
- {
42
- }
35
+ public IntegerDataTypeInspection ( RubberduckParserState state )
36
+ : base ( state )
37
+ { }
43
38
44
- protected override IEnumerable < IInspectionResult > DoGetInspectionResults ( )
39
+ protected override bool IsResultDeclaration ( Declaration declaration , DeclarationFinder finder )
45
40
{
46
- var interfaceImplementationMembers = State . DeclarationFinder . FindAllInterfaceImplementingMembers ( ) . ToHashSet ( ) ;
41
+ if ( declaration . AsTypeName != Tokens . Integer )
42
+ {
43
+ return false ;
44
+ }
47
45
48
- var excludeParameterMembers = State . DeclarationFinder . FindEventHandlers ( ) . ToHashSet ( ) ;
49
- excludeParameterMembers . UnionWith ( interfaceImplementationMembers ) ;
46
+ switch ( declaration )
47
+ {
48
+ case ParameterDeclaration parameter :
49
+ return ParameterIsResult ( parameter , finder ) ;
50
+ case ModuleBodyElementDeclaration member :
51
+ return MethodIsResult ( member ) ;
52
+ default :
53
+ return declaration . DeclarationType != DeclarationType . LibraryFunction ;
54
+ }
55
+ }
50
56
51
- var result = UserDeclarations
52
- . Where ( declaration =>
53
- declaration . AsTypeName == Tokens . Integer &&
54
- ! interfaceImplementationMembers . Contains ( declaration ) &&
55
- declaration . DeclarationType != DeclarationType . LibraryFunction &&
56
- ( declaration . DeclarationType != DeclarationType . Parameter || IncludeParameterDeclaration ( declaration , excludeParameterMembers ) ) )
57
- . Select ( issue =>
58
- new DeclarationInspectionResult ( this ,
59
- string . Format ( Resources . Inspections . InspectionResults . IntegerDataTypeInspection ,
60
- RubberduckUI . ResourceManager . GetString ( $ "DeclarationType_{ issue . DeclarationType } ", CultureInfo . CurrentUICulture ) , issue . IdentifierName ) ,
61
- issue ) ) ;
57
+ private static bool ParameterIsResult ( ParameterDeclaration parameter , DeclarationFinder finder )
58
+ {
59
+ var enclosingMember = parameter . ParentDeclaration ;
60
+ if ( ! ( enclosingMember is ModuleBodyElementDeclaration member ) )
61
+ {
62
+ return false ;
63
+ }
62
64
63
- return result ;
65
+ return ! member . IsInterfaceImplementation
66
+ && member . DeclarationType != DeclarationType . LibraryFunction
67
+ && member . DeclarationType != DeclarationType . LibraryProcedure
68
+ && ! finder . FindEventHandlers ( ) . Contains ( member ) ;
64
69
}
65
70
66
- private static bool IncludeParameterDeclaration ( Declaration parameterDeclaration , ICollection < Declaration > parentDeclarationsToExclude )
71
+ private static bool MethodIsResult ( ModuleBodyElementDeclaration member )
67
72
{
68
- var parentDeclaration = parameterDeclaration . ParentDeclaration ;
73
+ return ! member . IsInterfaceImplementation ;
74
+ }
69
75
70
- return parentDeclaration . DeclarationType != DeclarationType . LibraryFunction &&
71
- parentDeclaration . DeclarationType != DeclarationType . LibraryProcedure &&
72
- ! parentDeclarationsToExclude . Contains ( parentDeclaration ) ;
76
+ protected override string ResultDescription ( Declaration declaration )
77
+ {
78
+ var declarationType = declaration . DeclarationType . ToLocalizedString ( ) ;
79
+ var declarationName = declaration . IdentifierName ;
80
+ return string . Format (
81
+ Resources . Inspections . InspectionResults . IntegerDataTypeInspection ,
82
+ declarationType ,
83
+ declarationName ) ;
73
84
}
74
85
}
75
86
}
0 commit comments