2
2
using System . Linq ;
3
3
using Rubberduck . Parsing ;
4
4
using Rubberduck . Parsing . Grammar ;
5
+ using Rubberduck . Parsing . Symbols ;
5
6
6
7
namespace Rubberduck . Inspections
7
8
{
@@ -18,11 +19,22 @@ public ObsoleteCallStatementInspection()
18
19
19
20
public IEnumerable < CodeInspectionResultBase > GetInspectionResults ( VBProjectParseResult parseResult )
20
21
{
21
- // bug: will miss procedures not defined in project
22
- var issues = parseResult . Declarations . Items . SelectMany ( declaration =>
23
- declaration . References . Where ( reference => reference . HasExplicitCallStatement ( ) ) )
24
- . Select ( issue => new ObsoleteCallStatementUsageInspectionResult ( Name , Severity ,
25
- new QualifiedContext < VBAParser . ExplicitCallStmtContext > ( issue . QualifiedModuleName , issue . Context . Parent as VBAParser . ExplicitCallStmtContext ) ) ) ;
22
+ //note: this misses calls to procedures/functions without a Declaration object.
23
+ // alternative is to walk the tree and listen for "CallStmt".
24
+
25
+ var calls = ( from declaration in parseResult . Declarations . Items
26
+ from reference in declaration . References
27
+ where ( reference . Declaration . DeclarationType == DeclarationType . Function
28
+ || reference . Declaration . DeclarationType == DeclarationType . Procedure )
29
+ && reference . HasExplicitCallStatement ( )
30
+ select reference ) . ToList ( ) ;
31
+
32
+ var issues = from reference in calls
33
+ let context = reference . Context . Parent . Parent as VBAParser . ExplicitCallStmtContext
34
+ where context != null
35
+ let qualifiedContext = new QualifiedContext < VBAParser . ExplicitCallStmtContext >
36
+ ( reference . QualifiedModuleName , ( VBAParser . ExplicitCallStmtContext ) reference . Context . Parent . Parent )
37
+ select new ObsoleteCallStatementUsageInspectionResult ( Name , Severity , qualifiedContext ) ;
26
38
27
39
return issues ;
28
40
}
0 commit comments