Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: DFRefactor code indent problems with nested case

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Posts
    1,039

    Default DFRefactor code indent problems with nested case

    DFRefactor works excellent in most cases but its code indent cannot handle nested case statements. A lot of spaces are added in the beginning of certain lines. In the simple example below, just about 30 spaces were added, but I have got lines with 4000 blank characters added.

    Before processing

    Code:
        Procedure OnProcess
            String sAnimal sSex sTerm sNoise
            Case Begin
                Case (sAnimal = "Cat")
                    Move ("Meow") to sNoise
                    Case Begin 
                        Case (sSex="male")
                            Move "tomcat" to sTerm
                            Case Break
                        Case (sSex="female")
                            Move "female cat" to sTerm
                            Case Break
                    Case End
                    Case Break
                Case (sAnimal = "Dog")
                    Move ("Arf")  to sNoise
                    Case Break
                Case Else
                    Move ("") to sNoise
            Case End
        End_Procedure
    After re-indent

    Code:
    Object oNestedCase is a BusinessProcess
    
    
        Procedure OnProcess
            String sAnimal sSex sTerm sNoise
            Case Begin
                Case (sAnimal = "Cat")
                    Move ("Meow") to sNoise
                Case Begin
                    Case (sSex="male")
                            Move "tomcat" to sTerm
                                    Case Break
                    Case (sSex="female")
                                                    Move "female cat" to sTerm
                                                                                    Case Break
                Case End
                                                                                Case Break
                Case (sAnimal = "Dog")
                                                                                Move ("Arf")  to sNoise
                                                                                Case Break
                Case Else
                                                                                Move ("") to sNoise
            Case End
        End_Procedure

  2. #2

    Default Re: DFRefactor code indent problems with nested case

    Hi Bengt,

    That did ring a bell and I thought it was resolved already, but apparently not.

    See also:
    https://support.dataaccess.com/Forum...ess-up-my-file

    I will try to set aside some time to figure out what is happening here.
    --
    Wil

  3. #3
    Join Date
    Feb 2009
    Posts
    1,039

    Default Re: DFRefactor code indent problems with nested case

    I use version 3.2.1.0 compiled 2019-09-06

    I also had a problem with this structured variable.


    Code:
    Struct tEmbArray
        String sEmbTyp
        Integer iUtlan
        Integer iReturnerad
    End_Struct
    
    tEmbArray[] EmbSaldo
    It was changed to this despite the variable was used:

    Code:
    Struct tEmbArray
    End_Struct
    
    
    tEmbArray[] EmbSaldo

  4. #4
    Join Date
    Feb 2009
    Location
    Queens, NY, NY
    Posts
    7,429

    Default Re: DFRefactor code indent problems with nested case

    I wonder,

    Did you define the struct INSIDE a procedure or function?

    MM
    Michael Mullan.
    Danes Bridge Enterprises.

    ++++++++++++++++++++++++++++
    There is just today. Tomorrow is a concept
    that is mostly theoretical. -- GM Wylie
    ++++++++++++++++++++++++++++

  5. #5

    Default Re: DFRefactor code indent problems with nested case

    Thanks Michael,

    That is the correct question.
    Normally DfRefactor only removes unused variables within a method, so it is a strange problem to see.

    If you declare a struct within a method then that would certainly confuse DfRefactor.

    I had to test it, but this does indeed compile:
    Code:
    Use Windows.pkg
    
    Procedure Test
      Struct tEmbArray
          String sEmbTyp
          Integer iUtlan
          Integer iReturnerad
      End_Struct
    
      tEmbArray[] EmbSaldo  
      
      Move (ResizeArray(EmbSaldo,1)) To EmbSaldo
      Move 1 To EmbSaldo[0].iUtlan
      Showln "Hello"
    End_Procedure
    
    Send test
    
    inKey WindowIndex
    If you run DfRefactor on the above then it does indeed show the result that Bengt mentions.

    If I then rerun it, but move the struct declaration out of the method:
    Code:
    Use Windows.pkg
    
    Struct tEmbArray
      String sEmbTyp
      Integer iUtlan
      Integer iReturnerad
    End_Struct
    
    Procedure Test
      tEmbArray[] EmbSaldo  
      
      Move (ResizeArray(EmbSaldo,1)) To EmbSaldo
      Move 1 To EmbSaldo[0].iUtlan
      Showln "Hello"
    End_Procedure
    
    Send test
    
    inKey WindowIndex
    Then it works as expected and it does not remove the variables from the struct declaration.

    So in this scenario, unless you can provide a better example, I'd say "not a bug" as it points out a very non standard thing in your code.

    --
    Wil

  6. #6
    Join Date
    Feb 2009
    Posts
    1,039

    Default Re: DFRefactor code indent problems with nested case

    I had defined the struct inside a procedure, so that behavior is explained by that.

    I also have a code part which I re-use by including it on different places in my program. Variables are defined in the beginning of the methods where the code is included and some are only used in the included part. These where of course removed by DFRefactor. That is easy to fix, but anyway, I would prefer that the standard functions weren't selected as default.

    Bengt

  7. #7

    Default Re: DFRefactor code indent problems with nested case

    Bengt,

    Quote Originally Posted by Bengt View Post
    I had defined the struct inside a procedure, so that behavior is explained by that.

    I also have a code part which I re-use by including it on different places in my program. Variables are defined in the beginning of the methods where the code is included and some are only used in the included part. These where of course removed by DFRefactor. That is easy to fix, but anyway, I would prefer that the standard functions weren't selected as default.

    Bengt
    So if I'm reading that correctly then you have include files where you include logic within a method?

    So similar to:
    Code:
    Procedure MyMethod
      String sFoo
      Number nBar
    
      ... some code not using sFoo
      #include EXTRACODE.inc  // using sFoo
      ... more code
    End_Procedure
    and you want DfRefactor to leave your file alone?

    I think the better way would be to rewrite that logic similar to this:

    Code:
    Procedure ExtraCode String ByRef sFoo
      Move "abc" to sFoo
    End_Procedure 
    
    Procedure MyMethod
      String sFoo
      Number nBar
    
      ... some code not using sFoo
      Send Extracode (&sFoo)
      ... more code
    End_Procedure
    That way DfRefactor won't take away those variables and your code is cleaner.
    But I don't know if it is an option for you to rework the code in that way.

    Another solution would be to move files you don't want to be touched by DfRefactor in a folder outside of AppSrc/DdSrc so that they are not immediately selected.

    --
    Wil

  8. #8

    Default Re: DFRefactor code indent problems with nested case

    Hi Bengt,

    The issue with the nested case statements has been resolved.

    I tested with a small extension to your original example and after running re-indent it now looks like so:

    Code:
    Object oTest Is a BusinessProcess
    
        Procedure OnProcess
            String sAnimal sSex sTerm sNoise sCatch sDo
    
            Case Begin
                Case (sAnimal = "Cat")
                    Move ("Meow") to sNoise
                    Case Begin
                        Case (sSex="male")
                            Move "tomcat" to sTerm
                            Case Begin
                                Case (sCatch="mouse")
                                    Move "eat" to sDo
                                    Case Break
                                Case (sCatch="bird")
                                    Move "kill" to sDo
                                    Case Break
                            Case End
                            Case Break
                        Case (sSex="female")
                            Move "female cat" to sTerm
                            Case Break
                    Case End
                    Case Break
                Case (sAnimal = "Dog")
                    Move ("Arf")  to sNoise
                    Case Break
                Case Else
                    Move ("") to sNoise
            Case End
        End_Procedure
    
    End_Object
    The update is available from the files section of the project server.
    https://projects.vdf-guidance.com/pr...refactor/files

    --
    Wil

  9. #9
    Join Date
    Feb 2009
    Posts
    1,039

    Default Re: DFRefactor code indent problems with nested case

    Is there an installation instruction for DFRefactor?

    My previous version was working except for the case problem. I substituted my previous files in C:\Projects\DfRefactor with the new one downloaded structure from VDF-Guidance. It didn't work immediately so I supposed that DfRefactor had to be compiled, but when I did that I got the error

    - Error 4306: C:\Projects\DfRefactor\Libraries\DFAbout\DfAbout.p kg (ln 612) Cannot find forward reference GET_SQLSERVERCLIENTVERSIONNAME

    /Bengt

  10. #10

    Default Re: DFRefactor code indent problems with nested case

    Bengt,

    As you probably know there's 2 ways to get DfRefactor. One way is from the installer that Nils provides and the other one is the zip that I provide via the project vdf-guidance site. (https://projects.vdf-guidance.com/pr...refactor/files )

    You mention that you the new one from vdf-guidance, so I presume you downloaded the whole zip.
    I just did that here too and compiled it in DataFlex 19.1. It compiled and ran.

    Did you perhaps unzip on top of an existing DfRefactor folder? If so, then that might be the reason.
    An old file somewhere that has been moved to another location could explain this type of bug.
    Perhaps you are using another version of DataFlex? If so tell me which one and I will rerun the test.

    --
    Wil

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •