Skip to content

Latest commit

 

History

History
91 lines (68 loc) · 2.56 KB

NotIsRule.md

File metadata and controls

91 lines (68 loc) · 2.56 KB

<-- previous rule | overview | next rule -->

Prefer IS NOT to NOT IS

Transforms logical expressions to use IS NOT instead of NOT IS, if possible.

This rule is part of the essential profile, as it is explicitly demanded by the Clean ABAP Styleguide.

References

Options

  • (no options available for this rule)

Examples

  METHOD prefer_is_not_to_not_is.
    " simple cases
    IF NOT iv_param IS SUPPLIED.
      IF NOT <ls_data> IS ASSIGNED.
        IF NOT lo_object IS BOUND.
          IF NOT lo_object IS INSTANCE OF cl_any_class.
            IF NOT lts_table[ a = 1
                              b = 2
                              c = 3 ]-field IS INITIAL.
              " do nothing
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.

    " complex cases
    IF NOT iv_param IS SUPPLIED
    OR NOT iv_other_param IS SUPPLIED.

      IF NOT <ls_data> IS ASSIGNED
      OR ( NOT lo_object IS BOUND
           AND NOT lo_object IS INSTANCE OF cl_any_class ).
        " do nothing
      ENDIF.

    ENDIF.
  ENDMETHOD.

Resulting code:

  METHOD prefer_is_not_to_not_is.
    " simple cases
    IF iv_param IS NOT SUPPLIED.
      IF <ls_data> IS NOT ASSIGNED.
        IF lo_object IS NOT BOUND.
          IF lo_object IS NOT INSTANCE OF cl_any_class.
            IF lts_table[ a = 1
                              b = 2
                              c = 3 ]-field IS NOT INITIAL.
              " do nothing
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.

    " complex cases
    IF    iv_param       IS NOT SUPPLIED
       OR iv_other_param IS NOT SUPPLIED.

      IF    <ls_data> IS NOT ASSIGNED
         OR (     lo_object IS NOT BOUND
              AND lo_object IS NOT INSTANCE OF cl_any_class ).
        " do nothing
      ENDIF.

    ENDIF.
  ENDMETHOD.

Related code