All files / src skip_logic.ts

75.64% Statements 59/78
74.44% Branches 67/90
87.5% Functions 7/8
75.64% Lines 59/78

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  1x   1x   1x           132x 132x       147x   147x     3x 144x     1x 1x 1x 1x   143x       143x       143x   143x 1x 142x 1x     141x           11x 11x 1x   10x 1x 1x     9x       12x 12x 11x   1x 1x 1x             28x 28x 24x   4x 4x     4x                                               31x   31x 31x 29x     31x 2x 29x   29x 1x   28x       28x   28x       28x 28x 26x 26x 2x 2x           28x      
import {IObject} from "./objects/_iobject";
import {Class, ClassCategory, FunctionGroup, MaintenanceAndTransportObject, Interface, Program} from "./objects";
import {IRegistry} from "./_iregistry";
import {IncludeGraph} from "./utils/include_graph";
 
export class SkipLogic {
  private readonly reg: IRegistry;
  /** TOBJ cache hashmap */
  private tobj: { [index: string]: boolean } | undefined;
 
  public constructor(reg: IRegistry) {
    this.reg = reg;
    this.tobj = undefined;
  }
 
  public skip(obj: IObject): boolean {
    const global = this.reg.getConfig().getGlobal();
 
    if (global.skipGeneratedGatewayClasses
        && obj instanceof Class
        && this.isGeneratedGatewayClass(obj)) {
      return true;
    } else if (global.skipIncludesWithoutMain === true
        && obj instanceof Program
        && obj.isInclude() === true) {
      const ig = new IncludeGraph(this.reg);
      const file = obj.getMainABAPFile();
      Eif (file && ig.listMainForInclude(file.getFilename()).length === 0) {
        return true;
      }
    } else Iif (global.skipGeneratedPersistentClasses
        && obj instanceof Class
        && this.isGeneratedPersistentClass(obj)) {
      return true;
    } else Iif (global.skipGeneratedFunctionGroups
        && obj instanceof FunctionGroup
        && this.isGeneratedFunctionGroup(obj)) {
      return true;
    } else Iif (obj instanceof Class && this.isGeneratedProxyClass(obj)) {
      return true;
    } else if (obj instanceof Interface && this.isGeneratedProxyInterface(obj)) {
      return true;
    } else if (obj instanceof Interface && this.isGeneratedBOPFInterface(obj)) {
      return true;
    }
 
    return false;
  }
 
///////////////////////////
 
  private isGeneratedBOPFInterface(obj: Interface): boolean {
    const implementing = obj.getDefinition()?.getImplementing();
    if (implementing === undefined) {
      return false;
    }
    for (const i of implementing) {
      Eif (i.name.toUpperCase() === "/BOBF/IF_LIB_CONSTANTS") {
        return true;
      }
    }
    return false;
  }
 
  private isGeneratedProxyInterface(obj: Interface): boolean {
    const xml = obj.getXML();
    if (!xml) {
      return false;
    }
    const result = xml.match(/<CLSPROXY>(.)<\/CLSPROXY>/);
    Eif (result) {
      return true;
    } else {
      return false;
    }
  }
 
  private isGeneratedProxyClass(obj: Class): boolean {
    const xml = obj.getXML();
    if (!xml) {
      return false;
    }
    const result = xml.match(/<CLSPROXY>(.)<\/CLSPROXY>/);
    Iif (result) {
      return true;
    } else {
      return false;
    }
  }
 
  private isGeneratedFunctionGroup(group: FunctionGroup): boolean {
    if (this.tobj === undefined) {
      this.tobj = {};
 
      for (const obj of this.reg.getObjects()) {
        if (obj.getType() !== "TOBJ") {
          continue;
        }
        const tobj = obj as MaintenanceAndTransportObject;
        const area = tobj.getArea()?.toUpperCase();
        if (area) {
          this.tobj[area] = true;
        }
      }
    }
 
    return this.tobj[group.getName().toUpperCase()];
  }
 
  private isGeneratedGatewayClass(obj: Class): boolean {
    let sup = undefined;
 
    const definition = obj.getClassDefinition();
    if (definition) {
      sup = definition.superClassName?.toUpperCase();
    }
 
    if (obj.getName().match(/_MPC$/i) && sup === "/IWBEP/CL_MGW_PUSH_ABS_MODEL") {
      return true;
    } else Iif (obj.getName().match(/_DPC$/i) && sup === "/IWBEP/CL_MGW_PUSH_ABS_DATA") {
      return true;
    } else if (sup === "CL_SADL_GTK_EXPOSURE_MPC") {
      return true;
    }
    return false;
  }
 
  private isGeneratedPersistentClass(obj: Class): boolean {
    Iif (obj.getCategory() === ClassCategory.Persistent) {
      return true;
    } else Iif (obj.getCategory() === ClassCategory.PersistentFactory) {
      return true;
    }
 
    const main = obj.getClassDefinition();
    if (main) {
      const sup = main.superClassName;
      if (sup) {
        const sclass = this.reg.getObject("CLAS", sup.toUpperCase());
        Iif (sclass && (sclass as Class).getCategory() === ClassCategory.PersistentFactory) {
          return true;
        }
      }
    }
 
    return false;
  }
 
}