All files / src/objects program.ts

95.49% Statements 106/111
85.71% Branches 24/28
88.88% Functions 8/9
95.49% Lines 106/111

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 1121x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 37139x 37139x 1x 1x 4012x 4012x     4012x 4012x 1x 1x       1x 1x 174x 174x 174x 174x 174x 1x 1x 7630x 7630x 7630x 1x 1x 3629x 3629x 3629x 1x 1x 173x 173x 173x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3803x 1227x 1227x 2576x 2576x 2576x 3803x 2548x 2548x 2548x 2548x 2548x 2548x 2548x 28x 28x 3803x 3803x 1x 1x 1x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 28x 28x 3803x 3803x 3803x 3803x 3803x 1x  
import {ABAPObject} from "./_abap_object";
import {ABAPFile} from "../abap/abap_file";
import {xmlToArray} from "../xml_utils";
 
export type DynproField = {
  name: string,
  type: string,
  length: number,
};
export type DynproHeader = {
  number: string,
  fields: DynproField[],
};
export type DynproList = DynproHeader[];
 
 
export class Program extends ABAPObject {
  private parsedXML: {
    isInclude: boolean,
    isModulePool: boolean,
    dynpros: DynproList,
  } | undefined;
 
  public getType(): string {
    return "PROG";
  }
 
  public getSequencedFiles(): readonly ABAPFile[] {
    const main = this.getMainABAPFile();
    if (main === undefined) {
      return [];
    }
    return [main];
  }
 
  public getDescription(): string | undefined {
    // todo
    return undefined;
  }
 
  public getAllowedNaming() {
    return {
      maxLength: 40,
      allowNamespace: true,
    };
  }
 
  public setDirty(): void {
    this.parsedXML = undefined;
    super.setDirty();
  }
 
  public isInclude(): boolean {
    this.parseXML();
    return this.parsedXML!.isInclude;
  }
 
  public isModulePool(): boolean {
    this.parseXML();
    return this.parsedXML!.isModulePool;
  }
 
  public getDynpros(): DynproList {
    this.parseXML();
    return this.parsedXML!.dynpros;
  }
 
////////////////////////////
 
  private parseXML() {
    if (this.parsedXML !== undefined) {
      return;
    }
 
    const file = this.getXMLFile();
    const parsed = this.parseRaw2();
    if (parsed === undefined) {
      this.parsedXML = {
        isInclude: false,
        isModulePool: false,
        dynpros: [],
      };
      return;
    }
 
    const dynpros: DynproList = [];
    const xmlDynpros = parsed.abapGit?.["asx:abap"]?.["asx:values"]?.DYNPROS;
    if (xmlDynpros !== undefined) {
      for (const d of xmlToArray(xmlDynpros.item)) {
        const fields: DynproField[] = [];
        for (const f of xmlToArray(d.FIELDS?.RPY_DYFATC)) {
          fields.push({
            name: f.NAME,
            type: f.TYPE,
            length: f.LENGTH,
          });
        }
        dynpros.push({
          number: d.HEADER.SCREEN,
          fields: fields,
        });
      }
    }
 
    this.parsedXML = {
      isInclude: file ? file.getRaw().includes("<SUBC>I</SUBC>") : false,
      isModulePool: file ? file.getRaw().includes("<SUBC>M</SUBC>") : false,
      dynpros: dynpros,
    };
  }
}