All files / src/objects lock_object.ts

96.33% Statements 105/109
68.75% Branches 44/64
100% Functions 8/8
96.33% Lines 105/109

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 1101x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 95x 95x 1x 1x 2x 2x 2x 2x 2x 2x 1x 1x 13x 13x 13x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 1x 1x 15x 15x 15x 15x 15x 15x 8x 8x 3x 3x 3x 8x 5x 5x     15x 7x 7x 15x 1x 1x 37x 24x 24x 13x 13x 13x 13x 13x 13x 13x 37x 7x 7x 6x 37x 37x 37x 37x 37x 37x 9x     9x 9x 9x 9x 9x 9x 6x 6x 6x 6x 1x 1x 2x 2x 2x 1x  
import {UnknownType, VoidType} from "../abap/types/basic";
import {AbstractType} from "../abap/types/basic/_abstract_type";
import {DDIC} from "../ddic";
import {IObjectAndToken} from "../_iddic_references";
import {IRegistry} from "../_iregistry";
import {AbstractObject} from "./_abstract_object";
import {IAllowedNaming} from "./_iobject";
import {xmlToArray} from "../xml_utils";
 
export class LockObject extends AbstractObject {
  private parsedXML: {
    primaryTable?: string,
    description?: string,
    parameters?: {
      VIEWFIELD: string,
      TABNAME?: string,
      FIELDNAME?: string,
    }[],
  } | undefined;
 
  public getType(): string {
    return "ENQU";
  }
 
  public getAllowedNaming(): IAllowedNaming {
    return {
      maxLength: 16,
      customRegex: /^(\/[A-Z_\d]{3,8}\/)?E[A-Z0-9_]+$/i,
      allowNamespace: true,
    };
  }
 
  public setDirty(): void {
    this.parsedXML = undefined;
    super.setDirty();
  }
 
  public getPrimaryTable(): string | undefined {
    this.parse();
    return this.parsedXML?.primaryTable;
  }
 
  public getParameters() {
    this.parse();
    return this.parsedXML?.parameters;
  }
 
  public parseType(reg: IRegistry): AbstractType {
    this.parse();
 
    const references: IObjectAndToken[] = [];
    const ddic = new DDIC(reg);
 
    if (this.parsedXML?.primaryTable) {
      const found = ddic.lookupTableOrView2(this.parsedXML.primaryTable);
      if (found) {
        references.push({object: found});
        reg.getDDICReferences().setUsing(this, references);
        return found.parseType(reg);
      } else if (ddic.inErrorNamespace(this.parsedXML.primaryTable)) {
        return new UnknownType(this.parsedXML.primaryTable + " not found");
      } else {
        return VoidType.get(this.parsedXML.primaryTable);
      }
    } else {
      return new UnknownType("Parsing error");
    }
  }
 
  public parse() {
    if (this.parsedXML) {
      return {updated: false, runtime: 0};
    }
 
    const start = Date.now();
    this.parsedXML = {};
    const parsed = super.parseRaw2();
 
    if (parsed === undefined
        || parsed.abapGit === undefined
        || parsed.abapGit?.["asx:abap"]?.["asx:values"] === undefined) {
      return {updated: false, runtime: 0};
    }
 
    this.parsedXML.primaryTable = parsed.abapGit?.["asx:abap"]?.["asx:values"]?.DD25V?.ROOTTAB;
    this.parsedXML.description = parsed.abapGit?.["asx:abap"]?.["asx:values"]?.DD25V?.DDTEXT;
 
    this.parsedXML.parameters = [];
    const parameters = parsed.abapGit?.["asx:abap"]?.["asx:values"]?.DD27P_TABLE;
    for (const parameter of xmlToArray(parameters?.DD27P)) {
      if (typeof parameter?.VIEWFIELD !== "string") {
        continue;
      }
      this.parsedXML.parameters.push({
        VIEWFIELD: parameter.VIEWFIELD,
        TABNAME: parameter.TABNAME,
        FIELDNAME: parameter.FIELDNAME,
      });
    }
 
    const end = Date.now();
    return {updated: true, runtime: end - start};
  }
 
  public getDescription(): string | undefined {
    this.parse();
    return this.parsedXML?.description;
  }
}