Skip to content

Commit 59f785b

Browse files
committed
closes #431
1 parent ca7d42d commit 59f785b

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

RetailCoder.VBE/Inspections/ObsoleteCallStatementInspection.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using Rubberduck.Parsing;
44
using Rubberduck.Parsing.Grammar;
5+
using Rubberduck.Parsing.Symbols;
56

67
namespace Rubberduck.Inspections
78
{
@@ -18,11 +19,22 @@ public ObsoleteCallStatementInspection()
1819

1920
public IEnumerable<CodeInspectionResultBase> GetInspectionResults(VBProjectParseResult parseResult)
2021
{
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);
2638

2739
return issues;
2840
}

RetailCoder.VBE/Inspections/ObsoleteCallStatementUsageInspectionResult.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ public override IDictionary<string, Action<VBE>> GetQuickFixes()
2828

2929
private void RemoveObsoleteStatement(VBE vbe)
3030
{
31-
var module = vbe.FindCodeModule(QualifiedName);
32-
if (module == null)
33-
{
34-
return;
35-
}
31+
var module = QualifiedName.Component.CodeModule;
3632

3733
var selection = Context.GetSelection();
3834
var originalCodeLines = module.get_Lines(selection.StartLine, selection.LineCount);

0 commit comments

Comments
 (0)