All files / src/objects cds_metadata_extension.ts

88.13% Statements 52/59
80% Branches 8/10
85.71% Functions 6/7
88.13% Lines 52/59

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 601x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x           2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x     2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x  
import {ExpressionNode} from "../abap/nodes";
import {CDSParser} from "../cds/cds_parser";
import {AbstractObject} from "./_abstract_object";
import {IParseResult} from "./_iobject";
 
export type ParsedMetadataExtension = {
  tree: ExpressionNode | undefined;
};
 
 
export class CDSMetadataExtension extends AbstractObject {
  private parserError: boolean | undefined = undefined;
  private parsedData: ParsedMetadataExtension | undefined = undefined;
 
  public getType(): string {
    return "DDLX";
  }
 
  public getAllowedNaming() {
    return {
      maxLength: 40,
      allowNamespace: true,
    };
  }
 
  public setDirty(): void {
    this.parsedData = undefined;
    this.parserError = undefined;
    super.setDirty();
  }
 
  public hasParserError() {
    return this.parserError;
  }
 
  public parse(): IParseResult {
    if (this.isDirty() === false) {
      return {updated: false, runtime: 0};
    }
 
    const start = Date.now();
 
    this.parsedData = {
      tree: undefined,
    };
 
    this.parsedData.tree = new CDSParser().parse(this.findSourceFile());
    if (this.parsedData.tree === undefined) {
      this.parserError = true;
    }
 
    this.dirty = false;
    return {updated: true, runtime: Date.now() - start};
  }
 
  public findSourceFile() {
    return this.getFiles().find(f => f.getFilename().endsWith(".asddlxs") || f.getFilename().endsWith(".acds"));
  }
}