Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
retailcoder committed May 5, 2015
1 parent ca7d42d commit 59f785b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
22 changes: 17 additions & 5 deletions RetailCoder.VBE/Inspections/ObsoleteCallStatementInspection.cs
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using Rubberduck.Parsing;
using Rubberduck.Parsing.Grammar;
using Rubberduck.Parsing.Symbols;

namespace Rubberduck.Inspections
{
Expand All @@ -18,11 +19,22 @@ public ObsoleteCallStatementInspection()

public IEnumerable<CodeInspectionResultBase> GetInspectionResults(VBProjectParseResult parseResult)
{
// bug: will miss procedures not defined in project
var issues = parseResult.Declarations.Items.SelectMany(declaration =>
declaration.References.Where(reference => reference.HasExplicitCallStatement()))
.Select(issue => new ObsoleteCallStatementUsageInspectionResult(Name, Severity,
new QualifiedContext<VBAParser.ExplicitCallStmtContext>(issue.QualifiedModuleName, issue.Context.Parent as VBAParser.ExplicitCallStmtContext)));
//note: this misses calls to procedures/functions without a Declaration object.
// alternative is to walk the tree and listen for "CallStmt".

var calls = (from declaration in parseResult.Declarations.Items
from reference in declaration.References
where (reference.Declaration.DeclarationType == DeclarationType.Function
|| reference.Declaration.DeclarationType == DeclarationType.Procedure)
&& reference.HasExplicitCallStatement()
select reference).ToList();

var issues = from reference in calls
let context = reference.Context.Parent.Parent as VBAParser.ExplicitCallStmtContext
where context != null
let qualifiedContext = new QualifiedContext<VBAParser.ExplicitCallStmtContext>
(reference.QualifiedModuleName, (VBAParser.ExplicitCallStmtContext)reference.Context.Parent.Parent)
select new ObsoleteCallStatementUsageInspectionResult(Name, Severity, qualifiedContext);

return issues;
}
Expand Down
Expand Up @@ -28,11 +28,7 @@ public class ObsoleteCallStatementUsageInspectionResult : CodeInspectionResultBa

private void RemoveObsoleteStatement(VBE vbe)
{
var module = vbe.FindCodeModule(QualifiedName);
if (module == null)
{
return;
}
var module = QualifiedName.Component.CodeModule;

var selection = Context.GetSelection();
var originalCodeLines = module.get_Lines(selection.StartLine, selection.LineCount);
Expand Down

0 comments on commit 59f785b

Please sign in to comment.