All files / src skip_logic.ts

80.54% Statements 120/149
80% Branches 44/55
87.5% Functions 7/8
80.54% Lines 120/149

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 1491x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 158x 158x 158x 1x 1x 181x 181x 181x 181x 181x 3x 181x 178x 178x 1x 1x 1x 1x 1x 178x 177x 177x   177x 177x 177x   177x   177x 1x 177x 1x 1x 175x 175x 175x 1x 1x 1x 1x 11x 11x 1x 1x 11x 1x 1x 1x 1x 9x 9x 1x 1x 12x 12x 11x 11x 1x 1x 1x 12x     12x 1x 1x 30x 30x 26x 26x 4x 30x   30x 4x 4x 30x 1x 1x                                   1x 1x 33x 33x 33x 33x 31x 31x 33x 33x 2x 33x   31x 1x 1x 30x 30x 1x 1x 30x   30x     30x 30x 30x 28x 28x 2x 2x     2x 28x 30x 30x 30x 1x 1x
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();
      if (file && ig.listMainForInclude(file.getFilename()).length === 0) {
        return true;
      }
    } else if (global.skipGeneratedPersistentClasses
        && obj instanceof Class
        && this.isGeneratedPersistentClass(obj)) {
      return true;
    } else if (global.skipGeneratedFunctionGroups
        && obj instanceof FunctionGroup
        && this.isGeneratedFunctionGroup(obj)) {
      return true;
    } else if (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) {
      if (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>/);
    if (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>/);
    if (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 if (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 {
    if (obj.getCategory() === ClassCategory.Persistent) {
      return true;
    } else if (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());
        if (sclass && (sclass as Class).getCategory() === ClassCategory.PersistentFactory) {
          return true;
        }
      }
    }
 
    return false;
  }
 
}