@@ -148,23 +148,7 @@ 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
-
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
- }
151
+ RenameUsages ( _view . Target ) ;
168
152
169
153
if ( ModuleDeclarationTypes . Contains ( _view . Target . DeclarationType ) )
170
154
{
@@ -244,22 +228,9 @@ private void RenameDeclaration()
244
228
module . ReplaceLine ( argList . Start . Line , newContent ) ;
245
229
module . DeleteLines ( argList . Start . Line + 1 , lineNum - 1 ) ;
246
230
}
247
- else if ( ! _view . Target . DeclarationType . HasFlag ( DeclarationType . Property ) )
248
- {
249
- module . ReplaceLine ( _view . Target . Selection . StartLine , newContent ) ;
250
- }
251
231
else
252
232
{
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
- }
233
+ module . ReplaceLine ( _view . Target . Selection . StartLine , newContent ) ;
263
234
}
264
235
}
265
236
@@ -268,7 +239,7 @@ private void RenameControl()
268
239
try
269
240
{
270
241
var form = _view . Target . QualifiedName . QualifiedModuleName . Component . CodeModule ;
271
- var control = ( ( dynamic ) form . Parent . Designer ) . Controls ( _view . Target . IdentifierName ) ;
242
+ var control = ( ( dynamic ) form . Parent . Designer ) . Controls ( _view . Target . IdentifierName ) ;
272
243
273
244
foreach ( var handler in _declarations . FindEventHandlers ( _view . Target ) )
274
245
{
@@ -376,30 +347,30 @@ private string GetReplacementLine(string content, string target, string newName,
376
347
// this is going to have to be done the ugly way...
377
348
378
349
// todo: come back after the identifier references are fixed
379
- // var contentWithoutOldName = content.Remove(selection.StartColumn - 1, selection.EndColumn - selection.StartColumn);
380
- // return contentWithoutOldName.Insert(selection.StartColumn - 1, newName);
381
- return Regex . Replace ( content , "\\ b" + target + "\\ b" , newName ) ;
350
+ var contentWithoutOldName = content . Remove ( selection . StartColumn - 1 , selection . EndColumn - selection . StartColumn ) ;
351
+ return contentWithoutOldName . Insert ( selection . StartColumn - 1 , newName ) ;
352
+ // return Regex.Replace(content, "\\b" + target + "\\b", newName);
382
353
}
383
354
384
355
private string GetReplacementLine ( CodeModule module , Declaration target , string newName )
385
356
{
386
- var targetModule = _parseResult . ComponentParseResults . SingleOrDefault ( m => m . QualifiedName == target . QualifiedName . QualifiedModuleName ) ;
357
+ var targetModule = _parseResult . ComponentParseResults . SingleOrDefault ( m => m . QualifiedName == _view . Target . QualifiedName . QualifiedModuleName ) ;
387
358
if ( targetModule == null )
388
359
{
389
360
return null ;
390
361
}
391
362
392
- var content = module . Lines [ target . Selection . StartLine , 1 ] ;
363
+ var content = module . Lines [ _view . Target . Selection . StartLine , 1 ] ;
393
364
394
365
if ( target . DeclarationType == DeclarationType . Parameter )
395
366
{
396
- var argContext = ( VBAParser . ArgContext ) target . Context ;
367
+ var argContext = ( VBAParser . ArgContext ) _view . Target . Context ;
397
368
var rewriter = targetModule . GetRewriter ( ) ;
398
369
rewriter . Replace ( argContext . ambiguousIdentifier ( ) . Start . TokenIndex , _view . NewName ) ;
399
370
400
371
// Target.Context is an ArgContext, its parent is an ArgsListContext;
401
372
// the ArgsListContext's parent is the procedure context and it includes the body.
402
- var context = ( ParserRuleContext ) target . Context . Parent . Parent ;
373
+ var context = ( ParserRuleContext ) _view . Target . Context . Parent . Parent ;
403
374
var firstTokenIndex = context . Start . TokenIndex ;
404
375
var lastTokenIndex = - 1 ; // will blow up if this code runs for any context other than below
405
376
@@ -412,8 +383,8 @@ private string GetReplacementLine(CodeModule module, Declaration target, string
412
383
var functionStmtContext = context as VBAParser . FunctionStmtContext ;
413
384
if ( functionStmtContext != null )
414
385
{
415
- lastTokenIndex = functionStmtContext . asTypeClause ( ) != null
416
- ? functionStmtContext . asTypeClause ( ) . Stop . TokenIndex
386
+ lastTokenIndex = functionStmtContext . asTypeClause ( ) != null
387
+ ? functionStmtContext . asTypeClause ( ) . Stop . TokenIndex
417
388
: functionStmtContext . argList ( ) . RPAREN ( ) . Symbol . TokenIndex ;
418
389
}
419
390
@@ -475,7 +446,7 @@ private void AcquireTarget(out Declaration target, QualifiedSelection selection)
475
446
{
476
447
target = _declarations . Items
477
448
. Where ( item => ! item . IsBuiltIn && item . DeclarationType != DeclarationType . ModuleOption )
478
- . FirstOrDefault ( item => IsSelectedDeclaration ( selection , item )
449
+ . FirstOrDefault ( item => IsSelectedDeclaration ( selection , item )
479
450
|| IsSelectedReference ( selection , item ) ) ;
480
451
481
452
PromptIfTargetImplementsInterface ( ref target ) ;
0 commit comments