All files / src/json zcl_abapgit_ajson_mapping.clas.locals_imp.abap

96.48% Statements 329/341
77.77% Branches 14/18
75% Functions 6/8
96.48% Lines 329/341

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 3421x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 1x 1x 1x 20x 20x 20x 20x 20x 20x 6x 6x 20x 20x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 11x 11x 11x 11x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 6x 6x 6x 6x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 10x 10x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 32x 32x 32x 32x 32x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 91x 91x 91x 91x 91x 91x 91x 91x 91x 5x 5x 86x 86x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
CLASS lcl_mapping_fields IMPLEMENTATION. "DEPRECATED
 
 
  METHOD constructor.
 
    DATA ls_mapping_field LIKE LINE OF mt_mapping_fields.
 
    LOOP AT it_mapping_fields INTO ls_mapping_field.
      ls_mapping_field-abap = to_upper( ls_mapping_field-abap ).
      INSERT ls_mapping_field INTO TABLE mt_mapping_fields.
    ENDLOOP.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_ajson_mapping~to_abap.
 
    DATA ls_mapping_field LIKE LINE OF mt_mapping_fields.
 
    READ TABLE mt_mapping_fields INTO ls_mapping_field
      WITH KEY json COMPONENTS json = iv_name.
    IF sy-subrc = 0.
      rv_result = ls_mapping_field-abap.
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_ajson_mapping~to_json.
 
    DATA lv_field TYPE string.
    DATA ls_mapping_field LIKE LINE OF mt_mapping_fields.
 
    lv_field = to_upper( iv_name ).
 
    READ TABLE mt_mapping_fields INTO ls_mapping_field
      WITH KEY abap COMPONENTS abap = lv_field.
    IF sy-subrc = 0.
      rv_result = ls_mapping_field-json.
    ENDIF.
 
  ENDMETHOD.
 
  METHOD zif_abapgit_ajson_mapping~rename_node.

  ENDMETHOD.
 
ENDCLASS.
 
CLASS lcl_rename IMPLEMENTATION.
 
  METHOD constructor.
    mt_rename_map = it_rename_map.
    mv_rename_by = iv_rename_by.
  ENDMETHOD.
 
  METHOD zif_abapgit_ajson_mapping~to_abap.
  ENDMETHOD.
 
  METHOD zif_abapgit_ajson_mapping~to_json.
  ENDMETHOD.
 
  METHOD zif_abapgit_ajson_mapping~rename_node.
 
    DATA lv_full_path TYPE string.
    DATA lv_pair_found TYPE abap_bool.
    FIELD-SYMBOLS <r> LIKE LINE OF mt_rename_map.
 
    CASE mv_rename_by.
      WHEN zcl_abapgit_ajson_mapping=>rename_by-attr_name.
        READ TABLE mt_rename_map ASSIGNING <r> WITH TABLE KEY by_name COMPONENTS from = cv_name.
        lv_pair_found = boolc( sy-subrc = 0 ).
      WHEN zcl_abapgit_ajson_mapping=>rename_by-full_path.
        lv_full_path = is_node-path && cv_name.
        READ TABLE mt_rename_map ASSIGNING <r> WITH TABLE KEY by_name COMPONENTS from = lv_full_path.
        lv_pair_found = boolc( sy-subrc = 0 ).
      WHEN zcl_abapgit_ajson_mapping=>rename_by-pattern.
        lv_full_path = is_node-path && cv_name.
        LOOP AT mt_rename_map ASSIGNING <r>.
          IF lv_full_path CP <r>-from.
            lv_pair_found = abap_true.
            EXIT.
          ENDIF.
        ENDLOOP.
      WHEN OTHERS.
        lv_pair_found = abap_false. " No rename
    ENDCASE.
 
    IF lv_pair_found = abap_true.
      cv_name = <r>-to.
    ENDIF.
 
  ENDMETHOD.
 
ENDCLASS.
 
CLASS lcl_mapping_to_upper IMPLEMENTATION.
 
 
  METHOD constructor.
 
    mi_mapping_fields = zcl_abapgit_ajson_mapping=>create_field_mapping( it_mapping_fields ).
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_ajson_mapping~to_abap.
 
    rv_result = mi_mapping_fields->to_abap( iv_path = iv_path
                                            iv_name = iv_name ).
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_ajson_mapping~to_json.
 
    rv_result = mi_mapping_fields->to_json( iv_path = iv_path
                                            iv_name = iv_name ).
 
    IF rv_result IS NOT INITIAL. " Mapping found
      RETURN.
    ENDIF.
 
    rv_result = to_upper( iv_name ).
 
  ENDMETHOD.
 
  METHOD zif_abapgit_ajson_mapping~rename_node.
 
    cv_name = to_upper( cv_name ).
 
  ENDMETHOD.
 
ENDCLASS.
 
 
CLASS lcl_mapping_to_lower IMPLEMENTATION.
 
 
  METHOD constructor.
 
    mi_mapping_fields = zcl_abapgit_ajson_mapping=>create_field_mapping( it_mapping_fields ).
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_ajson_mapping~to_abap.
 
    rv_result = mi_mapping_fields->to_abap( iv_path = iv_path
                                            iv_name = iv_name ).
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_ajson_mapping~to_json.
 
    rv_result = mi_mapping_fields->to_json( iv_path = iv_path
                                            iv_name = iv_name ).
 
    IF rv_result IS NOT INITIAL. " Mapping found
      RETURN.
    ENDIF.
 
    rv_result = to_lower( iv_name ).
 
  ENDMETHOD.
 
  METHOD zif_abapgit_ajson_mapping~rename_node.
 
    cv_name = to_lower( cv_name ).
 
  ENDMETHOD.
 
