6
6
using System . Collections . Generic ;
7
7
using System . Linq ;
8
8
using Rubberduck . Parsing . Symbols ;
9
- using Rubberduck . Inspections . Inspections . Extensions ;
10
9
using Rubberduck . Common ;
10
+ using Rubberduck . Inspections . Inspections . Extensions ;
11
+ using Rubberduck . Parsing . VBA . DeclarationCaching ;
12
+ using Rubberduck . Parsing . VBA . Extensions ;
13
+ using Rubberduck . VBEditor ;
11
14
12
15
namespace Rubberduck . Inspections . Concrete
13
16
{
@@ -39,19 +42,48 @@ public EmptyMethodInspection(RubberduckParserState state)
39
42
40
43
protected override IEnumerable < IInspectionResult > DoGetInspectionResults ( )
41
44
{
42
- var allInterfaces = new HashSet < ClassModuleDeclaration > ( State . DeclarationFinder . FindAllUserInterfaces ( ) ) ;
43
-
44
- return State . DeclarationFinder . UserDeclarations ( DeclarationType . Member )
45
- . Where ( member => ! allInterfaces . Any ( userInterface => userInterface . QualifiedModuleName == member . QualifiedModuleName )
46
- && ! ( member is ModuleBodyElementDeclaration mbe && mbe . Block . ContainsExecutableStatements ( ) ) )
47
-
48
- . Select ( result => new DeclarationInspectionResult ( this ,
49
- string . Format ( InspectionResults . EmptyMethodInspection ,
50
- Resources . RubberduckUI . ResourceManager
51
- . GetString ( "DeclarationType_" + result . DeclarationType )
52
- . Capitalize ( ) ,
53
- result . IdentifierName ) ,
54
- result ) ) ;
45
+ var finder = State . DeclarationFinder ;
46
+
47
+ var userInterfaces = UserInterfaces ( finder ) ;
48
+ var emptyMethods = EmptyNonInterfaceMethods ( finder , userInterfaces ) ;
49
+
50
+ return emptyMethods . Select ( Result ) ;
51
+ }
52
+
53
+ private static ICollection < QualifiedModuleName > UserInterfaces ( DeclarationFinder finder )
54
+ {
55
+ return finder
56
+ . FindAllUserInterfaces ( )
57
+ . Select ( decl => decl . QualifiedModuleName )
58
+ . ToHashSet ( ) ;
59
+ }
60
+
61
+ private static IEnumerable < Declaration > EmptyNonInterfaceMethods ( DeclarationFinder finder , ICollection < QualifiedModuleName > userInterfaces )
62
+ {
63
+ return finder
64
+ . UserDeclarations ( DeclarationType . Member )
65
+ . Where ( member => ! userInterfaces . Contains ( member . QualifiedModuleName )
66
+ && member is ModuleBodyElementDeclaration moduleBodyElement
67
+ && ! moduleBodyElement . Block . ContainsExecutableStatements ( ) ) ;
68
+ }
69
+
70
+ private IInspectionResult Result ( Declaration member )
71
+ {
72
+ return new DeclarationInspectionResult (
73
+ this ,
74
+ ResultDescription ( member ) ,
75
+ member ) ;
76
+ }
77
+
78
+ private static string ResultDescription ( Declaration member )
79
+ {
80
+ var identifierName = member . IdentifierName ;
81
+ var declarationType = member . DeclarationType . ToLocalizedString ( ) ;
82
+
83
+ return string . Format (
84
+ InspectionResults . EmptyMethodInspection ,
85
+ declarationType ,
86
+ identifierName ) ;
55
87
}
56
88
}
57
89
}
0 commit comments