-
Notifications
You must be signed in to change notification settings - Fork 296
/
MemberNotOnInterfaceInspection.cs
42 lines (39 loc) · 2.25 KB
/
MemberNotOnInterfaceInspection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System.Collections.Generic;
using System.Linq;
using Rubberduck.Inspections.Abstract;
using Rubberduck.Inspections.Results;
using Rubberduck.Parsing.Grammar;
using Rubberduck.Parsing.Inspections.Abstract;
using Rubberduck.Resources.Inspections;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Parsing.VBA;
namespace Rubberduck.Inspections.Concrete
{
public sealed class MemberNotOnInterfaceInspection : InspectionBase
{
public MemberNotOnInterfaceInspection(RubberduckParserState state)
: base(state) { }
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
{
var unresolved = State.DeclarationFinder.UnresolvedMemberDeclarations.Where(decl => !IsIgnoringInspectionResultFor(decl, AnnotationName)).ToList();
var targets = Declarations.Where(decl => decl.AsTypeDeclaration != null &&
!decl.AsTypeDeclaration.IsUserDefined &&
decl.AsTypeDeclaration.DeclarationType.HasFlag(DeclarationType.ClassModule) &&
((ClassModuleDeclaration)decl.AsTypeDeclaration).IsExtensible)
.SelectMany(decl => decl.References).ToList();
return unresolved
.Select(access => new
{
access,
callingContext = targets.FirstOrDefault(usage => usage.Context.Equals(access.CallingContext)
|| (access.CallingContext is VBAParser.NewExprContext &&
usage.Context.Parent.Parent.Equals(access.CallingContext))
)
})
.Where(memberAccess => memberAccess.callingContext != null)
.Select(memberAccess => new DeclarationInspectionResult(this,
string.Format(InspectionResults.MemberNotOnInterfaceInspection, memberAccess.access.IdentifierName,
memberAccess.callingContext.Declaration.AsTypeDeclaration.IdentifierName), memberAccess.access));
}
}
}