All files / src/objects message_class.ts

91.42% Statements 64/70
88.88% Branches 24/27
87.5% Functions 7/8
91.42% Lines 64/70

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 701x 1x 1x 1x 40x 40x 40x 40x 101x 101x 40x 40x         40x 40x 1x 1x 1x 1x 1x 40x 40x 39x 39x 39x 40x 40x 22x 22x 22x 22x 40x 40x 9x 9x 9x 12x 8x 8x 12x 1x 1x 40x 40x 40x 40x 31x 9x 9x 22x 22x 22x 22x 31x     22x 31x 31x 2x 2x 31x 28x 28x 20x 40x 40x
import {AbstractObject} from "./_abstract_object";
import {Message} from "../abap/types/message";
import {xmlToArray, unescape} from "../xml_utils";
 
export class MessageClass extends AbstractObject {
  private parsedMessages: Message[] | undefined = undefined;
 
  public getType(): string {
    return "MSAG";
  }
 
  public getDescription(): string | undefined {
    this.parseXML();
    // todo
    return undefined;
  }
 
  public getAllowedNaming() {
    return {
      maxLength: 20,
      allowNamespace: true,
    };
  }
 
  public setDirty(): void {
    this.parsedMessages = undefined;
    super.setDirty();
  }
 
  public getMessages(): readonly Message[] {
    this.parseXML();
    const msg = this.parsedMessages;
    return msg ? msg : [];
  }
 
  public getByNumber(num: string): Message | undefined {
    this.parseXML();
    // todo, optimize performance,
    for (const message of this.getMessages()) {
      if (message.getNumber() === num) {
        return message;
      }
    }
    return undefined;
  }
 
/////////////////////////////////
 
  private parseXML() {
    if (this.parsedMessages !== undefined) {
      return;
    }
 
    this.parsedMessages = [];
 
    const parsed = super.parseRaw2();
    if (parsed === undefined) {
      return;
    }
 
    const t100 = parsed?.abapGit?.["asx:abap"]["asx:values"]?.T100;
    if (t100 === undefined) {
      return;
    }
    for (const msg of xmlToArray(t100.T100)) {
      this.parsedMessages.push(new Message(msg.MSGNR, unescape(msg.TEXT)));
    }
  }
 
}