Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename backing variable when renaming Getter/Setter #5566

Open
daFreeMan opened this issue Aug 21, 2020 · 2 comments
Open

Rename backing variable when renaming Getter/Setter #5566

daFreeMan opened this issue Aug 21, 2020 · 2 comments
Labels
enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. feature-refactorings refactoring-rename

Comments

@daFreeMan
Copy link
Contributor

Justification
Often, the backing variable of a Getter will have the same name as the method itself with the backing variable a member of a private type defined within the class. When renaming, it would be time efficient to do one rename/reparse to get both updated.

When renaming the Getter, the corresponding Setter/Letter is automatically renamed, so this would be an additional time savings/convenience.

Description
Using Refactor|Rename on a Public Property Get..., would cause the Duck to look at the line(s) assigning a value to the property name. If the backing variable (as a member of a Private Type) matches the name of the Public Property being "got", the backing variable name would be updated to match.

This could be a user configurable option, but I'd imagine that most people who use the Private Type method to make the backing variable names match the Getter/Setter names would want to keep them in sync, so that may be overkill

Additional context
An example:

Private Type TFoo
  bar as Long
  biff as Long
  fubar as Long
  frodo as long
End Type

Private this as TFoo

Public Property Get Bar() as Long
  Bar = this.bar
End Property
Public Property Let Bar(ByValue RHS as String)
  this.bar = RHS
End Property

Public Property Get Biff() as Long
  If isnull(this.fubar) Then
    Biff = Null
  ElseIf isnull(this.frodo) Then
    Biff = Null
  Else
    Biff = this.fubar + this.frodo
  End if
End Property

Put the cursor on Bar() and select Refactor|Rename. Type Snafu into the dialog box. Resulting code would be:

Private Type TFoo
  snafu as Long
  biff as Long
  fubar as Long
  frodo as long
End Type

Private this as TFoo

Public Property Get Snafu() as Long
  Snafu = this.snafu
End Property
Public Property Let Snafu(ByValue RHS as String)
  this.snafu = RHS
End Property

Public Property Get Biff() as Long
  If isnull(this.fubar) Then
    Biff = Null
  ElseIf isnull(this.frodo) Then
    Biff = Null
  Else
    Biff = this.fubar + this.frodo
  End if
End Property

Put the cursor on Biff() and select Refactor|Rename. Type Baz into the dialog box. Resulting code would be:

Private Type TFoo
  snafu as Long
  baz as Long
  fubar as Long
  frodo as long
End Type

Private this as TFoo

Public Property Get Snafu() as Long
  Snafu = this.snafu
End Property
Public Property Let Snafu(ByValue RHS as String)
  this.snafu = RHS
End Property

Public Property Get Baz() as Long
  If isnull(this.fubar) Then
    Baz= Null
  ElseIf isnull(this.frodo) Then
    Baz= Null
  Else
    Baz= this.fubar + this.frodo
  End if
End Property

I know there's no need in this contrived example for the biff \ baz backing variable, just roll with it.

Having it fix up the casing (as I've done) would be an awesome bonus, but that's simple enough to do by hand if necessary. Having the casing defined in RD options settings would be excellent, but that's probably a whole different feature request that this could take advantage of once it's defined.

@daFreeMan daFreeMan added the enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. label Aug 21, 2020
@BZngr
Copy link
Contributor

BZngr commented Aug 21, 2020

Related #5468

@daFreeMan
Copy link
Contributor Author

Now, see, @BZngr , I thought it was such a good idea, I reported it twice!

TBH, I started with renaming the backing fields and wondered if the Get/Set would get renamed. This go 'round, as I was thinking about it, I thought it would be easier to rename the Get/Set/Let and update the backing field, though, because of the layout of the code in the file (UDT before the Properties), the other request makes more sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. feature-refactorings refactoring-rename
Projects
None yet
Development

No branches or pull requests

2 participants