1
- using Antlr4 . Runtime ;
1
+ using System . Collections . Generic ;
2
+ using System . Linq ;
2
3
using Rubberduck . Inspections . Abstract ;
4
+ using Rubberduck . Inspections . Results ;
3
5
using Rubberduck . Parsing ;
4
- using Rubberduck . Parsing . Grammar ;
6
+ using Rubberduck . Parsing . Annotations ;
5
7
using Rubberduck . Parsing . Inspections . Abstract ;
8
+ using Rubberduck . Parsing . Symbols ;
6
9
using Rubberduck . Resources . Inspections ;
7
10
using Rubberduck . Parsing . VBA ;
8
- using Rubberduck . Parsing . VBA . Parsing ;
11
+ using Rubberduck . Parsing . VBA . DeclarationCaching ;
12
+ using Rubberduck . VBEditor ;
9
13
10
14
namespace Rubberduck . Inspections . Concrete
11
15
{
@@ -31,48 +35,57 @@ namespace Rubberduck.Inspections.Concrete
31
35
/// ' ...
32
36
/// ]]>
33
37
/// </example>
34
- public sealed class MissingAnnotationArgumentInspection : ParseTreeInspectionBase
38
+ public sealed class MissingAnnotationArgumentInspection : InspectionBase
35
39
{
36
- private readonly RubberduckParserState _state ;
40
+ public MissingAnnotationArgumentInspection ( IDeclarationFinderProvider declarationFinderProvider )
41
+ : base ( declarationFinderProvider )
42
+ { }
37
43
38
- public MissingAnnotationArgumentInspection ( RubberduckParserState state )
39
- : base ( state )
44
+ protected override IEnumerable < IInspectionResult > DoGetInspectionResults ( )
40
45
{
41
- _state = state ;
46
+ var finder = DeclarationFinderProvider . DeclarationFinder ;
47
+
48
+ return finder . UserDeclarations ( DeclarationType . Module )
49
+ . Where ( module => module != null )
50
+ . SelectMany ( module => DoGetInspectionResults ( module . QualifiedModuleName , finder ) )
51
+ . ToList ( ) ;
42
52
}
43
53
44
- public override CodeKind TargetKindOfCode => CodeKind . AttributesCode ;
54
+ protected override IEnumerable < IInspectionResult > DoGetInspectionResults ( QualifiedModuleName module )
55
+ {
56
+ var finder = DeclarationFinderProvider . DeclarationFinder ;
57
+ return DoGetInspectionResults ( module , finder ) ;
58
+ }
59
+
60
+ private IEnumerable < IInspectionResult > DoGetInspectionResults ( QualifiedModuleName module , DeclarationFinder finder )
61
+ {
62
+ var objectionableAnnotations = finder . FindAnnotations ( module )
63
+ . Where ( IsResultAnnotation ) ;
45
64
46
- public override IInspectionListener Listener { get ; } =
47
- new InvalidAnnotationStatementListener ( ) ;
65
+ return objectionableAnnotations
66
+ . Select ( InspectionResult )
67
+ . ToList ( ) ;
68
+ }
48
69
49
- protected override string ResultDescription ( QualifiedContext < ParserRuleContext > context )
70
+ private static bool IsResultAnnotation ( IParseTreeAnnotation pta )
50
71
{
51
- var expressionText = ( ( VBAParser . AnnotationContext ) context . Context ) . annotationName ( ) . GetText ( ) ;
52
- return string . Format (
53
- InspectionResults . MissingAnnotationArgumentInspection ,
54
- expressionText ) ;
72
+ return pta . Annotation . RequiredArguments > pta . AnnotationArguments . Count ;
55
73
}
56
74
57
- protected override bool IsResultContext ( QualifiedContext < ParserRuleContext > context )
75
+ private IInspectionResult InspectionResult ( IParseTreeAnnotation pta )
58
76
{
59
- // FIXME don't actually use listeners here, iterate the Annotations instead
60
- // FIXME don't maintain a separate list for annotations that require arguments, instead use AnnotationAttribute to store that information
61
- var annotationContext = ( VBAParser . AnnotationContext ) context . Context ;
62
- return ( annotationContext . annotationName ( ) . GetText ( ) == "Ignore"
63
- || annotationContext . annotationName ( ) . GetText ( ) == "Folder" )
64
- && annotationContext . annotationArgList ( ) == null ;
77
+ var qualifiedContext = new QualifiedContext ( pta . QualifiedSelection . QualifiedName , pta . Context ) ;
78
+ return new QualifiedContextInspectionResult (
79
+ this ,
80
+ ResultDescription ( pta ) ,
81
+ qualifiedContext ) ;
65
82
}
66
83
67
- public class InvalidAnnotationStatementListener : InspectionListenerBase
84
+ private static string ResultDescription ( IParseTreeAnnotation pta )
68
85
{
69
- public override void ExitAnnotation ( VBAParser . AnnotationContext context )
70
- {
71
- if ( context . annotationName ( ) != null )
72
- {
73
- SaveContext ( context ) ;
74
- }
75
- }
86
+ return string . Format (
87
+ InspectionResults . MissingAnnotationArgumentInspection ,
88
+ pta . Annotation . Name ) ;
76
89
}
77
90
}
78
91
}
0 commit comments