All files / src skip_logic.ts

60.64% Statements 94/155
61.9% Branches 26/42
62.5% Functions 5/8
60.64% Lines 94/155

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 1551x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 277x 277x 277x 1x 1x 340x 340x 340x 340x 340x 3x 340x 337x 337x 1x 1x 1x 1x 1x 337x 336x 336x   336x 336x 336x   336x 336x 336x   336x 336x 336x 1x 336x 335x 335x 1x 1x 334x 334x 334x 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 3x 3x 3x 3x 3x 3x 3x 3x 2x 3x   1x 1x 1x     1x 1x                                       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 === true
        && 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 === true
        && obj instanceof Class
        && this.isGeneratedPersistentClass(obj)) {
      return true;
    } else if (global.skipGeneratedFunctionGroups === true
        && obj instanceof FunctionGroup
        && this.isGeneratedFunctionGroup(obj)) {
      return true;
    } else if (global.skipGeneratedProxyClasses === true
        && obj instanceof Class
        && this.isGeneratedProxyClass(obj)) {
      return true;
    } else if (global.skipGeneratedProxyInterfaces === true
        && obj instanceof Interface
        && this.isGeneratedProxyInterface(obj)) {
      return true;
    } else if (global.skipGeneratedBOPFInterfaces === true
        && 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;
  }
 
}