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

Encapsulate Field refactoring does not always insert procedures in correct places #5420

Open
bclothier opened this issue Mar 9, 2020 · 1 comment
Labels
bug Identifies work items for known bugs

Comments

@bclothier
Copy link
Contributor

Rubberduck version information
Version 2.5.0.3853
OS: Microsoft Windows NT 10.0.17763.0, x64
Host Product: Microsoft Office x64
Host Version: 16.0.12430.20288
Host Executable: MSACCESS.EXE

Description
It seems that Declare statements are not handled correctly and get pushed down into middle of module when adding new property statements as a result of the refactoring.

To Reproduce
Start with this code in a class module:

Private foo As String
Private strBar As String
Private bizz As String

Private Declare PtrSafe Function GetFocus Lib "user32" () As LongPtr

Public Property Get Bar() As String
    Bar = strBar
End Property

Public Sub doit()
    Debug.Print "do it"
End Sub

Refactor as shown:
image

We end up with this uncompilable code:

Private Type TClass1
    Foo As String
    Bar_1 As String
    Bizz As String
End Type


Private this As TClass1

Public Property Get Foo() As String
    Foo = this.Foo
End Property

Public Property Let Foo(ByVal value As String)
    this.Foo = value
End Property


Public Property Get Bar_1() As String
    Bar_1 = this.Bar_1
End Property

Public Property Let Bar_1(ByVal value As String)
    this.Bar_1 = value
End Property


Public Property Get Bizz() As String
    Bizz = this.Bizz
End Property

Public Property Let Bizz(ByVal value As String)
    this.Bizz = value
End Property

Private Declare PtrSafe Function GetFocus Lib "user32" () As LongPtr

Public Property Get Bar() As String
    Bar = Bar_1
End Property

Public Sub doit()
    Debug.Print "do it"
End Sub

Expected behavior
The refactoring should ensure that it actually insert at the end of the code declaration section and that should factor in Declare statements which are technically a part of the declaration section.

@bclothier bclothier added the bug Identifies work items for known bugs label Mar 9, 2020
@retailcoder
Copy link
Member

Note, this refactoring has a tech debt refactor pending - I blocked it in Max' PR because I have a branch with UI & other tweaks to this feature... but I need to get back to it.

I'll wrap up these overdue changes and then this bug can be addressed.

@BZngr BZngr changed the title Encapuslate Field refactoring does not always insert procedures in correct places Encapsulate Field refactoring does not always insert procedures in correct places Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Identifies work items for known bugs
Projects
None yet
Development

No branches or pull requests

2 participants