@@ -28,7 +28,6 @@ public IllegalAnnotationInspection(RubberduckParserState state)
2828
2929 public override CodeInspectionType InspectionType => CodeInspectionType . RubberduckOpportunities ;
3030 public override IInspectionListener Listener { get ; }
31- public override ParsePass Pass => ParsePass . AttributesPass ;
3231
3332 public override IEnumerable < IInspectionResult > GetInspectionResults ( )
3433 {
@@ -39,10 +38,11 @@ public override IEnumerable<IInspectionResult> GetInspectionResults()
3938
4039 public class IllegalAttributeAnnotationsListener : VBAParserBaseListener , IInspectionListener
4140 {
42- private readonly IDictionary < AnnotationType , int > _annotationCounts ;
43-
4441 private static readonly AnnotationType [ ] AnnotationTypes = Enum . GetValues ( typeof ( AnnotationType ) ) . Cast < AnnotationType > ( ) . ToArray ( ) ;
4542
43+ private IDictionary < Tuple < QualifiedModuleName , AnnotationType > , int > _annotationCounts =
44+ new Dictionary < Tuple < QualifiedModuleName , AnnotationType > , int > ( ) ;
45+
4646 private readonly RubberduckParserState _state ;
4747
4848 private Lazy < Declaration > _module ;
@@ -51,32 +51,39 @@ public class IllegalAttributeAnnotationsListener : VBAParserBaseListener, IInspe
5151 public IllegalAttributeAnnotationsListener ( RubberduckParserState state )
5252 {
5353 _state = state ;
54- _annotationCounts = AnnotationTypes . ToDictionary ( a => a , a => 0 ) ;
5554 }
5655
5756 private readonly List < QualifiedContext < ParserRuleContext > > _contexts =
5857 new List < QualifiedContext < ParserRuleContext > > ( ) ;
5958
6059 public IReadOnlyList < QualifiedContext < ParserRuleContext > > Contexts => _contexts ;
6160
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+ }
6373
6474 private bool _isFirstMemberProcessed ;
6575
6676 public void ClearContexts ( )
6777 {
78+ _annotationCounts = new Dictionary < Tuple < QualifiedModuleName , AnnotationType > , int > ( ) ;
6879 _contexts . Clear ( ) ;
6980 _isFirstMemberProcessed = false ;
70- var keys = _annotationCounts . Keys . ToList ( ) ;
71- foreach ( var key in keys )
72- {
73- _annotationCounts [ key ] = 0 ;
74- }
7581 }
7682
7783 #region scoping
7884 private Declaration _currentScopeDeclaration ;
7985 private bool _hasMembers ;
86+ private QualifiedModuleName _currentModuleName ;
8087
8188 private void SetCurrentScope ( string memberName = null )
8289 {
@@ -160,7 +167,8 @@ public override void ExitAnnotation(VBAParser.AnnotationContext context)
160167 {
161168 var name = Identifier . GetName ( context . annotationName ( ) . unrestrictedIdentifier ( ) ) ;
162169 var annotationType = ( AnnotationType ) Enum . Parse ( typeof ( AnnotationType ) , name ) ;
163- _annotationCounts [ annotationType ] ++ ;
170+ var key = Tuple . Create ( _currentModuleName , annotationType ) ;
171+ _annotationCounts [ key ] ++ ;
164172
165173 var moduleHasMembers = _members . Value . Any ( ) ;
166174
@@ -174,7 +182,7 @@ public override void ExitAnnotation(VBAParser.AnnotationContext context)
174182 && ( _currentScopeDeclaration ? . DeclarationType . HasFlag ( DeclarationType . Member ) ?? false ) ;
175183
176184 var isIllegal = ! ( isMemberAnnotation && moduleHasMembers && ! _isFirstMemberProcessed ) &&
177- ( isModuleAnnotation && _annotationCounts [ annotationType ] > 1
185+ ( isModuleAnnotation && _annotationCounts [ key ] > 1
178186 || isMemberAnnotatedForModuleAnnotation
179187 || isModuleAnnotatedForMemberAnnotation ) ;
180188
0 commit comments