Skip to content

Commit c6863a7

Browse files
committed
Omit controls from member not on interface inspection results. Ref #2592. Closes #3532
1 parent 3c002ee commit c6863a7

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/MemberNotOnInterfaceInspection.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2121

2222
var targets = Declarations.Where(decl => decl.AsTypeDeclaration != null &&
2323
!decl.AsTypeDeclaration.IsUserDefined &&
24-
decl.AsTypeDeclaration.DeclarationType.HasFlag(DeclarationType.ClassModule) &&
24+
decl.AsTypeDeclaration.DeclarationType.HasFlag(DeclarationType.ClassModule) &&
2525
((ClassModuleDeclaration)decl.AsTypeDeclaration).IsExtensible)
2626
.SelectMany(decl => decl.References).ToList();
2727
return unresolved
@@ -33,7 +33,8 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
3333
usage.Context.Parent.Parent.Equals(access.CallingContext))
3434
)
3535
})
36-
.Where(memberAccess => memberAccess.callingContext != null)
36+
.Where(memberAccess => memberAccess.callingContext != null &&
37+
memberAccess.callingContext.Declaration.DeclarationType != DeclarationType.Control) //TODO - remove this exception after resolving #2592)
3738
.Select(memberAccess => new DeclarationInspectionResult(this,
3839
string.Format(InspectionResults.MemberNotOnInterfaceInspection, memberAccess.access.IdentifierName,
3940
memberAccess.callingContext.Declaration.AsTypeDeclaration.IdentifierName), memberAccess.access));

RubberduckTests/Inspections/MemberNotOnInterfaceInspectionTests.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ End With
267267
//See https://github.com/rubberduck-vba/Rubberduck/issues/4308
268268
[Test]
269269
[Category("Inspections")]
270-
[Ignore("To be unignored in a PR fixing issue 4308.")]
270+
//[Ignore("To be unignored in a PR fixing issue 4308.")]
271271
public void MemberNotOnInterface_ProcedureArgument()
272272
{
273273
const string inputCode =
@@ -380,12 +380,28 @@ End Sub
380380

381381
[Test]
382382
[Category("Inspections")]
383-
public void InspectionName()
383+
public void MemberNotOnInterface_DoesNotReturnResult_ControlObject()
384384
{
385-
const string inspectionName = "MemberNotOnInterfaceInspection";
386-
var inspection = new MemberNotOnInterfaceInspection(null);
385+
const string inputCode =
386+
@"Sub Foo(bar as MSForms.TextBox)
387+
Debug.Print bar.Left
388+
End Sub";
389+
390+
var vbeBuilder = new MockVbeBuilder();
391+
var projectBuilder = vbeBuilder.ProjectBuilder("testproject", ProjectProtection.Unprotected);
392+
projectBuilder.MockUserFormBuilder("UserForm1", inputCode).AddFormToProjectBuilder()
393+
.AddReference("MSForms", MockVbeBuilder.LibraryPathMsForms, 2, 0, true);
387394

388-
Assert.AreEqual(inspectionName, inspection.Name);
395+
vbeBuilder.AddProject(projectBuilder.Build());
396+
var vbe = vbeBuilder.Build();
397+
398+
using (var state = MockParser.CreateAndParse(vbe.Object))
399+
{
400+
var inspection = new MemberNotOnInterfaceInspection(state);
401+
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);
402+
403+
Assert.IsTrue(!inspectionResults.Any());
404+
}
389405
}
390406
}
391407
}

0 commit comments

Comments
 (0)