@@ -116,33 +116,32 @@ private string BuildLocalCopyAssignment()
116
116
117
117
private IEnumerable < string > GetIdentifierNamesAccessibleToProcedureContext ( )
118
118
{
119
- var allIdentifiers = new HashSet < string > ( ) ;
120
-
121
- var allParametersAndLocalVariables = _parserState . AllUserDeclarations
119
+ var allSameProcedureDeclarations = _parserState . AllUserDeclarations
122
120
. Where ( item => item . ParentScope == _target . ParentScope )
123
121
. ToList ( ) ;
124
122
125
- allIdentifiers . UnionWith ( allParametersAndLocalVariables . Select ( d => d . IdentifierName ) ) ;
126
-
127
123
var sameModuleDeclarations = _parserState . AllUserDeclarations
128
124
. Where ( item => item . ComponentName == _target . ComponentName
129
- && ! IsProceduralContext ( item . ParentDeclaration . Context ) )
125
+ && ! IsDeclaredInMethodOrProperty ( item . ParentDeclaration . Context ) )
130
126
. ToList ( ) ;
131
127
132
- allIdentifiers . UnionWith ( sameModuleDeclarations . Select ( d => d . IdentifierName ) ) ;
133
-
134
- var allPublicDeclarations = _parserState . AllUserDeclarations
135
- . Where ( item => ( item . Accessibility == Accessibility . Public
136
- || ( ( item . Accessibility == Accessibility . Implicit )
137
- && item . ParentScopeDeclaration is ProceduralModuleDeclaration ) )
138
- && ! ( item . ParentScopeDeclaration is ClassModuleDeclaration ) )
128
+ var allGloballyAccessibleDeclarations = _parserState . AllUserDeclarations
129
+ . Where ( item => item . ProjectName == _target . ProjectName
130
+ && ! ( item . ParentScopeDeclaration is ClassModuleDeclaration )
131
+ && ( item . Accessibility == Accessibility . Public
132
+ || ( ( item . Accessibility == Accessibility . Implicit )
133
+ && item . ParentScopeDeclaration is ProceduralModuleDeclaration ) ) )
139
134
. ToList ( ) ;
140
135
141
- allIdentifiers . UnionWith ( allPublicDeclarations . Select ( d => d . IdentifierName ) ) ;
136
+ var accessibleIdentifierNames = new HashSet < string > ( ) ;
137
+ accessibleIdentifierNames . UnionWith ( allSameProcedureDeclarations . Select ( d => d . IdentifierName ) ) ;
138
+ accessibleIdentifierNames . UnionWith ( sameModuleDeclarations . Select ( d => d . IdentifierName ) ) ;
139
+ accessibleIdentifierNames . UnionWith ( allGloballyAccessibleDeclarations . Select ( d => d . IdentifierName ) ) ;
142
140
143
- return allIdentifiers . ToList ( ) ;
141
+ return accessibleIdentifierNames . ToList ( ) ;
144
142
}
145
- private bool IsProceduralContext ( RuleContext context )
143
+
144
+ private bool IsDeclaredInMethodOrProperty ( RuleContext context )
146
145
{
147
146
if ( context is VBAParser . SubStmtContext )
148
147
{
0 commit comments