Tapatalk

Function list for SAP/ABAP code with classes and methods

Function list for SAP/ABAP code with classes and methods

4
NewbieNewbie
4

    Oct 06, 2014#1

    Dear All

    This is an SAP/ABAP Code snippet. I have the following requirement.
    This command lists currently only class names, but not their methods.

    Code: Select all

    /Function String = "%*^{XYXYXYXY^}^{CLASS^}*"
    I still need the METHOD and METHODS, but per each class.
    E.g.

    Code: Select all

    Class vehicle DEFINITION ABSTRACT
    METHODS: accelerate 
                   show_speed
    
    CLASS vehicle IMPLEMENTATION.
    METHOD accelerate.

    Code: Select all

    CLASS vehicle DEFINITION ABSTRACT.
      PUBLIC SECTION.
        METHODS: accelerate IMPORTING delta TYPE i,
                 show_speed ABSTRACT.
      PROTECTED SECTION.
        DATA speed TYPE i.
        
      PRIVATE SECTION.
    ENDCLASS.
    
    
    CLASS vehicle IMPLEMENTATION.
      METHOD accelerate.
        me->speed = me->speed + delta.
      ENDMETHOD.
    ENDCLASS.
    I thank you for your kind hints in advance.

    Regards
    kalem123

    6,685587
    Grand MasterGrand Master
    6,685587

      Oct 07, 2014#2

      Which version of UltraEdit do you currently use?

      Support for a hierarchical function list as well as support for Perl regular expression finds for elements below top level in function list depends on version of UltraEdit.

      And what are the rules to find methods?

      UltraEdit needs for a hierarchical function list always a begin and end block specification.

      It is easy to see that a class definition block starts on line with CLASS and ends with line containing ENDCLASS..

      The methods of this class are declared within a class block in a block starting with METHODS:. What marks end of a method declaration block? A line with a dot? Or a line with SECTION or ENDCLASS.?

      For your samle code block, what exactly do you want to see in function list?

      Just the names of the classes and their methods or also the rest of the line?
      Best regards from an UC/UE/UES for Windows user from Austria

      4
      NewbieNewbie
      4

        Oct 07, 2014#3

        I am on UltraEdit 14.00a

        E.g.

        This reg exp lists all classes and methods and method as well relating to the given below code example

        Code: Select all

        /Function String = "%[ ^t]++^(method[ ^]+[a-z0-9_.]+^)[ ^p^r^n]"
        /Function String 1 = "%[ ^t]++^(class[ ^]+[a-z0-9_.]+^)[ ^p^r^n]"
        /Function String 2 = "%[ ^t]++^(methods[ ^t]+[a-z0-9_.]+^)[ ^p^r^n]"
        The goal is displaying classes with their corresponding methods.

        class vehicle
        method accelerate

        class xyz
        method test1
        method test2
        method test3

        next class
        next method
        ...

        Is it clear to you.

        Kind Regards
        kalem123

        6,685587
        Grand MasterGrand Master
        6,685587

          Oct 07, 2014#4

          A tree-style (hierarchical) function list is supported only in UE v16.00 and later. Therefore the best function list displaying also the structure even with a sorted function list view is not possible for you.

          A quick suggestion for UltraEdit regular expressions is:

          Code: Select all

          /Function String = "%[ ^t]++^(class[ ^t]+[a-z0-9_]+^)[ ^t]+DEFINITION"
          /Function String 1 = "%[ ^t]++^(method[ ^t]+[a-z0-9_]+^)."
          Or faster as of just 1 search string:

          Code: Select all

          /Function String = "%[ ^t]++^(^{method^}^{class^}[ ^t]+[a-z0-9_]+^)^{.^}^{[ ^t]+DEFINITION^}"
          To get them listed as defined in the file and as written in your previous post, you have to right click into the function list view and left click on context menu item Sort List to turn off alphabetic sort of the elements in the function list.

          For something better, i.e. a tree-style function list, you would need to upgrade to UE v21.30.
          Best regards from an UC/UE/UES for Windows user from Austria

          4
          NewbieNewbie
          4

            Oct 07, 2014#5

            Hi Mofi,

            you are really a big Master:-). Thank you very much for your quick help.

            Can you pls. guide me a bit on how to understand some expressions.

            E.g.

            What is the meaning of this expresion in small pieces. Where is beginning end endning of, are there delimiters

            "%[ ^t]++^(^{method^}^{class^}[ ^t]+[a-z0-9_]+^)^{.^}^{[ ^t]+DEFINITION^}"

            Kind Regards
            kalem123

            6,685587
            Grand MasterGrand Master
            6,685587

              Oct 07, 2014#6

              /Function String = "%[ ^t]++^(^{method^}^{class^}[ ^t]+[a-z0-9_]+^)^{.^}^{[ ^t]+DEFINITION^}"

              %[ ^t]++ ... start every search at beginning of a line where 0 or more spaces or tabs can exist. In other words the existence of leading whitespaces does not result in a negative match.

              ^(...^) ... the string found by the regular expression inside the escaped parentheses is tagged for being displayed in the function list. Everything else matched by the entire expression is ignored.

              The UltraEdit regular expression as used here supports up to 9 such capturing groups, but for function list only the first one is evaluated.

              With using Perl regular expression it would be also possible to use up to 9 capturing groups, but the difference is that for function list view all strings of the capturing groups would be concatenated with a single space character between all found strings. Therefore it is possible with using Perl regular expression to get more control over what is displayed in function list and how. This special behavior was used for example in the last expressions posted at Perl regexp function list for C# to have always exactly 1 space between name of a function and its parameters independent on how many spaces/tabs exist really between function name and opening parenthesis. The Perl regular expression supports also non capturing groups as you can see in referenced post.

              ^{method^}^{class^} ... is an OR expression for the two words method and class. So the first word on a line must be either method OR class in any case for a positive match as the regular expression searches are always executed not case-sensitive.

              The UltraEdit and the Unix regexp engines support only OR expressions with exactly two arguments. The Perl regexp engine supports much more as it can be seen in the referenced post. With Perl regular expression engine it would be also possible to change behavior regarding case-sensitivity for each search expression if that is really needed.

              [ ^t]+ ... 1 or more spaces or tabs must exist after either string method or string class.

              [a-z0-9_]+ ... the name of a method or class must be found next consisting only of letters (in any case), digits or underscores. At least 1 of those characters must be found. In C/C++ and many other languages a better expression would be [a-z_][a-z0-9_]++ as the first character cannot be a digit for a valid function/method/class name.

              Now we would have already found the name of a class or method. But we want to avoid duplicates in function list view because of definition and implementation of a class. Therefore one more OR expression must be applied for a positive match of the search.

              ^{.^}^{[ ^t]+DEFINITION^} ... the next character must be either a dot for methods OR after 1 or more spaces/tabs the word DEFINITION (in any case) for classes.

              Of course false positives on invalid method/class definitions would be possible with this regular expression. But the main target for the function string regular expression is to find as quickly as possible the strings of interest and not checking syntax of the source file with ignoring all invalid definitions if that would result in more complex expressions and therefore slower searches.
              Best regards from an UC/UE/UES for Windows user from Austria

              4
              NewbieNewbie
              4

                Oct 07, 2014#7

                Hi Mofi,

                I dont know how can I thank you for all the complaisances. I hope one day I get the chance for a revenge.

                Thousand Thanks.
                kalem123