ENDCLASS.
 
 
CLASS lcl_mapping_camel IMPLEMENTATION. "DEPRECATED
 
 
  METHOD constructor.
 
    mi_mapping_fields   = zcl_abapgit_ajson_mapping=>create_field_mapping( it_mapping_fields ).
    mv_first_json_upper = iv_first_json_upper.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_ajson_mapping~to_abap.
 
    rv_result = mi_mapping_fields->to_abap( iv_path = iv_path
                                            iv_name = iv_name ).
 
    IF rv_result IS NOT INITIAL. " Mapping found
      RETURN.
    ENDIF.
 
    rv_result = iv_name.
 
    REPLACE ALL OCCURRENCES OF REGEX `([a-z])([A-Z])` IN rv_result WITH `$1_$2`.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_ajson_mapping~to_json.
 
    TYPES ty_token TYPE c LENGTH 255.
    DATA lt_tokens TYPE STANDARD TABLE OF ty_token.
    DATA lv_from TYPE i.
    FIELD-SYMBOLS <token> LIKE LINE OF lt_tokens.
 
    rv_result = mi_mapping_fields->to_json( iv_path = iv_path
                                            iv_name = iv_name ).
 
    IF rv_result IS NOT INITIAL. " Mapping found
      RETURN.
    ENDIF.
 
    rv_result = iv_name.
 
    REPLACE ALL OCCURRENCES OF `__` IN rv_result WITH `*`.
 
    TRANSLATE rv_result TO LOWER CASE.
    TRANSLATE rv_result USING `/_:_~_`.
 
    IF mv_first_json_upper = abap_true.
      lv_from = 1.
    ELSE.
      lv_from = 2.
    ENDIF.
 
    SPLIT rv_result AT `_` INTO TABLE lt_tokens.
    LOOP AT lt_tokens ASSIGNING <token> FROM lv_from.
      TRANSLATE <token>(1) TO UPPER CASE.
    ENDLOOP.
 
    CONCATENATE LINES OF lt_tokens INTO rv_result.
    REPLACE ALL OCCURRENCES OF `*` IN rv_result WITH `_`.
 
  ENDMETHOD.
 
  METHOD zif_abapgit_ajson_mapping~rename_node.

  ENDMETHOD.
 
ENDCLASS.
 
CLASS lcl_compound_mapper IMPLEMENTATION.
 
  METHOD constructor.
    mt_queue = it_queue.
  ENDMETHOD.
 
  METHOD zif_abapgit_ajson_mapping~rename_node.
 
    DATA ls_node LIKE is_node.
    DATA li_mapper LIKE LINE OF mt_queue.
 
    ls_node = is_node.
 
    LOOP AT mt_queue INTO li_mapper.
      li_mapper->rename_node(
        EXPORTING
          is_node = ls_node
        CHANGING
          cv_name = cv_name ).
      ls_node-name = cv_name.
    ENDLOOP.
 
  ENDMETHOD.
 
  METHOD zif_abapgit_ajson_mapping~to_abap.
 
  ENDMETHOD.
 
  METHOD zif_abapgit_ajson_mapping~to_json.
 
  ENDMETHOD.
 
ENDCLASS.
 
CLASS lcl_to_snake IMPLEMENTATION.
 
  METHOD zif_abapgit_ajson_mapping~rename_node.
 
    REPLACE ALL OCCURRENCES OF REGEX `([a-z])([A-Z])` IN cv_name WITH `$1_$2`.
    cv_name = to_lower( cv_name ).
 
  ENDMETHOD.
 
  METHOD zif_abapgit_ajson_mapping~to_abap.
 
  ENDMETHOD.
 
  METHOD zif_abapgit_ajson_mapping~to_json.
 
  ENDMETHOD.
 
ENDCLASS.
 
CLASS lcl_to_camel IMPLEMENTATION.
 
  METHOD constructor.
    mv_first_json_upper = iv_first_json_upper.
  ENDMETHOD.
 
  METHOD zif_abapgit_ajson_mapping~rename_node.
 
    TYPES lty_token TYPE c LENGTH 255.
    CONSTANTS lc_forced_underscore_marker TYPE c LENGTH 1 VALUE cl_abap_char_utilities=>horizontal_tab.
 
    DATA lt_tokens TYPE STANDARD TABLE OF lty_token.
    DATA lv_from TYPE i.
    FIELD-SYMBOLS <token> LIKE LINE OF lt_tokens.
 
    IF mv_first_json_upper = abap_true.
      lv_from = 1.
    ELSE.
      lv_from = 2.
    ENDIF.
    REPLACE ALL OCCURRENCES OF `__` IN cv_name WITH lc_forced_underscore_marker. " Force underscore
 
    SPLIT cv_name AT `_` INTO TABLE lt_tokens.
    DELETE lt_tokens WHERE table_line IS INITIAL.
    LOOP AT lt_tokens ASSIGNING <token> FROM lv_from.
      TRANSLATE <token>+0(1) TO UPPER CASE.
    ENDLOOP.
 
    CONCATENATE LINES OF lt_tokens INTO cv_name.
    REPLACE ALL OCCURRENCES OF lc_forced_underscore_marker IN cv_name WITH `_`.
 
  ENDMETHOD.
 
  METHOD zif_abapgit_ajson_mapping~to_abap.
 
  ENDMETHOD.
 
  METHOD zif_abapgit_ajson_mapping~to_json.
 
  ENDMETHOD.
 
ENDCLASS.