All files / src skip_logic.ts

62.74% Statements 96/153
60.46% Branches 26/43
62.5% Functions 5/8
62.74% Lines 96/153

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 1541x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 263x 263x 263x 263x 1x 1x 343x 343x 343x 343x 343x 3x 343x 340x 340x 1x 1x 1x 1x 1x 340x 339x 339x   339x 339x 339x   339x 339x 339x   339x 339x 339x 1x 339x 338x 338x 1x 1x 337x 337x 337x 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;
  private includeGraph: IncludeGraph | undefined;
  /** TOBJ cache hashmap */
  private tobj: { [index: string]: boolean } | undefined;
 
  public constructor(reg: IRegistry) {
    this.reg = reg;
    this.includeGraph = undefined;
    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) {
      this.includeGraph ??= new IncludeGraph(this.reg);
      const file = obj.getMainABAPFile();
      if (file && this.includeGraph.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;
    }
  }
 
  public isGeneratedFunctionGroup(group: FunctionGroup): boolean {
    if (this.tobj === undefined) {
      this.tobj = {};

      for (const tobj of this.reg.getObjectsByType("TOBJ")) {
        const area = (tobj as MaintenanceAndTransportObject).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;
  }
 
}