@@ -28,7 +28,6 @@ public IllegalAnnotationInspection(RubberduckParserState state)
28
28
29
29
public override CodeInspectionType InspectionType => CodeInspectionType . RubberduckOpportunities ;
30
30
public override IInspectionListener Listener { get ; }
31
- public override ParsePass Pass => ParsePass . AttributesPass ;
32
31
33
32
public override IEnumerable < IInspectionResult > GetInspectionResults ( )
34
33
{
@@ -39,10 +38,11 @@ public override IEnumerable<IInspectionResult> GetInspectionResults()
39
38
40
39
public class IllegalAttributeAnnotationsListener : VBAParserBaseListener , IInspectionListener
41
40
{
42
- private readonly IDictionary < AnnotationType , int > _annotationCounts ;
43
-
44
41
private static readonly AnnotationType [ ] AnnotationTypes = Enum . GetValues ( typeof ( AnnotationType ) ) . Cast < AnnotationType > ( ) . ToArray ( ) ;
45
42
43
+ private IDictionary < Tuple < QualifiedModuleName , AnnotationType > , int > _annotationCounts =
44
+ new Dictionary < Tuple < QualifiedModuleName , AnnotationType > , int > ( ) ;
45
+
46
46
private readonly RubberduckParserState _state ;
47
47
48
48
private Lazy < Declaration > _module ;
@@ -51,32 +51,39 @@ public class IllegalAttributeAnnotationsListener : VBAParserBaseListener, IInspe
51
51
public IllegalAttributeAnnotationsListener ( RubberduckParserState state )
52
52
{
53
53
_state = state ;
54
- _annotationCounts = AnnotationTypes . ToDictionary ( a => a , a => 0 ) ;
55
54
}
56
55
57
56
private readonly List < QualifiedContext < ParserRuleContext > > _contexts =
58
57
new List < QualifiedContext < ParserRuleContext > > ( ) ;
59
58
60
59
public IReadOnlyList < QualifiedContext < ParserRuleContext > > Contexts => _contexts ;
61
60
62
- public QualifiedModuleName CurrentModuleName { get ; set ; }
61
+ public QualifiedModuleName CurrentModuleName
62
+ {
63
+ get => _currentModuleName ;
64
+ set
65
+ {
66
+ _currentModuleName = value ;
67
+ foreach ( var type in AnnotationTypes )
68
+ {
69
+ _annotationCounts . Add ( Tuple . Create ( value , type ) , 0 ) ;
70
+ }
71
+ }
72
+ }
63
73
64
74
private bool _isFirstMemberProcessed ;
65
75
66
76
public void ClearContexts ( )
67
77
{
78
+ _annotationCounts = new Dictionary < Tuple < QualifiedModuleName , AnnotationType > , int > ( ) ;
68
79
_contexts . Clear ( ) ;
69
80
_isFirstMemberProcessed = false ;
70
- var keys = _annotationCounts . Keys . ToList ( ) ;
71
- foreach ( var key in keys )
72
- {
73
- _annotationCounts [ key ] = 0 ;
74
- }
75
81
}
76
82
77
83
#region scoping
78
84
private Declaration _currentScopeDeclaration ;
79
85
private bool _hasMembers ;
86
+ private QualifiedModuleName _currentModuleName ;
80
87
81
88
private void SetCurrentScope ( string memberName = null )
82
89
{
@@ -160,7 +167,8 @@ public override void ExitAnnotation(VBAParser.AnnotationContext context)
160
167
{
161
168
var name = Identifier . GetName ( context . annotationName ( ) . unrestrictedIdentifier ( ) ) ;
162
169
var annotationType = ( AnnotationType ) Enum . Parse ( typeof ( AnnotationType ) , name ) ;
163
- _annotationCounts [ annotationType ] ++ ;
170
+ var key = Tuple . Create ( _currentModuleName , annotationType ) ;
171
+ _annotationCounts [ key ] ++ ;
164
172
165
173
var moduleHasMembers = _members . Value . Any ( ) ;
166
174
@@ -174,7 +182,7 @@ public override void ExitAnnotation(VBAParser.AnnotationContext context)
174
182
&& ( _currentScopeDeclaration ? . DeclarationType . HasFlag ( DeclarationType . Member ) ?? false ) ;
175
183
176
184
var isIllegal = ! ( isMemberAnnotation && moduleHasMembers && ! _isFirstMemberProcessed ) &&
177
- ( isModuleAnnotation && _annotationCounts [ annotationType ] > 1
185
+ ( isModuleAnnotation && _annotationCounts [ key ] > 1
178
186
|| isMemberAnnotatedForModuleAnnotation
179
187
|| isModuleAnnotatedForMemberAnnotation ) ;
180
188
0 commit comments