All files / src/objects data_element.ts

93.1% Statements 135/145
92.75% Branches 64/69
77.77% Functions 7/9
93.1% Lines 135/145

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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 1461x 1x 1x 1x 1x 1x 1x 63x 63x 63x 63x 63x 63x 63x 63x 63x 63x 63x 63x 63x 63x 63x 63x 63x 1193x 1193x 63x 63x 66x 66x 66x 63x 63x 43x 43x 43x 43x 43x 63x 63x 80x 80x 80x 80x 63x 63x       63x 63x       63x 63x 220x 220x 220x 220x 220x 220x   220x 220x 154x 154x 66x 66x 220x 9x 2x 9x 7x 7x 220x 1x   1x 1x 1x 57x 56x 20x 56x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 56x 220x 66x 220x 6x 6x 66x 66x 220x 44x 44x 44x 44x 66x 66x 63x 63x 376x 316x 316x 60x 60x 60x 60x 376x     60x 376x 376x 376x 376x 376x 376x 376x 376x 376x 376x 376x 376x 376x 376x 376x 376x 376x 376x 376x 63x 63x  
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,
    texts?: {
      short?: string,
      medium?: string,
      long?: string,
      heading?: string,
    }
    decimals?: string} | undefined = undefined;
  private parsedType: AbstractType | undefined = undefined;
 
  public getType(): string {
    return "DTEL";
  }
 
  public getDescription(): string | undefined {
    this.parse();
    return this.parsedXML?.description;
  }
 
  public getAllowedNaming() {
    return {
      maxLength: 30,
      allowNamespace: true,
    };
  }
 
  public setDirty(): void {
    this.parsedXML = undefined;
    this.parsedType = undefined;
    super.setDirty();
  }
 
  public getDomainName(): string | undefined {
    this.parse();
    return this.parsedXML?.domname;
  }
 
  public getTexts() {
    this.parse();
    return this.parsedXML?.texts;
  }
 
  public parseType(reg: IRegistry): AbstractType {
    const references: IObjectAndToken[] = [];
    let lookup: ILookupResult | undefined = undefined;
 
    this.parse();
 
    if (this.parsedXML === undefined) {
      lookup = {type: new Types.UnknownType("Data Element " + this.getName() + ", parser error")};
    } else {
      if (this.parsedType) {
        return this.parsedType;
      }
 
      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(), this.getDescription());
        }
      } 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({
            text: this.parsedXML.datatype,
            length: this.parsedXML.leng,
            decimals: this.parsedXML.decimals,
            infoText: this.getName(),
            qualifiedName: this.getName(),
            conversionExit: undefined,
            ddicName: this.getName(),
            description: this.parsedXML.texts?.heading,
          })};
        }
      }
    }
 
    if (lookup.object) {
      references.push({object: lookup.object});
    }
    reg.getDDICReferences().setUsing(this, references);
 
    if (!(lookup.type instanceof Types.UnknownType)) {
      // the referenced type might not exist or contain syntax errors(for CLAS)
      // so dont cache it, expect the user to fix it
      this.parsedType = lookup.type;
    }
    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,
      texts: {
        short: dd04v?.SCRTEXT_S,
        medium: dd04v?.SCRTEXT_M,
        long: dd04v?.SCRTEXT_L,
        heading: dd04v?.REPTEXT,
      },
    };
 
    const end = Date.now();
    return {updated: true, runtime: end - start};
  }
 
}