@@ -148,7 +148,23 @@ private void OnOkButtonClicked(object sender, EventArgs e)
148
148
149
149
// must rename usages first; if target is a module or a project,
150
150
// then renaming the declaration first would invalidate the parse results.
151
- RenameUsages ( _view . Target ) ;
151
+
152
+ if ( _view . Target . DeclarationType . HasFlag ( DeclarationType . Property ) )
153
+ {
154
+ // properties can have more than 1 member.
155
+ var members = _declarations [ _view . Target . IdentifierName ]
156
+ . Where ( item => item . Project == _view . Target . Project
157
+ && item . ComponentName == _view . Target . ComponentName
158
+ && item . DeclarationType . HasFlag ( DeclarationType . Property ) ) ;
159
+ foreach ( var member in members )
160
+ {
161
+ RenameUsages ( member ) ;
162
+ }
163
+ }
164
+ else
165
+ {
166
+ RenameUsages ( _view . Target ) ;
167
+ }
152
168
153
169
if ( ModuleDeclarationTypes . Contains ( _view . Target . DeclarationType ) )
154
170
{
@@ -228,10 +244,23 @@ private void RenameDeclaration()
228
244
module . ReplaceLine ( argList . Start . Line , newContent ) ;
229
245
module . DeleteLines ( argList . Start . Line + 1 , lineNum - 1 ) ;
230
246
}
231
- else
247
+ else if ( ! _view . Target . DeclarationType . HasFlag ( DeclarationType . Property ) )
232
248
{
233
249
module . ReplaceLine ( _view . Target . Selection . StartLine , newContent ) ;
234
250
}
251
+ else
252
+ {
253
+ var members = _declarations [ _view . Target . IdentifierName ]
254
+ . Where ( item => item . Project == _view . Target . Project
255
+ && item . ComponentName == _view . Target . ComponentName
256
+ && item . DeclarationType . HasFlag ( DeclarationType . Property ) ) ;
257
+
258
+ foreach ( var member in members )
259
+ {
260
+ newContent = GetReplacementLine ( module , member , _view . NewName ) ;
261
+ module . ReplaceLine ( member . Selection . StartLine , newContent ) ;
262
+ }
263
+ }
235
264
}
236
265
237
266
private void RenameControl ( )
@@ -354,23 +383,23 @@ private string GetReplacementLine(string content, string target, string newName,
354
383
355
384
private string GetReplacementLine ( CodeModule module , Declaration target , string newName )
356
385
{
357
- var targetModule = _parseResult . ComponentParseResults . SingleOrDefault ( m => m . QualifiedName == _view . Target . QualifiedName . QualifiedModuleName ) ;
386
+ var targetModule = _parseResult . ComponentParseResults . SingleOrDefault ( m => m . QualifiedName == target . QualifiedName . QualifiedModuleName ) ;
358
387
if ( targetModule == null )
359
388
{
360
389
return null ;
361
390
}
362
391
363
- var content = module . Lines [ _view . Target . Selection . StartLine , 1 ] ;
392
+ var content = module . Lines [ target . Selection . StartLine , 1 ] ;
364
393
365
394
if ( target . DeclarationType == DeclarationType . Parameter )
366
395
{
367
- var argContext = ( VBAParser . ArgContext ) _view . Target . Context ;
396
+ var argContext = ( VBAParser . ArgContext ) target . Context ;
368
397
var rewriter = targetModule . GetRewriter ( ) ;
369
398
rewriter . Replace ( argContext . ambiguousIdentifier ( ) . Start . TokenIndex , _view . NewName ) ;
370
399
371
400
// Target.Context is an ArgContext, its parent is an ArgsListContext;
372
401
// the ArgsListContext's parent is the procedure context and it includes the body.
373
- var context = ( ParserRuleContext ) _view . Target . Context . Parent . Parent ;
402
+ var context = ( ParserRuleContext ) target . Context . Parent . Parent ;
374
403
var firstTokenIndex = context . Start . TokenIndex ;
375
404
var lastTokenIndex = - 1 ; // will blow up if this code runs for any context other than below
376
405
@@ -511,3 +540,4 @@ private bool IsSelectedDeclaration(QualifiedSelection selection, Declaration dec
511
540
}
512
541
}
513
542
}
543
+
0 commit comments