All files / src/objects program.ts

98.07% Statements 102/104
77.27% Branches 34/44
100% Functions 10/10
98.07% Lines 102/104

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 1051x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 71527x 71527x 1x 1x 4838x 4838x     4838x 4838x 1x 1x 4x 4x 4x 1x 1x 189x 189x 189x 189x 189x 1x 1x 10832x 10832x 10832x 1x 1x 15063x 15063x 15063x 1x 1x 176x 176x 176x 1x 1x 16x 16x 16x 1x 1x 195x 195x 195x 1x 1x 1x 1x 15454x 5697x 5697x 9757x 9757x 9757x 15454x 9668x 9668x 9668x 9668x 9668x 9668x 9668x 9668x 9668x 89x 89x 89x 15454x 103x 35x 103x 20x 20x 103x 89x 89x 89x 89x 15454x 15454x 15454x 15454x 15454x 15454x 15454x 1x  
import {ABAPObject, ITextElements} from "./_abap_object";
import {ABAPFile} from "../abap/abap_file";
import {DynproList, parseDynpros} from "./_dynpros";
import {xmlToArray, unescape} from "../xml_utils";
 
export class Program extends ABAPObject {
  private parsedXML: {
    isInclude: boolean,
    isModulePool: boolean,
    description: string | undefined,
    dynpros: DynproList,
    selectionTexts: ITextElements,
  } | undefined;
 
  public getType(): string {
    return "PROG";
  }
 
  public getSequencedFiles(): readonly ABAPFile[] {
    const main = this.getMainABAPFile();
    if (main === undefined) {
      return [];
    }
    return [main];
  }
 
  public getDescription(): string | undefined {
    this.parseXML();
    return this.parsedXML?.description;
  }
 
  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 || [];
  }
 
  public getSelectionTexts(): ITextElements {
    this.parseXML();
    return this.parsedXML!.selectionTexts;
  }
 
////////////////////////////
 
  private parseXML() {
    if (this.parsedXML !== undefined) {
      return;
    }
 
    const file = this.getXMLFile();
    const parsed = this.parseRaw2();
    if (parsed === undefined) {
      this.parsedXML = {
        isInclude: false,
        isModulePool: false,
        description: undefined,
        dynpros: [],
        selectionTexts: {},
      };
      return;
    }
 
    let description = "";
    const selectionTexts: ITextElements = {};
    for (const t of xmlToArray(parsed?.abapGit?.["asx:abap"]?.["asx:values"]?.TPOOL?.item)) {
      if (t?.ID === "R") {
        description = t.ENTRY ? unescape(t.ENTRY) : "";
      } else if (t?.ID === "S" && typeof t.KEY === "string") {
        selectionTexts[t.KEY.toUpperCase()] = {entry: t.ENTRY ? unescape(t.ENTRY) : "", maxLength: parseInt(t.LENGTH, 10)};
      }
    }
 
    const dynpros = parseDynpros(parsed);
 
    this.parsedXML = {
      isInclude: file ? file.getRaw().includes("<SUBC>I</SUBC>") : false,
      isModulePool: file ? file.getRaw().includes("<SUBC>M</SUBC>") : false,
      dynpros: dynpros,
      description: description,
      selectionTexts: selectionTexts,
    };
  }
}