|
1 | 1 | using Rubberduck.Inspections.Abstract;
|
2 |
| -using Rubberduck.Inspections.Results; |
3 |
| -using Rubberduck.Parsing.Inspections.Abstract; |
4 | 2 | using Rubberduck.Resources.Inspections;
|
5 |
| -using System.Collections.Generic; |
6 | 3 | using System.Linq;
|
7 | 4 | using Rubberduck.Parsing.Symbols;
|
8 | 5 | using Rubberduck.Inspections.Inspections.Extensions;
|
9 | 6 | using Rubberduck.Common;
|
10 |
| -using System; |
11 | 7 | using Rubberduck.Parsing.Annotations;
|
| 8 | +using Rubberduck.Parsing.VBA.DeclarationCaching; |
12 | 9 |
|
13 | 10 | namespace Rubberduck.Inspections.Concrete
|
14 | 11 | {
|
@@ -38,30 +35,49 @@ namespace Rubberduck.Inspections.Concrete
|
38 | 35 | /// End Sub
|
39 | 36 | /// ]]>
|
40 | 37 | /// </example>
|
41 |
| - internal class ImplementedInterfaceMemberInspection : InspectionBase |
| 38 | + internal class ImplementedInterfaceMemberInspection : DeclarationInspectionBase |
42 | 39 | {
|
43 | 40 | public ImplementedInterfaceMemberInspection(Parsing.VBA.RubberduckParserState state)
|
44 |
| - : base(state) { } |
| 41 | + : base(state, DeclarationType.ClassModule) |
| 42 | + {} |
45 | 43 |
|
46 |
| - protected override IEnumerable<IInspectionResult> DoGetInspectionResults() |
| 44 | + protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) |
47 | 45 | {
|
48 |
| - var annotatedAsInterface = State.DeclarationFinder.Classes |
49 |
| - .Where(cls => cls.Annotations.Any(an => an.Annotation is InterfaceAnnotation)).Cast<ClassModuleDeclaration>(); |
| 46 | + if (!IsInterfaceDeclaration(declaration)) |
| 47 | + { |
| 48 | + return false; |
| 49 | + } |
50 | 50 |
|
51 |
| - var implementedAndOrAnnotatedInterfaceModules = State.DeclarationFinder.FindAllUserInterfaces() |
52 |
| - .Union(annotatedAsInterface); |
| 51 | + var moduleBodyElements = finder.Members(declaration, DeclarationType.Member) |
| 52 | + .OfType<ModuleBodyElementDeclaration>(); |
53 | 53 |
|
54 |
| - return implementedAndOrAnnotatedInterfaceModules |
55 |
| - .SelectMany(interfaceModule => interfaceModule.Members |
56 |
| - .Where(member => ((ModuleBodyElementDeclaration)member).Block.ContainsExecutableStatements(true))) |
57 |
| - .Select(result => new DeclarationInspectionResult(this, |
58 |
| - string.Format(InspectionResults.ImplementedInterfaceMemberInspection, |
59 |
| - result.QualifiedModuleName.ToString(), |
60 |
| - Resources.RubberduckUI.ResourceManager |
61 |
| - .GetString("DeclarationType_" + result.DeclarationType) |
62 |
| - .Capitalize(), |
63 |
| - result.IdentifierName), |
64 |
| - result)); |
| 54 | + return moduleBodyElements |
| 55 | + .Any(member => member.Block.ContainsExecutableStatements(true)); |
| 56 | + } |
| 57 | + |
| 58 | + private static bool IsInterfaceDeclaration(Declaration declaration) |
| 59 | + { |
| 60 | + if (!(declaration is ClassModuleDeclaration classModule)) |
| 61 | + { |
| 62 | + return false; |
| 63 | + } |
| 64 | + return classModule.IsInterface |
| 65 | + || declaration.Annotations.Any(an => an.Annotation is InterfaceAnnotation); |
| 66 | + } |
| 67 | + |
| 68 | + protected override string ResultDescription(Declaration declaration) |
| 69 | + { |
| 70 | + var qualifiedName = declaration.QualifiedModuleName.ToString(); |
| 71 | + var declarationType = Resources.RubberduckUI.ResourceManager |
| 72 | + .GetString("DeclarationType_" + declaration.DeclarationType) |
| 73 | + .Capitalize(); |
| 74 | + var identifierName = declaration.IdentifierName; |
| 75 | + |
| 76 | + return string.Format( |
| 77 | + InspectionResults.ImplementedInterfaceMemberInspection, |
| 78 | + qualifiedName, |
| 79 | + declarationType, |
| 80 | + identifierName); |
65 | 81 | }
|
66 | 82 | }
|
67 | 83 | }
|
0 commit comments