All files / src/objects data_element.ts

93.26% Statements 97/104
92% Branches 46/50
87.5% Functions 7/8
93.26% Lines 97/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 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 1195x 1195x 52x 52x 51x 51x 52x 52x 36x 36x 36x 36x 36x 52x 52x 64x 64x 64x 52x 52x       52x 52x 178x 178x 178x 178x   178x 178x 178x 15x 2x 15x 13x 13x 178x 2x   2x 2x 2x 163x 161x 19x 161x 142x 142x 161x 178x 178x 178x 7x 7x 178x 178x 178x 52x 52x 77x 27x 27x 50x 50x 50x 50x 77x     50x 77x 77x 77x 77x 77x 77x 77x 77x 77x 77x 77x 77x 77x 52x 52x  
import {AbstractObject} from "./_abstract_object";
import {AbstractType} from "../abap/types/basic/_abstract_type";
import {IRegistry} from "../_iregistry";
import {DDIC, ILookupResult} from "../ddic";
import * as Types from "../abap/types/basic";
import {IObjectAndToken} from "../_iddic_references";
 
export class DataElement extends AbstractObject {
  private parsedXML: {
    description?: string,
    refkind?: string,
    domname?: string,
    datatype?: string,
    leng?: string,
    decimals?: string} | undefined = undefined;
 
  public getType(): string {
    return "DTEL";
  }
 
  public getDescription(): string | undefined {
    return this.parsedXML?.description;
  }
 
  public getAllowedNaming() {
    return {
      maxLength: 30,
      allowNamespace: true,
    };
  }
 
  public setDirty(): void {
    this.parsedXML = undefined;
    super.setDirty();
  }
 
  public getDomainName(): string | undefined {
    this.parse();
    return this.parsedXML?.domname;
  }
 
  public parseType(reg: IRegistry): AbstractType {
    const references: IObjectAndToken[] = [];
 
    let lookup: ILookupResult | undefined = undefined;
    if (this.parsedXML === undefined) {
      lookup = {type: new Types.UnknownType("Data Element " + this.getName() + ", parser error")};
    } else {
      const ddic = new DDIC(reg);
      if (this.parsedXML.refkind === "D") {
        if (this.parsedXML.domname === undefined || this.parsedXML.domname === "") {
          lookup = {type: new Types.UnknownType("DOMNAME unexpectely empty in " + this.getName())};
        } else {
          lookup = ddic.lookupDomain(this.parsedXML.domname, this.getName());
        }
      } else if (this.parsedXML.refkind === "R") {
        if (this.parsedXML.domname === undefined || this.parsedXML.domname === "") {
          lookup = {type: new Types.UnknownType("DOMNAME unexpectely empty in " + this.getName())};
        } else {
          lookup = ddic.lookupObject(this.parsedXML.domname);
        }
      } else {
        if (this.parsedXML.datatype === undefined || this.parsedXML.datatype === "") {
          lookup = {type: new Types.UnknownType("DATATYPE unexpectely empty in " + this.getName())};
        } else {
          lookup = {type: ddic.textToType(this.parsedXML.datatype, this.parsedXML.leng, this.parsedXML.decimals, this.getName())};
        }
      }
    }
 
    if (lookup.object) {
      references.push({object: lookup.object});
    }
    reg.getDDICReferences().setUsing(this, references);
    return lookup.type;
  }
 
  public parse() {
    if (this.parsedXML !== undefined) {
      return {updated: false, runtime: 0};
    }
 
    const start = Date.now();
    this.parsedXML = {};
    const parsed = super.parseRaw2();
    if (parsed === undefined) {
      return {updated: false, runtime: 0};
    }
 
    const dd04v = parsed.abapGit?.["asx:abap"]?.["asx:values"]?.DD04V;
    this.parsedXML = {
      description: dd04v?.DDTEXT,
      refkind: dd04v?.REFKIND,
      domname: dd04v?.DOMNAME,
      datatype: dd04v?.DATATYPE,
      leng: dd04v?.LENG,
      decimals: dd04v?.DECIMALS,
    };
 
    const end = Date.now();
    return {updated: true, runtime: end - start};
  }
 
}